Browse Source

Fleshed out new passing 'failure on no n passed' test, fixed a minor bug. Added 404 test, but failing

Luiserebii 2 years ago
parent
commit
efb84d4a40
Signed by: Luiserebii <luis@serebii.io> GPG Key ID: 58A745E0A5422230
2 changed files with 22 additions and 10 deletions
  1. 3
    3
      routes/api_v1.js
  2. 19
    7
      test/api-v1.test.js

+ 3
- 3
routes/api_v1.js View File

@@ -13,7 +13,7 @@ var router = express.Router();
13 13
 
14 14
 router.get("/fibonacci", function(req, res, next){
15 15
    if(req.query.type) { return next(); }
16
-   if(!req.query.n) { return res.end("ERROR: No \"n\" parameter query passed."); }
16
+   if(!req.query.n) { return res.status(400).send("ERROR: No \"n\" parameter query passed."); }
17 17
 
18 18
    let n = parseInt(req.query.n, 10);
19 19
    let fibResult = MathFun.fibonacci(n);
@@ -24,7 +24,7 @@ router.get("/fibonacci", function(req, res, next){
24 24
 
25 25
 router.use(function(req, res, next){
26 26
    if(!req.query.type == "isFib") { return next(); }
27
-   if(!req.query.n) { return res.end("ERROR: No \"fib\" parameter query passed."); }
27
+   if(!req.query.n) { return res.status(400).send("ERROR: No \"fib\" parameter query passed."); }
28 28
 
29 29
    let n = parseInt(req.query.n, 10);
30 30
    let boolRes = MathFun.isFibonacci(n);
@@ -37,7 +37,7 @@ router.use(function(req, res, next){
37 37
 
38 38
 
39 39
 router.use(function(req, res){
40
-   res.end("Sorry, nothing hit!");
40
+   res.status(404).send("Sorry, nothing hit!");
41 41
 });
42 42
 
43 43
 module.exports = router;

+ 19
- 7
test/api-v1.test.js View File

@@ -17,9 +17,7 @@ const app = require("../app");
17 17
 describe("API V1", function(){
18 18
    
19 19
    it("fibonacci endpoint returns valid fib", function(done){
20
-
21 20
       testFib(10, 34, done);
22
-
23 21
    });
24 22
 
25 23
    it("isfib returns valid response", function(done){
@@ -40,14 +38,28 @@ describe("API V1", function(){
40 38
    });
41 39
 
42 40
   
43
-   it("failure on no 'n' passed", function(){
44
-
45
- 
46
-
41
+   it("failure on no 'n' passed", function(done){
42
+      
43
+      supertest(app)
44
+         .get("/v1/fibonacci")
45
+         .expect(400)
46
+         .end(function(err, res){
47
+            if (err) return done(err);
48
+            done();
49
+         });
50
+      
47 51
    });
48 52
 
49
-   it("returns apology on nothing hit", function(){
53
+   it("returns apology on nothing hit", function(done){
50 54
 
55
+      supertest(app)
56
+         .get("/v1/anallubricant")
57
+         .expect(404)
58
+         .end(function(err, res){
59
+            if (err) return done(err);
60
+            done();
61
+         });
62
+ 
51 63
    });
52 64
 
53 65
 });

Loading…
Cancel
Save