From f24f0211464d331aa7188063cd77da77dec0a323 Mon Sep 17 00:00:00 2001 From: nsdeschenes Date: Fri, 5 Mar 2021 09:55:57 -0400 Subject: [PATCH 1/8] update translations --- api-js/src/locale/en/messages.js | 2 ++ api-js/src/locale/en/messages.po | 10 +++++----- api-js/src/locale/fr/messages.js | 2 ++ api-js/src/locale/fr/messages.po | 10 +++++----- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/api-js/src/locale/en/messages.js b/api-js/src/locale/en/messages.js index 100b2042f0..3b6fd2bb8c 100644 --- a/api-js/src/locale/en/messages.js +++ b/api-js/src/locale/en/messages.js @@ -365,6 +365,8 @@ 'Unable to update domain. Please try again.', 'Unable to update organization. Please try again.': 'Unable to update organization. Please try again.', + 'Unable to update password, authentication error occurred, please sign in again.': + 'Unable to update password, authentication error occurred, please sign in again.', 'Unable to update password, current password does not match. Please try again.': 'Unable to update password, current password does not match. Please try again.', 'Unable to update password, new passwords do not match. Please try again.': diff --git a/api-js/src/locale/en/messages.po b/api-js/src/locale/en/messages.po index df8e2dd3ad..60a63e1d09 100644 --- a/api-js/src/locale/en/messages.po +++ b/api-js/src/locale/en/messages.po @@ -285,7 +285,7 @@ msgstr "Successfully dispatched one time scan." msgid "Successfully email verified account, and set TFA send method to email." msgstr "Successfully email verified account, and set TFA send method to email." -#: src/affiliation/mutations/invite-user-to-org.js:171 +#: src/affiliation/mutations/invite-user-to-org.js:172 msgid "Successfully invited user to organization, and sent notification email." msgstr "Successfully invited user to organization, and sent notification email." @@ -301,7 +301,7 @@ msgstr "Successfully removed organization: {0}." msgid "Successfully removed user from organization." msgstr "Successfully removed user from organization." -#: src/affiliation/mutations/invite-user-to-org.js:119 +#: src/affiliation/mutations/invite-user-to-org.js:120 msgid "Successfully sent invitation to service, and organization email." msgstr "Successfully sent invitation to service, and organization email." @@ -464,9 +464,9 @@ msgid "Unable to find verified organization. Please try again." msgstr "Unable to find verified organization. Please try again." #: src/affiliation/mutations/invite-user-to-org.js:79 -#: src/affiliation/mutations/invite-user-to-org.js:92 -#: src/affiliation/mutations/invite-user-to-org.js:147 -#: src/affiliation/mutations/invite-user-to-org.js:162 +#: src/affiliation/mutations/invite-user-to-org.js:93 +#: src/affiliation/mutations/invite-user-to-org.js:148 +#: src/affiliation/mutations/invite-user-to-org.js:163 msgid "Unable to invite user. Please try again." msgstr "Unable to invite user. Please try again." diff --git a/api-js/src/locale/fr/messages.js b/api-js/src/locale/fr/messages.js index 0b0ec120fb..8642c2f493 100644 --- a/api-js/src/locale/fr/messages.js +++ b/api-js/src/locale/fr/messages.js @@ -180,6 +180,8 @@ 'Unable to two factor authenticate. Please try again.': 'todo', 'Unable to update domain. Please try again.': 'todo', 'Unable to update organization. Please try again.': 'todo', + 'Unable to update password, authentication error occurred, please sign in again.': + 'todo', 'Unable to update password, current password does not match. Please try again.': 'todo', 'Unable to update password, new passwords do not match. Please try again.': diff --git a/api-js/src/locale/fr/messages.po b/api-js/src/locale/fr/messages.po index 322c082fdd..be769f704c 100644 --- a/api-js/src/locale/fr/messages.po +++ b/api-js/src/locale/fr/messages.po @@ -285,7 +285,7 @@ msgstr "todo" msgid "Successfully email verified account, and set TFA send method to email." msgstr "todo" -#: src/affiliation/mutations/invite-user-to-org.js:171 +#: src/affiliation/mutations/invite-user-to-org.js:172 msgid "Successfully invited user to organization, and sent notification email." msgstr "todo" @@ -301,7 +301,7 @@ msgstr "todo" msgid "Successfully removed user from organization." msgstr "todo" -#: src/affiliation/mutations/invite-user-to-org.js:119 +#: src/affiliation/mutations/invite-user-to-org.js:120 msgid "Successfully sent invitation to service, and organization email." msgstr "todo" @@ -464,9 +464,9 @@ msgid "Unable to find verified organization. Please try again." msgstr "todo" #: src/affiliation/mutations/invite-user-to-org.js:79 -#: src/affiliation/mutations/invite-user-to-org.js:92 -#: src/affiliation/mutations/invite-user-to-org.js:147 -#: src/affiliation/mutations/invite-user-to-org.js:162 +#: src/affiliation/mutations/invite-user-to-org.js:93 +#: src/affiliation/mutations/invite-user-to-org.js:148 +#: src/affiliation/mutations/invite-user-to-org.js:163 msgid "Unable to invite user. Please try again." msgstr "todo" From b3676434a558e50e64585aec7c19f3f47e2c8168 Mon Sep 17 00:00:00 2001 From: nsdeschenes Date: Fri, 5 Mar 2021 09:56:18 -0400 Subject: [PATCH 2/8] create new objects for the update user password union --- .../update-user-password-error.test.js | 39 +++++++++++++++++++ .../update-user-password-result.test.js | 24 ++++++++++++ api-js/src/user/objects/index.js | 2 + .../objects/update-user-password-error.js | 19 +++++++++ .../objects/update-user-password-result.js | 15 +++++++ 5 files changed, 99 insertions(+) create mode 100644 api-js/src/user/objects/__tests__/update-user-password-error.test.js create mode 100644 api-js/src/user/objects/__tests__/update-user-password-result.test.js create mode 100644 api-js/src/user/objects/update-user-password-error.js create mode 100644 api-js/src/user/objects/update-user-password-result.js diff --git a/api-js/src/user/objects/__tests__/update-user-password-error.test.js b/api-js/src/user/objects/__tests__/update-user-password-error.test.js new file mode 100644 index 0000000000..2f2937ed24 --- /dev/null +++ b/api-js/src/user/objects/__tests__/update-user-password-error.test.js @@ -0,0 +1,39 @@ +import { GraphQLInt, GraphQLString } from 'graphql' + +import { updateUserPasswordErrorType } from '../update-user-password-error' + +describe('given the updateUserPasswordErrorType object', () => { + describe('testing the field definitions', () => { + it('has an code field', () => { + const demoType = updateUserPasswordErrorType.getFields() + + expect(demoType).toHaveProperty('code') + expect(demoType.code.type).toMatchObject(GraphQLInt) + }) + it('has a description field', () => { + const demoType = updateUserPasswordErrorType.getFields() + + expect(demoType).toHaveProperty('description') + expect(demoType.description.type).toMatchObject(GraphQLString) + }) + }) + + describe('testing the field resolvers', () => { + describe('testing the code resolver', () => { + it('returns the resolved field', () => { + const demoType = updateUserPasswordErrorType.getFields() + + expect(demoType.code.resolve({ code: 400 })).toEqual(400) + }) + }) + describe('testing the description field', () => { + it('returns the resolved value', () => { + const demoType = updateUserPasswordErrorType.getFields() + + expect( + demoType.description.resolve({ description: 'description' }), + ).toEqual('description') + }) + }) + }) +}) diff --git a/api-js/src/user/objects/__tests__/update-user-password-result.test.js b/api-js/src/user/objects/__tests__/update-user-password-result.test.js new file mode 100644 index 0000000000..b4688b7e53 --- /dev/null +++ b/api-js/src/user/objects/__tests__/update-user-password-result.test.js @@ -0,0 +1,24 @@ +import { GraphQLString } from 'graphql' + +import { updateUserPasswordResultType } from '../update-user-password-result' + +describe('given the updateUserPasswordResultType object', () => { + describe('testing the field definitions', () => { + it('has an status field', () => { + const demoType = updateUserPasswordResultType.getFields() + + expect(demoType).toHaveProperty('status') + expect(demoType.status.type).toMatchObject(GraphQLString) + }) + }) + + describe('testing the field resolvers', () => { + describe('testing the status resolver', () => { + it('returns the resolved field', () => { + const demoType = updateUserPasswordResultType.getFields() + + expect(demoType.status.resolve({ status: 'status' })).toEqual('status') + }) + }) + }) +}) diff --git a/api-js/src/user/objects/index.js b/api-js/src/user/objects/index.js index b3b39d2f49..123f126fee 100644 --- a/api-js/src/user/objects/index.js +++ b/api-js/src/user/objects/index.js @@ -7,5 +7,7 @@ export * from './send-phone-code-result' export * from './sign-in-error' export * from './sign-up-error' export * from './tfa-sign-in-result' +export * from './update-user-password-error' +export * from './update-user-password-result' export * from './user-personal' export * from './user-shared' diff --git a/api-js/src/user/objects/update-user-password-error.js b/api-js/src/user/objects/update-user-password-error.js new file mode 100644 index 0000000000..7708ba6106 --- /dev/null +++ b/api-js/src/user/objects/update-user-password-error.js @@ -0,0 +1,19 @@ +import { GraphQLInt, GraphQLObjectType, GraphQLString } from 'graphql' + +export const updateUserPasswordErrorType = new GraphQLObjectType({ + name: 'UpdateUserPasswordError', + description: + 'This object is used to inform the user if any errors occurred while updating their password.', + fields: () => ({ + code: { + type: GraphQLInt, + description: 'Error code to inform user what the issue is related to.', + resolve: ({ code }) => code, + }, + description: { + type: GraphQLString, + description: 'Description of the issue that was encountered.', + resolve: ({ description }) => description, + }, + }), +}) diff --git a/api-js/src/user/objects/update-user-password-result.js b/api-js/src/user/objects/update-user-password-result.js new file mode 100644 index 0000000000..4ab81653f2 --- /dev/null +++ b/api-js/src/user/objects/update-user-password-result.js @@ -0,0 +1,15 @@ +import { GraphQLObjectType, GraphQLString } from 'graphql' + +export const updateUserPasswordResultType = new GraphQLObjectType({ + name: 'UpdateUserPasswordResultType', + description: + 'This object is used to inform the user that no errors were encountered while updating their password.', + fields: () => ({ + status: { + type: GraphQLString, + description: + 'Informs the user if their password was successfully updated.', + resolve: ({ status }) => status, + }, + }), +}) From 67b965e62854aa1241ee6f03d4ceafe50a1d4137 Mon Sep 17 00:00:00 2001 From: nsdeschenes Date: Fri, 5 Mar 2021 09:56:32 -0400 Subject: [PATCH 3/8] create update-user-password-union --- .../update-user-password-union.test.js | 48 +++++++++++++++++++ api-js/src/user/unions/index.js | 1 + .../user/unions/update-user-password-union.js | 19 ++++++++ 3 files changed, 68 insertions(+) create mode 100644 api-js/src/user/unions/__tests__/update-user-password-union.test.js create mode 100644 api-js/src/user/unions/update-user-password-union.js diff --git a/api-js/src/user/unions/__tests__/update-user-password-union.test.js b/api-js/src/user/unions/__tests__/update-user-password-union.test.js new file mode 100644 index 0000000000..850aa2a905 --- /dev/null +++ b/api-js/src/user/unions/__tests__/update-user-password-union.test.js @@ -0,0 +1,48 @@ +import { + updateUserPasswordErrorType, + updateUserPasswordResultType, +} from '../../objects/index' +import { updateUserPasswordUnion } from '../update-user-password-union' + +describe('given the updateUserPasswordUnion', () => { + describe('testing the field types', () => { + it('contains updateUserPasswordResultType', () => { + const demoType = updateUserPasswordUnion.getTypes() + + expect(demoType).toContain(updateUserPasswordResultType) + }) + it('contains updateUserPasswordErrorType', () => { + const demoType = updateUserPasswordUnion.getTypes() + + expect(demoType).toContain(updateUserPasswordErrorType) + }) + }) + describe('testing the field selection', () => { + describe('testing the updateUserPasswordResultType', () => { + it('returns the correct type', () => { + const obj = { + _type: 'regular', + authResult: {}, + } + + expect(updateUserPasswordUnion.resolveType(obj)).toMatchObject( + updateUserPasswordResultType, + ) + }) + }) + describe('testing the updateUserPasswordErrorType', () => { + it('returns the correct type', () => { + const obj = { + _type: 'error', + error: 'sign-in-error', + code: 401, + description: 'text', + } + + expect(updateUserPasswordUnion.resolveType(obj)).toMatchObject( + updateUserPasswordErrorType, + ) + }) + }) + }) +}) diff --git a/api-js/src/user/unions/index.js b/api-js/src/user/unions/index.js index 38b33db64c..0b1d33b563 100644 --- a/api-js/src/user/unions/index.js +++ b/api-js/src/user/unions/index.js @@ -3,3 +3,4 @@ export * from './reset-password-union' export * from './send-phone-code-union' export * from './sign-in-union' export * from './sign-up-union' +export * from './update-user-password-union' diff --git a/api-js/src/user/unions/update-user-password-union.js b/api-js/src/user/unions/update-user-password-union.js new file mode 100644 index 0000000000..f5b63b38b8 --- /dev/null +++ b/api-js/src/user/unions/update-user-password-union.js @@ -0,0 +1,19 @@ +import { GraphQLUnionType } from 'graphql' +import { + updateUserPasswordErrorType, + updateUserPasswordResultType, +} from '../objects' + +export const updateUserPasswordUnion = new GraphQLUnionType({ + name: 'UpdateUserPasswordUnion', + description: + 'This union is used with the `updateUserPassword` mutation, allowing for users to update their password, and support any errors that may occur', + types: [updateUserPasswordErrorType, updateUserPasswordResultType], + resolveType({ _type }) { + if (_type === 'regular') { + return updateUserPasswordResultType + } else { + return updateUserPasswordErrorType + } + }, +}) From 52eac32475ddb6d6c6bdb2b0337a0a760bb0273f Mon Sep 17 00:00:00 2001 From: nsdeschenes Date: Fri, 5 Mar 2021 09:56:41 -0400 Subject: [PATCH 4/8] update the mutation to use the new union --- .../__tests__/update-user-password.test.js | 299 +++++++++++++++--- .../user/mutations/update-user-password.js | 54 +++- 2 files changed, 284 insertions(+), 69 deletions(-) diff --git a/api-js/src/user/mutations/__tests__/update-user-password.test.js b/api-js/src/user/mutations/__tests__/update-user-password.test.js index 28c949baed..858b4674c9 100644 --- a/api-js/src/user/mutations/__tests__/update-user-password.test.js +++ b/api-js/src/user/mutations/__tests__/update-user-password.test.js @@ -129,7 +129,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -155,7 +163,9 @@ describe('authenticate user account', () => { const expectedResponse = { data: { updateUserPassword: { - status: 'Password was successfully updated.', + result: { + status: 'Password was successfully updated.', + }, }, }, } @@ -235,7 +245,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -258,11 +276,19 @@ describe('authenticate user account', () => { }, ) - const error = [ - new GraphQLError('Authentication error, please sign in again.'), - ] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: + 'Unable to update password, authentication error occurred, please sign in again.', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ 'User attempted to update password, but the user id is undefined.', ]) @@ -281,7 +307,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -304,11 +338,19 @@ describe('authenticate user account', () => { }, ) - const error = [ - new GraphQLError('Unable to update password. Please try again.'), - ] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: + 'Unable to update password, authentication error occurred, please sign in again.', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ `User: 1 attempted to update their password, but no account is associated with that id.`, ]) @@ -327,7 +369,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -350,13 +400,19 @@ describe('authenticate user account', () => { }, ) - const error = [ - new GraphQLError( - 'Unable to update password, current password does not match. Please try again.', - ), - ] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: + 'Unable to update password, current password does not match. Please try again.', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ `User: ${user._key} attempted to update their password, however they did not enter the current password correctly.`, ]) @@ -375,7 +431,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "oldtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -398,13 +462,19 @@ describe('authenticate user account', () => { }, ) - const error = [ - new GraphQLError( - 'Unable to update password, new passwords do not match. Please try again.', - ), - ] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: + 'Unable to update password, new passwords do not match. Please try again.', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ `User: ${user._key} attempted to update their password, however the new passwords do not match.`, ]) @@ -423,7 +493,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "password" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -446,13 +524,19 @@ describe('authenticate user account', () => { }, ) - const error = [ - new GraphQLError( - 'Unable to update password, passwords are required to be 12 characters or longer. Please try again.', - ), - ] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: + 'Unable to update password, passwords are required to be 12 characters or longer. Please try again.', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ `User: ${user._key} attempted to update their password, however the new password does not meet GoC requirements.`, ]) @@ -478,7 +562,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -541,7 +633,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -567,7 +667,9 @@ describe('authenticate user account', () => { const expectedResponse = { data: { updateUserPassword: { - status: 'todo', + result: { + status: 'todo', + }, }, }, } @@ -647,7 +749,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -670,9 +780,18 @@ describe('authenticate user account', () => { }, ) - const error = [new GraphQLError('todo')] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: 'todo', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ 'User attempted to update password, but the user id is undefined.', ]) @@ -691,7 +810,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -714,9 +841,18 @@ describe('authenticate user account', () => { }, ) - const error = [new GraphQLError('todo')] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: 'todo', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ `User: 1 attempted to update their password, but no account is associated with that id.`, ]) @@ -735,7 +871,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -758,9 +902,18 @@ describe('authenticate user account', () => { }, ) - const error = [new GraphQLError('todo')] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: 'todo', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ `User: ${user._key} attempted to update their password, however they did not enter the current password correctly.`, ]) @@ -779,7 +932,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "oldtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -802,9 +963,18 @@ describe('authenticate user account', () => { }, ) - const error = [new GraphQLError('todo')] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: 'todo', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ `User: ${user._key} attempted to update their password, however the new passwords do not match.`, ]) @@ -823,7 +993,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "password" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, @@ -846,9 +1024,18 @@ describe('authenticate user account', () => { }, ) - const error = [new GraphQLError('todo')] + const error = { + data: { + updateUserPassword: { + result: { + code: 400, + description: 'todo', + }, + }, + }, + } - expect(response.errors).toEqual(error) + expect(response).toEqual(error) expect(consoleOutput).toEqual([ `User: ${user._key} attempted to update their password, however the new password does not meet GoC requirements.`, ]) @@ -874,7 +1061,15 @@ describe('authenticate user account', () => { updatedPasswordConfirm: "newtestpassword123" } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } `, diff --git a/api-js/src/user/mutations/update-user-password.js b/api-js/src/user/mutations/update-user-password.js index 3d0fd1afcf..44f5f13d6d 100644 --- a/api-js/src/user/mutations/update-user-password.js +++ b/api-js/src/user/mutations/update-user-password.js @@ -2,6 +2,8 @@ import { GraphQLString, GraphQLNonNull } from 'graphql' import { mutationWithClientMutationId } from 'graphql-relay' import { t } from '@lingui/macro' +import { updateUserPasswordUnion } from '../unions' + export const updateUserPassword = new mutationWithClientMutationId({ name: 'UpdateUserPassword', description: @@ -22,12 +24,11 @@ export const updateUserPassword = new mutationWithClientMutationId({ }, }), outputFields: () => ({ - status: { - type: GraphQLString, - description: 'The status if the user profile update was successful.', - resolve: async (payload) => { - return payload.status - }, + result: { + type: updateUserPasswordUnion, + description: + '`UpdateUserPasswordUnion` returning either a `UpdateUserPasswordResultType`, or `UpdateUserPasswordError` object.', + resolve: (payload) => payload, }, }), mutateAndGetPayload: async ( @@ -51,7 +52,13 @@ export const updateUserPassword = new mutationWithClientMutationId({ console.warn( `User attempted to update password, but the user id is undefined.`, ) - throw new Error(i18n._(t`Authentication error, please sign in again.`)) + return { + _type: 'error', + code: 400, + description: i18n._( + t`Unable to update password, authentication error occurred, please sign in again.`, + ), + } } // Get user from db @@ -61,7 +68,13 @@ export const updateUserPassword = new mutationWithClientMutationId({ console.warn( `User: ${userKey} attempted to update their password, but no account is associated with that id.`, ) - throw new Error(i18n._(t`Unable to update password. Please try again.`)) + return { + _type: 'error', + code: 400, + description: i18n._( + t`Unable to update password, authentication error occurred, please sign in again.`, + ), + } } // Check to see if current passwords match @@ -69,11 +82,13 @@ export const updateUserPassword = new mutationWithClientMutationId({ console.warn( `User: ${user._key} attempted to update their password, however they did not enter the current password correctly.`, ) - throw new Error( - i18n._( + return { + _type: 'error', + code: 400, + description: i18n._( t`Unable to update password, current password does not match. Please try again.`, ), - ) + } } // Check to see if new passwords match @@ -81,11 +96,13 @@ export const updateUserPassword = new mutationWithClientMutationId({ console.warn( `User: ${user._key} attempted to update their password, however the new passwords do not match.`, ) - throw new Error( - i18n._( + return { + _type: 'error', + code: 400, + description: i18n._( t`Unable to update password, new passwords do not match. Please try again.`, ), - ) + } } // Check to see if they meet GoC requirements @@ -93,11 +110,13 @@ export const updateUserPassword = new mutationWithClientMutationId({ console.warn( `User: ${user._key} attempted to update their password, however the new password does not meet GoC requirements.`, ) - throw new Error( - i18n._( + return { + _type: 'error', + code: 400, + description: i18n._( t`Unable to update password, passwords are required to be 12 characters or longer. Please try again.`, ), - ) + } } // Update password in DB @@ -117,6 +136,7 @@ export const updateUserPassword = new mutationWithClientMutationId({ console.info(`User: ${user._key} successfully updated their password.`) return { + _type: 'regular', status: i18n._(t`Password was successfully updated.`), } }, From 42ee75402f1973a6b04186a58a7efba73bfcc116 Mon Sep 17 00:00:00 2001 From: nsdeschenes Date: Fri, 5 Mar 2021 10:02:44 -0400 Subject: [PATCH 5/8] update faker --- frontend/schema.faker.graphql | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/frontend/schema.faker.graphql b/frontend/schema.faker.graphql index 80fa5f8aad..9fae6af14b 100644 --- a/frontend/schema.faker.graphql +++ b/frontend/schema.faker.graphql @@ -1886,6 +1886,14 @@ type UpdateOrganizationPayload { clientMutationId: String } +# This object is used to inform the user if any errors occurred while updating their password. +type UpdateUserPasswordError { + # Error code to inform user what the issue is related to. + code: Int + # Description of the issue that was encountered. + description: String +} + input UpdateUserPasswordInput { # The users current password to verify it is the current user. currentPassword: String! @@ -1897,11 +1905,23 @@ input UpdateUserPasswordInput { } type UpdateUserPasswordPayload { - # The status if the user profile update was successful. - status: String + # `UpdateUserPasswordUnion` returning either a `UpdateUserPasswordResultType`, or `UpdateUserPasswordError` object. + result: UpdateUserPasswordUnion clientMutationId: String } +# This object is used to inform the user that no errors were encountered while updating their password. +type UpdateUserPasswordResultType { + # Informs the user if their password was successfully updated. + status: String +} + +# This union is used with the `updateUserPassword` mutation, allowing for users to +# update their password, and support any errors that may occur +union UpdateUserPasswordUnion = + UpdateUserPasswordError + | UpdateUserPasswordResultType + input UpdateUserProfileInput { # The updated display name the user wishes to change to. displayName: String From d15ed17b80f687485ee88167cb6853df28e7ee4f Mon Sep 17 00:00:00 2001 From: nsdeschenes Date: Fri, 5 Mar 2021 10:02:53 -0400 Subject: [PATCH 6/8] update mutation string --- frontend/src/graphql/mutations.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/frontend/src/graphql/mutations.js b/frontend/src/graphql/mutations.js index d801ce26ce..e0d269dcfb 100644 --- a/frontend/src/graphql/mutations.js +++ b/frontend/src/graphql/mutations.js @@ -161,7 +161,15 @@ export const UPDATE_USER_PASSWORD = gql` updatedPasswordConfirm: $updatedPasswordConfirm } ) { - status + result { + ... on UpdateUserPasswordResultType { + status + } + ... on UpdateUserPasswordError { + code + description + } + } } } ` From ffe9b5f5de02f152000b8052cdab1dac9b28f288 Mon Sep 17 00:00:00 2001 From: nsdeschenes Date: Fri, 5 Mar 2021 10:02:59 -0400 Subject: [PATCH 7/8] update component --- frontend/src/EditableUserPassword.js | 46 ++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 10 deletions(-) diff --git a/frontend/src/EditableUserPassword.js b/frontend/src/EditableUserPassword.js index 0d1d3d9a08..61d540436e 100644 --- a/frontend/src/EditableUserPassword.js +++ b/frontend/src/EditableUserPassword.js @@ -51,16 +51,42 @@ function EditableUserPassword() { position: 'top-left', }) }, - onCompleted() { - toast({ - title: t`Changed User Password`, - description: t`You have successfully updated your password.`, - status: 'success', - duration: 9000, - isClosable: true, - position: 'top-left', - }) - onClose() + onCompleted({ updateUserPassword }) { + if ( + updateUserPassword.result.__typeName === + 'UpdateUserPasswordResultType' + ) { + toast({ + title: t`Changed User Password`, + description: t`You have successfully updated your password.`, + status: 'success', + duration: 9000, + isClosable: true, + position: 'top-left', + }) + onClose() + } else if ( + updateUserPassword.result.__typeName === 'UpdateUserPasswordError' + ) { + toast({ + title: t`Unable to update your password, please try again.`, + description: updateUserPassword.result.description, + status: 'error', + duration: 9000, + isClosable: true, + position: 'top-left', + }) + } else { + toast({ + title: t`Incorrect send method received.`, + description: t`Incorrect updateUserPassword.result typename.`, + status: 'error', + duration: 9000, + isClosable: true, + position: 'top-left', + }) + console.log('Incorrect updateUserPassword.result typename.') + } }, }, ) From 563710d08833bfec8b3c80d9bb0b2c5b7c4ac095 Mon Sep 17 00:00:00 2001 From: nsdeschenes Date: Mon, 8 Mar 2021 06:34:05 -0400 Subject: [PATCH 8/8] fix property name --- frontend/src/EditableUserPassword.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/EditableUserPassword.js b/frontend/src/EditableUserPassword.js index 61d540436e..6831b8df9f 100644 --- a/frontend/src/EditableUserPassword.js +++ b/frontend/src/EditableUserPassword.js @@ -53,7 +53,7 @@ function EditableUserPassword() { }, onCompleted({ updateUserPassword }) { if ( - updateUserPassword.result.__typeName === + updateUserPassword.result.__typename === 'UpdateUserPasswordResultType' ) { toast({ @@ -66,7 +66,7 @@ function EditableUserPassword() { }) onClose() } else if ( - updateUserPassword.result.__typeName === 'UpdateUserPasswordError' + updateUserPassword.result.__typename === 'UpdateUserPasswordError' ) { toast({ title: t`Unable to update your password, please try again.`,