test that existing emails do not throw anymore

This commit is contained in:
Moriz Wahl 2023-01-27 16:03:27 +01:00
parent 78b8d18c4e
commit 88de09b1ba
4 changed files with 17 additions and 7 deletions

View File

@ -33,7 +33,9 @@ const sendPasswordResetMail = async (resolve, root, args, context, resolveInfo)
const sendEmailVerificationMail = async (resolve, root, args, context, resolveInfo) => {
const response = await resolve(root, args, context, resolveInfo)
const { email, nonce, name } = response
await sendMail(emailVerificationTemplate({ email, variables: { nonce, name } }))
if (nonce) {
await sendMail(emailVerificationTemplate({ email, variables: { nonce, name } }))
}
delete response.nonce
return response
}

View File

@ -40,7 +40,9 @@ export default {
}
// check email does not belong to anybody
await existingEmailAddress({ args, context })
const existingEmail = await existingEmailAddress({ args, context })
if (existingEmail && existingEmail.alreadyExistingEmail && existingEmail.user)
return existingEmail.alreadyExistingEmail
const nonce = generateNonce()
const {

View File

@ -134,11 +134,17 @@ describe('AddEmailAddress', () => {
})
describe('but if another user owns an `EmailAddress` already with that email', () => {
it('throws UserInputError because of unique constraints', async () => {
it('does not throw UserInputError', async () => {
await Factory.build('user', {}, { email: 'new-email@example.org' })
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
data: { AddEmailAddress: null },
errors: [{ message: 'A user account with this email already exists.' }],
data: {
AddEmailAddress: {
createdAt: expect.any(String),
verifiedAt: null,
email: 'new-email@example.org',
},
},
errors: undefined,
})
})
})

View File

@ -118,9 +118,9 @@ describe('Signup', () => {
await emailAddress.relateTo(user, 'belongsTo')
})
it('throws UserInputError error because of unique constraint violation', async () => {
it('does not throw UserInputError error', async () => {
await expect(mutate({ mutation, variables })).resolves.toMatchObject({
errors: [{ message: 'A user account with this email already exists.' }],
data: { Signup: { email: 'someuser@example.org' } },
})
})
})