This repository has been archived by the owner on Apr 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
147 additions
and
62 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,98 @@ | ||
var User = require('../../../api/models/User'); | ||
var sinon = require('sinon'); | ||
var assert = require('assert'); | ||
|
||
describe('/', function () { | ||
var chai = require('chai'); | ||
var assert = chai.assert; | ||
var expect = chai.expect; | ||
|
||
describe('User model —', function () { | ||
describe('Before the user is created', function () { | ||
|
||
/** | ||
* @description Test to make sure an error is thrown if there is | ||
* no password. If an error is thrown, the test passes. | ||
*/ | ||
it('should be a password', function (done) { | ||
User.beforeCreate({ | ||
password: null, | ||
confirmation: null | ||
}, function (error, user) { | ||
try { | ||
expect(user).to.be.null; | ||
expect(error).to.be.a('string'); | ||
expect(error).to.equal('Password required.'); | ||
done(); | ||
} catch (error) { | ||
done(error); | ||
} | ||
}) | ||
}); | ||
|
||
/** | ||
* @description Test to make sure that the password will be | ||
* encrypted. If the `encryptedPassword` and `password` are | ||
* different, the test passes. | ||
*/ | ||
it('should hash the password', function (done) { | ||
User.beforeCreate({ | ||
password: 'password', | ||
confirmation: 'password' | ||
}, function (error, user) { | ||
|
||
if (!error) { | ||
try { | ||
assert.notEqual(user.password , 'password'); | ||
done(); | ||
} catch (error) { | ||
done(error); | ||
} | ||
} if (error) { | ||
done(error); // test fails | ||
} | ||
|
||
}); | ||
}); | ||
|
||
/** | ||
* @description Test to make sure that an error will be thrown | ||
* if the password and the password confirmation are the not | ||
* same. If an error is thrown, the test passes. | ||
*/ | ||
it('should not allow different passwords', function (done) { | ||
User.beforeCreate({ | ||
password: 'password', | ||
confirmation: 'is different' | ||
}, function (error, user) { | ||
|
||
if (error) { | ||
expect(user).to.be.null; | ||
done(); | ||
} else if (!error) { | ||
done('different passwords are allowed'); // test fails | ||
} | ||
|
||
}); | ||
}); | ||
|
||
/** | ||
* @description Test to make sure that no errors will be thrown | ||
* when the password and the password confirmation are the | ||
* same. If no error is thrown, the test passes. | ||
*/ | ||
it('should allow identical passwords', function (done) { | ||
User.beforeCreate({ | ||
password: 'password', | ||
confirmation: 'password' | ||
}, function (error, user) { | ||
|
||
if (error) { | ||
expect(user).to.be.null; | ||
done(error); | ||
} else if (!error) { | ||
done(); | ||
} | ||
|
||
}); | ||
}); | ||
|
||
}); | ||
}); |
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,5 +10,5 @@ | |
|
||
module.exports.models = { | ||
migrate: 'safe', | ||
connection: 'productionMongo' | ||
connection: 'production' | ||
}; |
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