|
1 | 1 | import request from 'supertest';
|
2 | 2 | import createLoopback from '~/test/utils/create-loopback';
|
| 3 | +import AccountFactory from './account'; |
| 4 | +import { host } from '../config.json'; |
| 5 | + |
| 6 | +describe('Account unit', () => { |
| 7 | + const AccountMock = { |
| 8 | + on: jest.fn(), |
| 9 | + app: {models: {Email: {send: jest.fn()}}}, |
| 10 | + }; |
| 11 | + |
| 12 | + beforeEach(() => { |
| 13 | + jest.resetAllMocks(); |
| 14 | + }); |
| 15 | + |
| 16 | + it('add resetPasswordRequest remote method', () => { |
| 17 | + AccountFactory(AccountMock); |
| 18 | + expect(AccountMock.on).toBeCalledWith( |
| 19 | + 'resetPasswordRequest', |
| 20 | + expect.any(Function), |
| 21 | + ); |
| 22 | + }); |
| 23 | + |
| 24 | + it('calls send method from Email model', () => { |
| 25 | + const infoMock = { |
| 26 | + |
| 27 | + accessToken: { |
| 28 | + id: 'foobar', |
| 29 | + }, |
| 30 | + }; |
| 31 | + AccountMock.on.mockImplementation((_, fn) => { |
| 32 | + fn(infoMock); |
| 33 | + }); |
| 34 | + AccountFactory(AccountMock); |
| 35 | + expect(AccountMock.app.models.Email.send).toBeCalledWith( |
| 36 | + expect.objectContaining({ |
| 37 | + to: infoMock.email, |
| 38 | + |
| 39 | + subject: '[alpp] Create a new password', |
| 40 | + html: expect.stringMatching( |
| 41 | + new RegExp(`${host}.*${infoMock.accessToken.id}`) |
| 42 | + ), |
| 43 | + }), |
| 44 | + expect.any(Function), |
| 45 | + ); |
| 46 | + }); |
| 47 | +}); |
3 | 48 |
|
4 | 49 | describe('Account', () => {
|
5 | 50 | const email = '[email protected]';
|
|
0 commit comments