47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
const models = require('vn-loopback/server/server').models;
|
|
const LoopBackContext = require('loopback-context');
|
|
describe('VnUser recoverPassword', () => {
|
|
const userId = 1107;
|
|
|
|
const activeCtx = {
|
|
accessToken: {userId: userId},
|
|
http: {
|
|
req: {
|
|
headers: {origin: 'http://localhost'}
|
|
}
|
|
}
|
|
};
|
|
|
|
beforeEach(() => {
|
|
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
|
|
active: activeCtx
|
|
});
|
|
});
|
|
|
|
describe('By email', () => {
|
|
it('should send email with token', async() => {
|
|
const userId = 1107;
|
|
const user = await models.VnUser.findById(userId);
|
|
|
|
await models.VnUser.recoverPassword(user.email);
|
|
|
|
const result = await models.AccessToken.findOne({where: {userId: userId}});
|
|
|
|
expect(result).toBeDefined();
|
|
});
|
|
});
|
|
|
|
describe('By SMS()', () => {
|
|
it('should send sms with token', async() => {
|
|
const userId = 1107;
|
|
const user = await models.VnUser.findById(userId);
|
|
|
|
await models.VnUser.recoverPasswordSMS(user.email);
|
|
|
|
const result = await models.AuthCode.findOne({where: {userId: userId}});
|
|
|
|
expect(result).toBeDefined();
|
|
});
|
|
});
|
|
});
|