|
6 | 6 | import {faker} from '@faker-js/faker'; |
7 | 7 | import {DomainEvent, EmailAddress} from '../../../src/types'; |
8 | 8 | import {TestFramework, initTestFramework} from '../test-framework'; |
| 9 | +import { EditEmail } from '../../../src/commands/members/edit-email'; |
9 | 10 |
|
10 | 11 | describe('lookupByEmail', () => { |
11 | 12 | let events: ReadonlyArray<DomainEvent>; |
@@ -44,6 +45,28 @@ describe('lookupByEmail', () => { |
44 | 45 | const result = lookupByEmail(command.email)(events); |
45 | 46 | expect(result).toStrictEqual(O.some(command.memberNumber)); |
46 | 47 | }); |
| 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 | + }); |
47 | 70 | }); |
48 | 71 |
|
49 | 72 | describe('when no member with the given email exists', () => { |
@@ -115,6 +138,37 @@ describe('lookupByCaseInsensitiveEmail', () => { |
115 | 138 | {emailAddress: command.email, memberNumber: command.memberNumber}, |
116 | 139 | ]); |
117 | 140 | }); |
| 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 | + }); |
118 | 172 | }); |
119 | 173 |
|
120 | 174 | describe('when no member with the given email exists', () => { |
|
0 commit comments