Skip to content

Commit

Permalink
LOR-214 - feat: add test to Account
Browse files Browse the repository at this point in the history
  • Loading branch information
Daaaiii committed Feb 7, 2024
1 parent 2cea824 commit a9bb6f0
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/unit/account.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('AccountService unit test', () => {
.fn()
.mockReturnValue(stubs.getCredentialOutput),
savePasswordResetInformation: jest.fn(),
getCredentialId: jest.fn().mockReturnValue(stubs.getCredentialOutputById),
};

beforeEach(async () => {
Expand Down Expand Up @@ -94,4 +95,48 @@ describe('AccountService unit test', () => {
}
});
});
describe('Account', () => {
it('Happy path - should return account details', async () => {
const actual = await service.getCredential(
stubs.getCredentialOutputById.id,
);

expect(actual.credential).toHaveProperty(
'message',
'Dados recebidos com sucesso',
);
expect(actual).toHaveProperty('credential');
expect(actual.credential).toHaveProperty(
'id',
stubs.getCredentialOutputById.id,
);
expect(actual.credential).toHaveProperty(
'email',
stubs.getCredentialOutputById.email,
);
expect(actual.credential).toHaveProperty('parentProfile');
expect(actual.credential.parentProfile).toHaveProperty(
'id',
stubs.getCredentialOutputById.parentProfile.id,
);
expect(actual.credential.parentProfile).toHaveProperty(
'fullname',
stubs.getCredentialOutputById.parentProfile.fullname,
);
expect(actual.credential.parentProfile).toHaveProperty('childrens');
expect(actual.credential.parentProfile.childrens).toHaveLength(1);
});
});

it('Unhappy path - should return void', async () => {
jest
.spyOn(accountRepositoryMock, 'getCredentialId')
.mockReturnValueOnce(null);

try {
await service.getCredential(stubs.getCredentialOutputById.id);
} catch (actual) {
expect(actual).toBeInstanceOf(EmailNotFoundException);
}
});
});
17 changes: 17 additions & 0 deletions test/unit/account.service.stubs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,20 @@ export const getCredentialOutput: GetCredentialIdByEmailOutput = {
],
},
};
export const getCredentialOutputById = {
message: 'Dados recebidos com sucesso',
id: faker.string.uuid(),
email: faker.internet.email(),
parentProfile: {
id: faker.string.uuid(),
fullname: faker.person.fullName(),
childrens: [
{
id: faker.number.int(),
fullname: faker.person.fullName(),
birthdate: faker.date.birthdate(),
gender: faker.helpers.enumValue(Genders),
},
],
},
};

0 comments on commit a9bb6f0

Please sign in to comment.