Last active
August 29, 2015 14:26
-
-
Save Ntropish/1b9217282f17fe29c3cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var test = require('tape'); | |
var request = require('supertest'); | |
var url = 'localhost:3000'; | |
test('Bad login tests', function (t) { | |
var badLogin = function badLogin(username, password, message){ | |
return request(url).post('/login').send({ | |
username: username, | |
password: password | |
}) | |
.expect('Content-Type', /json/) | |
.expect(200) | |
.end(function (err, res) { | |
t.error(err, 'Request should be successful'); | |
t.equal(res.body.success, false, message); | |
}) | |
}; | |
Promise.all( | |
[ | |
badLogin('cat', 'wrong-password', 'login with wrong password should fail'), | |
badLogin('', 'wrong-password', 'login with no username should fail'), | |
badLogin('cat', '', 'login with no password should fail'), | |
badLogin('-=5%%>0-08-13;???<', 'wrong-password', 'login with silly username should fail'), | |
badLogin(undefined, undefined, 'login with no credentials should fail') | |
]) | |
.then(function(){ | |
t.end() | |
},function(err){ | |
t.error(err, 'no errors should have happened when requesting'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment