Skip to content

Commit 8341a06

Browse files
authored
Fix Verify Account Mutation (canada-ca#2380)
1 parent 4ddd986 commit 8341a06

2 files changed

Lines changed: 21 additions & 148 deletions

File tree

api-js/src/user/mutations/__tests__/verify-account.test.js

Lines changed: 7 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -205,64 +205,6 @@ describe('user send password reset email', () => {
205205
})
206206
})
207207
describe('given an unsuccessful validation', () => {
208-
describe('userKey is undefined', () => {
209-
it('returns an error message', async () => {
210-
const token = tokenize({
211-
parameters: { userKey: 1 },
212-
})
213-
214-
const response = await graphql(
215-
schema,
216-
`
217-
mutation {
218-
verifyAccount(input: { verifyTokenString: "${token}" }) {
219-
result {
220-
... on VerifyAccountResult {
221-
status
222-
}
223-
... on VerifyAccountError {
224-
code
225-
description
226-
}
227-
}
228-
}
229-
}
230-
`,
231-
null,
232-
{
233-
i18n,
234-
request,
235-
userKey: undefined,
236-
query,
237-
auth: {
238-
verifyToken: verifyToken({}),
239-
},
240-
validators: {
241-
cleanseInput,
242-
},
243-
loaders: {
244-
loadUserByKey: loadUserByKey({ query }),
245-
},
246-
},
247-
)
248-
249-
const error = {
250-
data: {
251-
verifyAccount: {
252-
result: {
253-
code: 400,
254-
description: 'Unable to verify account. Please try again.',
255-
},
256-
},
257-
},
258-
}
259-
260-
expect(response).toEqual(error)
261-
expect(consoleOutput).toEqual([
262-
`User attempted to verify their account, but the userKey is undefined.`,
263-
])
264-
})
265-
})
266208
describe('user cannot be found in db', () => {
267209
it('returns an error message', async () => {
268210
const token = tokenize({
@@ -308,7 +250,7 @@ describe('user send password reset email', () => {
308250
verifyAccount: {
309251
result: {
310252
code: 400,
311-
description: 'Unable to verify account. Please try again.',
253+
description: 'Unable to verify account. Please request a new email.',
312254
},
313255
},
314256
},
@@ -391,7 +333,7 @@ describe('user send password reset email', () => {
391333

392334
expect(response).toEqual(error)
393335
expect(consoleOutput).toEqual([
394-
`When validating account user: ${user._key} attempted to verify account, but userKey is not located in the token parameters.`,
336+
`When validating account, user attempted to verify account, but userKey is not located in the token parameters.`,
395337
])
396338
})
397339
})
@@ -466,7 +408,7 @@ describe('user send password reset email', () => {
466408

467409
expect(response).toEqual(error)
468410
expect(consoleOutput).toEqual([
469-
`When validating account user: ${user._key} attempted to verify account, but userKey is not located in the token parameters.`,
411+
`When validating account, user attempted to verify account, but userKey is not located in the token parameters.`,
470412
])
471413
})
472414
})
@@ -541,7 +483,7 @@ describe('user send password reset email', () => {
541483

542484
expect(response).toEqual(error)
543485
expect(consoleOutput).toEqual([
544-
`User: ${user._key} attempted to verify their account, but the user id's do not match.`,
486+
`User: 1 attempted to verify account, however no account is associated with this id.`,
545487
])
546488
})
547489
})
@@ -769,64 +711,6 @@ describe('user send password reset email', () => {
769711
})
770712
})
771713
describe('given an unsuccessful validation', () => {
772-
describe('userKey is undefined', () => {
773-
it('returns an error message', async () => {
774-
const token = tokenize({
775-
parameters: { userKey: 1 },
776-
})
777-
778-
const response = await graphql(
779-
schema,
780-
`
781-
mutation {
782-
verifyAccount(input: { verifyTokenString: "${token}" }) {
783-
result {
784-
... on VerifyAccountResult {
785-
status
786-
}
787-
... on VerifyAccountError {
788-
code
789-
description
790-
}
791-
}
792-
}
793-
}
794-
`,
795-
null,
796-
{
797-
i18n,
798-
request,
799-
userKey: undefined,
800-
query,
801-
auth: {
802-
verifyToken: verifyToken({}),
803-
},
804-
validators: {
805-
cleanseInput,
806-
},
807-
loaders: {
808-
loadUserByKey: loadUserByKey({ query }),
809-
},
810-
},
811-
)
812-
813-
const error = {
814-
data: {
815-
verifyAccount: {
816-
result: {
817-
code: 400,
818-
description: 'todo',
819-
},
820-
},
821-
},
822-
}
823-
824-
expect(response).toEqual(error)
825-
expect(consoleOutput).toEqual([
826-
`User attempted to verify their account, but the userKey is undefined.`,
827-
])
828-
})
829-
})
830714
describe('user cannot be found in db', () => {
831715
it('returns an error message', async () => {
832716
const token = tokenize({
@@ -954,7 +838,7 @@ describe('user send password reset email', () => {
954838

955839
expect(response).toEqual(error)
956840
expect(consoleOutput).toEqual([
957-
`When validating account user: ${user._key} attempted to verify account, but userKey is not located in the token parameters.`,
841+
`When validating account, user attempted to verify account, but userKey is not located in the token parameters.`,
958842
])
959843
})
960844
})
@@ -1028,7 +912,7 @@ describe('user send password reset email', () => {
1028912

1029913
expect(response).toEqual(error)
1030914
expect(consoleOutput).toEqual([
1031-
`When validating account user: ${user._key} attempted to verify account, but userKey is not located in the token parameters.`,
915+
`When validating account, user attempted to verify account, but userKey is not located in the token parameters.`,
1032916
])
1033917
})
1034918
})
@@ -1102,7 +986,7 @@ describe('user send password reset email', () => {
1102986

1103987
expect(response).toEqual(error)
1104988
expect(consoleOutput).toEqual([
1105-
`User: ${user._key} attempted to verify their account, but the user id's do not match.`,
989+
`User: 1 attempted to verify account, however no account is associated with this id.`,
1106990
])
1107991
})
1108992
})

api-js/src/user/mutations/verify-account.js

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export const verifyAccount = new mutationWithClientMutationId({
2727
{
2828
i18n,
2929
query,
30-
userKey,
3130
auth: { verifyToken },
3231
loaders: { loadUserByKey },
3332
validators: { cleanseInput },
@@ -36,19 +35,29 @@ export const verifyAccount = new mutationWithClientMutationId({
3635
// Cleanse Input
3736
const verifyTokenString = cleanseInput(args.verifyTokenString)
3837

39-
if (typeof userKey === 'undefined') {
38+
// Get info from token
39+
const tokenParameters = verifyToken({ token: verifyTokenString })
40+
41+
// Check to see if userKey exists in tokenParameters
42+
if (
43+
tokenParameters.userKey === 'undefined' ||
44+
typeof tokenParameters.userKey === 'undefined'
45+
) {
4046
console.warn(
41-
`User attempted to verify their account, but the userKey is undefined.`,
47+
`When validating account, user attempted to verify account, but userKey is not located in the token parameters.`,
4248
)
4349
return {
4450
_type: 'error',
4551
code: 400,
46-
description: i18n._(t`Unable to verify account. Please try again.`),
52+
description: i18n._(
53+
t`Unable to verify account. Please request a new email.`,
54+
),
4755
}
4856
}
4957

5058
// Auth shouldn't be needed with this
5159
// Check if user exists
60+
const { userKey } = tokenParameters
5261
const user = await loadUserByKey.load(userKey)
5362

5463
if (typeof user === 'undefined') {
@@ -58,27 +67,7 @@ export const verifyAccount = new mutationWithClientMutationId({
5867
return {
5968
_type: 'error',
6069
code: 400,
61-
description: i18n._(t`Unable to verify account. Please try again.`),
62-
}
63-
}
64-
65-
// Get info from token
66-
const tokenParameters = verifyToken({ token: verifyTokenString })
67-
68-
// Check to see if userKey exists in tokenParameters
69-
if (
70-
tokenParameters.userKey === 'undefined' ||
71-
typeof tokenParameters.userKey === 'undefined'
72-
) {
73-
console.warn(
74-
`When validating account user: ${user._key} attempted to verify account, but userKey is not located in the token parameters.`,
75-
)
76-
return {
77-
_type: 'error',
78-
code: 400,
79-
description: i18n._(
80-
t`Unable to verify account. Please request a new email.`,
81-
),
70+
description: i18n._(t`Unable to verify account. Please request a new email.`),
8271
}
8372
}
8473

0 commit comments

Comments
 (0)