salix/back/methods/account/specs/recover-password.spec.js

37 lines
988 B
JavaScript

const models = require('vn-loopback/server/server').models;
describe('account recoverPassword()', () => {
const ctx = {
req: {
headers: {origin: 'http://localhost:5000'}
}
};
ctx.req.__ = value => {
return value;
};
it('should throw an error when email does not belong to a user', async() => {
let error;
try {
await models.Account.recoverPassword(ctx, 'thor@mydomain.com');
} catch (e) {
error = e;
}
expect(error.message).toEqual('This email does not belong to a user');
});
it('should update password when it passes requirements', async() => {
const user = await models.Account.findById(1107);
await models.Account.recoverPassword(ctx, user.email);
const [result] = await models.AccessToken.find({
where: {
userId: user.id
}
});
expect(result).toBeDefined();
});
});