-
-
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): Fix emailAddress conflict when creating Customers
Closes #300 BREAKING CHANGE: The `customer` and `user` tables have received some non-destructive modifications, requiring a DB migration.
- Loading branch information
1 parent
8395c61
commit 0d4e31a
Showing
5 changed files
with
70 additions
and
10 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 |
---|---|---|
|
@@ -12,7 +12,7 @@ import gql from 'graphql-tag'; | |
import path from 'path'; | ||
|
||
import { initialData } from '../../../e2e-common/e2e-initial-data'; | ||
import { TEST_SETUP_TIMEOUT_MS, testConfig } from '../../../e2e-common/test-config'; | ||
import { testConfig, TEST_SETUP_TIMEOUT_MS } from '../../../e2e-common/test-config'; | ||
|
||
import { CUSTOMER_FRAGMENT } from './graphql/fragments'; | ||
import { | ||
|
@@ -400,6 +400,23 @@ describe('Customer resolver', () => { | |
expect(createCustomer.user!.verified).toBe(true); | ||
expect(sendEmailFn).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
it( | ||
'throws when using an existing, non-deleted emailAddress', | ||
assertThrowsWithMessage(async () => { | ||
const { createCustomer } = await adminClient.query< | ||
CreateCustomer.Mutation, | ||
CreateCustomer.Variables | ||
>(CREATE_CUSTOMER, { | ||
input: { | ||
emailAddress: '[email protected]', | ||
firstName: 'New', | ||
lastName: 'Customer', | ||
}, | ||
password: 'test', | ||
}); | ||
}, 'The email address must be unique'), | ||
); | ||
}); | ||
|
||
describe('deletion', () => { | ||
|
@@ -456,6 +473,23 @@ describe('Customer resolver', () => { | |
`No Customer with the id '3' could be found`, | ||
), | ||
); | ||
|
||
it('new Customer can be created with same emailAddress as a deleted Customer', async () => { | ||
const { createCustomer } = await adminClient.query< | ||
CreateCustomer.Mutation, | ||
CreateCustomer.Variables | ||
>(CREATE_CUSTOMER, { | ||
input: { | ||
emailAddress: thirdCustomer.emailAddress, | ||
firstName: 'Reusing Email', | ||
lastName: 'Customer', | ||
}, | ||
}); | ||
|
||
expect(createCustomer.emailAddress).toBe(thirdCustomer.emailAddress); | ||
expect(createCustomer.firstName).toBe('Reusing Email'); | ||
expect(createCustomer.user?.identifier).toBe(thirdCustomer.emailAddress); | ||
}); | ||
}); | ||
}); | ||
|
||
|
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
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
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
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