add extra tests to user_spec to test some else conditions.

This commit is contained in:
dceejay 2015-03-19 19:57:41 +00:00
parent a9789697e7
commit df065e94b7
1 changed files with 55 additions and 18 deletions

View File

@ -25,12 +25,12 @@ describe("Users", function() {
before(function() { before(function() {
Users.init({ Users.init({
type:"credentials", type:"credentials",
users:[{ users:{
username:"fred", username:"fred",
password:'$2a$08$LpYMefvGZ3MjAfZGzcoyR.1BcfHh4wy4NpbN.cEny5aHnWOqjKOXK', password:'$2a$08$LpYMefvGZ3MjAfZGzcoyR.1BcfHh4wy4NpbN.cEny5aHnWOqjKOXK',
// 'password' -> require('bcryptjs').hashSync('password', 8); // 'password' -> require('bcryptjs').hashSync('password', 8);
permissions:"*" permissions:"*"
}] }
}); });
}); });
describe('#get',function() { describe('#get',function() {
@ -46,7 +46,7 @@ describe("Users", function() {
} }
}); });
}); });
it('returns null for unknown user', function(done) { it('returns null for unknown user', function(done) {
Users.get("barney").then(function(user) { Users.get("barney").then(function(user) {
try { try {
@ -58,7 +58,7 @@ describe("Users", function() {
}); });
}); });
}); });
describe('#default',function() { describe('#default',function() {
it('returns null for default user', function(done) { it('returns null for default user', function(done) {
Users.default().then(function(user) { Users.default().then(function(user) {
@ -71,9 +71,8 @@ describe("Users", function() {
}); });
}); });
}); });
describe('#authenticate',function() { describe('#authenticate',function() {
it('authenticates a known user', function(done) { it('authenticates a known user', function(done) {
Users.authenticate('fred','password').then(function(user) { Users.authenticate('fred','password').then(function(user) {
try { try {
@ -96,7 +95,7 @@ describe("Users", function() {
} }
}); });
}); });
it('rejects invalid user', function(done) { it('rejects invalid user', function(done) {
Users.authenticate('barney','wrong').then(function(user) { Users.authenticate('barney','wrong').then(function(user) {
try { try {
@ -109,8 +108,7 @@ describe("Users", function() {
}); });
}); });
}); });
describe('Initalised with a credentials object including anon',function() { describe('Initalised with a credentials object including anon',function() {
before(function() { before(function() {
Users.init({ Users.init({
@ -133,8 +131,8 @@ describe("Users", function() {
}); });
}); });
}); });
describe('Initialised with a credentials object with user functions',function() { describe('Initialised with a credentials object with user functions',function() {
var authUsername = ''; var authUsername = '';
var authPassword = ''; var authPassword = '';
before(function() { before(function() {
@ -150,7 +148,7 @@ describe("Users", function() {
} }
}); });
}); });
describe('#get',function() { describe('#get',function() {
it('delegates get user',function(done) { it('delegates get user',function(done) {
Users.get('dave').then(function(user) { Users.get('dave').then(function(user) {
@ -179,8 +177,47 @@ describe("Users", function() {
}); });
}); });
}); });
});
describe('Initialised with bad settings to test else cases',function() {
}); before(function() {
}); Users.init({
type:"foo",
users:{
username:"fred",
password:'$2a$08$LpYMefvGZ3MjAfZGzcoyR.1BcfHh4wy4NpbN.cEny5aHnWOqjKOXK',
permissions:"*"
}
});
});
describe('#get',function() {
it('should fail to return user fred',function(done) {
Users.get("fred").then(function(userf) {
try {
userf.should.not.have.a.property("username","fred");
userf.should.not.have.a.property("permissions","*");
done();
} catch(err) {
done(err);
}
});
});
});
});
describe('Initialised with default set as function',function() {
before(function() {
Users.init({
type:"credentials",
default: function() { return("Done"); }
});
});
describe('#default',function() {
it('handles api.default being a function',function(done) {
Users.should.have.property('default').which.is.a.Function;
(Users.default()).should.equal("Done");
done();
});
});
});
});