-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Normalize email address on updating Customer
Fixes #2449
- Loading branch information
1 parent
02fe6ae
commit 957d0ad
Showing
3 changed files
with
70 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -525,6 +525,22 @@ describe('Customer resolver', () => { | |
expect(createCustomer.message).toBe('The email address is not available.'); | ||
expect(createCustomer.errorCode).toBe(ErrorCode.EMAIL_ADDRESS_CONFLICT_ERROR); | ||
}); | ||
|
||
it('normalizes email address on creation', async () => { | ||
const { createCustomer } = await adminClient.query< | ||
Codegen.CreateCustomerMutation, | ||
Codegen.CreateCustomerMutationVariables | ||
>(CREATE_CUSTOMER, { | ||
input: { | ||
emailAddress: ' [email protected] ', | ||
firstName: 'Joe', | ||
lastName: 'Smith', | ||
}, | ||
password: 'test', | ||
}); | ||
customerErrorGuard.assertSuccess(createCustomer); | ||
expect(createCustomer.emailAddress).toBe('[email protected]'); | ||
}); | ||
}); | ||
|
||
describe('update', () => { | ||
|
@@ -566,6 +582,27 @@ describe('Customer resolver', () => { | |
|
||
expect(me?.identifier).toBe('[email protected]'); | ||
}); | ||
|
||
// https://github.com/vendure-ecommerce/vendure/issues/2449 | ||
it('normalizes email address on update', async () => { | ||
const { updateCustomer } = await adminClient.query< | ||
Codegen.UpdateCustomerMutation, | ||
Codegen.UpdateCustomerMutationVariables | ||
>(UPDATE_CUSTOMER, { | ||
input: { | ||
id: thirdCustomer.id, | ||
emailAddress: ' [email protected] ', | ||
}, | ||
}); | ||
customerErrorGuard.assertSuccess(updateCustomer); | ||
|
||
expect(updateCustomer.emailAddress).toBe('[email protected]'); | ||
|
||
await shopClient.asUserWithCredentials('[email protected]', 'test'); | ||
const { me } = await shopClient.query<Codegen.MeQuery>(ME); | ||
|
||
expect(me?.identifier).toBe('[email protected]'); | ||
}); | ||
}); | ||
|
||
describe('deletion', () => { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1263,6 +1263,29 @@ describe('Updating email address without email verification', () => { | |
); | ||
expect(activeCustomer!.emailAddress).toBe(NEW_EMAIL_ADDRESS); | ||
}); | ||
|
||
it('normalizes updated email address', async () => { | ||
await shopClient.asUserWithCredentials(NEW_EMAIL_ADDRESS, 'test'); | ||
const { requestUpdateCustomerEmailAddress } = await shopClient.query< | ||
CodegenShop.RequestUpdateEmailAddressMutation, | ||
CodegenShop.RequestUpdateEmailAddressMutationVariables | ||
>(REQUEST_UPDATE_EMAIL_ADDRESS, { | ||
password: 'test', | ||
newEmailAddress: ' [email protected] ', | ||
}); | ||
successErrorGuard.assertSuccess(requestUpdateCustomerEmailAddress); | ||
// Attempting to fix flakiness possibly caused by race condition on the event | ||
// subscriber | ||
await new Promise(resolve => setTimeout(resolve, 100)); | ||
expect(requestUpdateCustomerEmailAddress.success).toBe(true); | ||
expect(sendEmailFn).toHaveBeenCalledTimes(1); | ||
expect(sendEmailFn.mock.calls[0][0] instanceof IdentifierChangeEvent).toBe(true); | ||
|
||
const { activeCustomer } = await shopClient.query<CodegenShop.GetActiveCustomerQuery>( | ||
GET_ACTIVE_CUSTOMER, | ||
); | ||
expect(activeCustomer!.emailAddress).toBe('[email protected]'); | ||
}); | ||
}); | ||
|
||
function getVerificationTokenPromise(): Promise<string> { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters