Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 108 additions & 1 deletion api-js/src/user/mutations/__tests__/verify-account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,64 @@ describe('user send password reset email', () => {
user = await cursor.next()

expect(response).toEqual(expectedResult)
expect(user.emailValidated).toEqual(true)
expect(consoleOutput).toEqual([
`User: ${user._key} successfully email validated their account.`,
])
})
it('sets emailValidated to true', async () => {
let cursor = await query`
FOR user IN users
FILTER user.userName == "test.account@istio.actually.exists"
RETURN user
`
let user = await cursor.next()

const token = tokenize({ parameters: { userKey: user._key } })

await graphql(
schema,
`
mutation {
verifyAccount(input: { verifyTokenString: "${token}" }) {
result {
... on VerifyAccountResult {
status
}
... on VerifyAccountError {
code
description
}
}
}
}
`,
null,
{
i18n,
request,
userKey: user._key,
query,
auth: {
verifyToken: verifyToken({}),
},
validators: {
cleanseInput,
},
loaders: {
userLoaderByKey: userLoaderByKey(query),
},
},
)

cursor = await query`
FOR user IN users
FILTER user.userName == "test.account@istio.actually.exists"
RETURN user
`
user = await cursor.next()

expect(user.emailValidated).toEqual(true)
})
})
describe('given an unsuccessful validation', () => {
describe('userKey is undefined', () => {
Expand Down Expand Up @@ -660,6 +713,60 @@ describe('user send password reset email', () => {
`User: ${user._key} successfully email validated their account.`,
])
})
it('sets emailValidated to true', async () => {
let cursor = await query`
FOR user IN users
FILTER user.userName == "test.account@istio.actually.exists"
RETURN user
`
let user = await cursor.next()

const token = tokenize({ parameters: { userKey: user._key } })

await graphql(
schema,
`
mutation {
verifyAccount(input: { verifyTokenString: "${token}" }) {
result {
... on VerifyAccountResult {
status
}
... on VerifyAccountError {
code
description
}
}
}
}
`,
null,
{
i18n,
request,
userKey: user._key,
query,
auth: {
verifyToken: verifyToken({}),
},
validators: {
cleanseInput,
},
loaders: {
userLoaderByKey: userLoaderByKey(query),
},
},
)

cursor = await query`
FOR user IN users
FILTER user.userName == "test.account@istio.actually.exists"
RETURN user
`
user = await cursor.next()

expect(user.emailValidated).toEqual(true)
})
})
describe('given an unsuccessful validation', () => {
describe('userKey is undefined', () => {
Expand Down
4 changes: 2 additions & 2 deletions api-js/src/user/mutations/verify-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ export const verifyAccount = new mutationWithClientMutationId({
try {
await query`
UPSERT { _key: ${user._key} }
INSERT { emailValidated: true, tfaSendMethod: 'email' }
UPDATE { emailValidated: true, tfaSendMethod: 'email' }
INSERT { emailValidated: true }
UPDATE { emailValidated: true }
IN users
`
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions api-js/src/user/mutations/verify-phone-number.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ export const verifyPhoneNumber = new mutationWithClientMutationId({
try {
await query`
UPSERT { _key: ${user._key} }
INSERT { phoneValidated: true, tfaSendMethod: 'phone' }
UPDATE { phoneValidated: true, tfaSendMethod: 'phone' }
INSERT { phoneValidated: true }
UPDATE { phoneValidated: true }
IN users
`
} catch (err) {
Expand Down