mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Added unit test coverage to the user service
refs https://github.com/TryGhost/Ghost/issues/15008 - Added basic coverage for the reset all passwords frlow to pass the test coverage bar
This commit is contained in:
parent
db125ec0b9
commit
0bc66558c3
1 changed files with 52 additions and 0 deletions
52
test/unit/server/services/users/users-service.test.js
Normal file
52
test/unit/server/services/users/users-service.test.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
const assert = require('assert');
|
||||
const sinon = require('sinon');
|
||||
|
||||
const Users = require('../../../../../core/server/services/users');
|
||||
|
||||
describe('Users service', function () {
|
||||
describe('resetAllPasswords', function () {
|
||||
it('resets all user passwords', async function () {
|
||||
const userToReset = {
|
||||
save: sinon.mock().resolves(),
|
||||
get: sinon.mock().withArgs('email').returns('test_email@example.com')
|
||||
};
|
||||
const mockOptions = {
|
||||
dbBackup: {
|
||||
backup: sinon.mock().resolves('backup/path/file.json')
|
||||
},
|
||||
models: {
|
||||
Base: {
|
||||
transaction: (cb) => {
|
||||
return cb('fake_transaction');
|
||||
}
|
||||
},
|
||||
User: {
|
||||
findAll: sinon.mock().resolves([userToReset])
|
||||
}
|
||||
},
|
||||
auth: {
|
||||
passwordreset: {
|
||||
generateToken: sinon.mock().resolves('secret_fake_token'),
|
||||
sendResetNotification: sinon.mock().resolves('reset_notification_sent')
|
||||
}
|
||||
},
|
||||
apiMail: 'fake_api_mail',
|
||||
apiSettings: 'fake_api_settings'
|
||||
};
|
||||
const usersService = new Users(mockOptions);
|
||||
|
||||
await usersService.resetAllPasswords({
|
||||
context: {}
|
||||
});
|
||||
|
||||
assert.equal(mockOptions.auth.passwordreset.generateToken.calledOnce, true);
|
||||
assert.equal(mockOptions.auth.passwordreset.generateToken.args[0][0], 'test_email@example.com');
|
||||
assert.equal(mockOptions.auth.passwordreset.generateToken.args[0][1], 'fake_api_settings');
|
||||
assert.equal(mockOptions.auth.passwordreset.generateToken.args[0][2], 'fake_transaction');
|
||||
|
||||
assert.equal(mockOptions.auth.passwordreset.sendResetNotification.calledOnce, true);
|
||||
assert.equal(mockOptions.auth.passwordreset.sendResetNotification.args[0][0], 'secret_fake_token');
|
||||
assert.equal(mockOptions.auth.passwordreset.sendResetNotification.args[0][1], 'fake_api_mail');
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue