Skip to content

Commit

Permalink
Add isNaN(str) check
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianchia committed Jul 22, 2014
1 parent 5582300 commit 5c1c8cc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion 1-echo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"main": "server.js",
"scripts": {
"test": "node server.js && mocha",
"test": "mocha",
"start": "node server.js"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion 2-video/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"main": "server.js",
"scripts": {
"test": "node server.js && mocha",
"test": "mocha",
"start": "node server.js"
},
"dependencies": {
Expand Down
3 changes: 2 additions & 1 deletion 2-video/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ app.get('/video', function(req,res) {
});

app.post('/video', function(req, res) {
console.log(req.body);
var name = req.body.name;
var url = req.body.url;
var duration = req.body.duration;

if(!name || !url || !duration || name.length < 1 || url.length < 10 || parseInt(duration) < 0) {
if(!name || !url || !duration || name.length < 1 || url.length < 10 || isNaN(duration) || parseInt(duration) < 0) {
res
.status(400)
.send("Missing ['name','duration','url'].");
Expand Down
18 changes: 18 additions & 0 deletions 2-video/test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,23 @@ describe('Video test add and list', function() {
.expect(400)
.expect("Missing ['name','duration','url'].", done);
});

it("should return Missing ['name','duration','url'].", function(done) {
request(BASE_URL)
.post('/video')
.set('Content-Type','application/x-www-form-urlencoded')
.send({"name": '', "url": 'www.a.com', "duration": ""})
.expect(400)
.expect("Missing ['name','duration','url'].", done);
});

it("should return Missing ['name','duration','url'].", function(done) {
request(BASE_URL)
.post('/video')
.set('Content-Type','application/x-www-form-urlencoded')
.send({"name": '', "url": 'www.a.com', "duration": "aaa"})
.expect(400)
.expect("Missing ['name','duration','url'].", done);
});
});

0 comments on commit 5c1c8cc

Please sign in to comment.