Skip to content

Commit e7d62ee

Browse files
author
Walker Leite
committed
test(Account): add unit tests
1 parent 9664336 commit e7d62ee

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

template/server/models/account.spec.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,50 @@
11
import request from 'supertest';
22
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+
email: 'foo@bar.net',
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+
from: 'alpp <noreply@mydomain.com>',
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+
});
348

449
describe('Account', () => {
550
const email = '936ue5+4bnywbeje42pw@sharklasers.com';

0 commit comments

Comments
 (0)