Skip to content

Commit 5c6640b

Browse files
committed
Tests to cover the member lookup by email used for auth
1 parent 0dad92f commit 5c6640b

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

src/commands/members/edit-email.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const codec = t.strict({
1212
email: EmailAddressCodec,
1313
});
1414

15-
type EditEmail = t.TypeOf<typeof codec>;
15+
export type EditEmail = t.TypeOf<typeof codec>;
1616

1717
const process: Command<EditEmail>['process'] = input =>
1818
O.some(

tests/read-models/members/lookup-by-email.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import {faker} from '@faker-js/faker';
77
import {DomainEvent, EmailAddress} from '../../../src/types';
88
import {TestFramework, initTestFramework} from '../test-framework';
9+
import { EditEmail } from '../../../src/commands/members/edit-email';
910

1011
describe('lookupByEmail', () => {
1112
let events: ReadonlyArray<DomainEvent>;
@@ -44,6 +45,28 @@ describe('lookupByEmail', () => {
4445
const result = lookupByEmail(command.email)(events);
4546
expect(result).toStrictEqual(O.some(command.memberNumber));
4647
});
48+
49+
describe('when the member has changed their email', () => {
50+
const editEmailCommand: EditEmail = {
51+
memberNumber: command.memberNumber,
52+
email: faker.internet.email() as EmailAddress,
53+
};
54+
55+
beforeEach(async () => {
56+
await framework.commands.members.editEmail(editEmailCommand);
57+
});
58+
59+
it('returns their member number using the new email', () => {
60+
const result = lookupByEmail(editEmailCommand.email)(events);
61+
expect(result).toStrictEqual(O.some(command.memberNumber));
62+
});
63+
64+
it('returns their member number using the old email', () => {
65+
const result = lookupByEmail(command.email)(events);
66+
expect(result).toStrictEqual(O.some(command.memberNumber));
67+
});
68+
69+
});
4770
});
4871

4972
describe('when no member with the given email exists', () => {
@@ -115,6 +138,37 @@ describe('lookupByCaseInsensitiveEmail', () => {
115138
{emailAddress: command.email, memberNumber: command.memberNumber},
116139
]);
117140
});
141+
142+
describe('when the member has changed their email', () => {
143+
const editEmailCommand: EditEmail = {
144+
memberNumber: command.memberNumber,
145+
email: faker.internet.email() as EmailAddress,
146+
};
147+
148+
beforeEach(async () => {
149+
await framework.commands.members.editEmail(editEmailCommand);
150+
});
151+
152+
it('returns their member number using the new email', () => {
153+
const result = lookupByEmail(editEmailCommand.email)(events);
154+
expect(result).toStrictEqual(O.some(command.memberNumber));
155+
});
156+
157+
it('returns their member number using the old email', () => {
158+
const result = lookupByEmail(command.email)(events);
159+
expect(result).toStrictEqual(O.some(command.memberNumber));
160+
});
161+
162+
it('returns their member number using the new email even in wrong case', () => {
163+
const result = lookupByEmail(editEmailCommand.email.toUpperCase())(events);
164+
expect(result).toStrictEqual(O.some(command.memberNumber));
165+
});
166+
167+
it('returns their member number using the old email even in wrong case', () => {
168+
const result = lookupByEmail(command.email.toUpperCase())(events);
169+
expect(result).toStrictEqual(O.some(command.memberNumber));
170+
});
171+
});
118172
});
119173

120174
describe('when no member with the given email exists', () => {

0 commit comments

Comments
 (0)