From 3c85ddb387a7dc7b3f94e14194886778ad8f0b15 Mon Sep 17 00:00:00 2001 From: Jia Xu Date: Fri, 11 Aug 2023 16:26:05 -0700 Subject: [PATCH] 14946 - Add a new dialog for account missing email and phone (#561) * add new dialog for account missing email and phone * 5.4.2 * add error types as enums * remove extra code --- package-lock.json | 4 +- package.json | 2 +- src/App.vue | 25 +++++-- src/dialogs/AccountContactMissingDialog.vue | 66 +++++++++++++++++++ src/dialogs/index.ts | 1 + src/enums/errorTypes.ts | 7 ++ src/enums/index.ts | 1 + .../unit/AccountContactMissingDialog.spec.ts | 56 ++++++++++++++++ 8 files changed, 153 insertions(+), 9 deletions(-) create mode 100644 src/dialogs/AccountContactMissingDialog.vue create mode 100644 src/enums/errorTypes.ts create mode 100644 tests/unit/AccountContactMissingDialog.spec.ts diff --git a/package-lock.json b/package-lock.json index 39a656c44..25a4625bd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "business-create-ui", - "version": "5.4.1", + "version": "5.4.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "business-create-ui", - "version": "5.4.1", + "version": "5.4.2", "dependencies": { "@babel/compat-data": "^7.21.5", "@bcrs-shared-components/approval-type": "1.0.19", diff --git a/package.json b/package.json index 1ef9a9515..04434be02 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "business-create-ui", - "version": "5.4.1", + "version": "5.4.2", "private": true, "appName": "Create UI", "sbcName": "SBC Common Components", diff --git a/src/App.vue b/src/App.vue index b0991aa4a..155f4fc64 100644 --- a/src/App.vue +++ b/src/App.vue @@ -25,6 +25,12 @@ @retry="fetchData()" /> + + { console.log('User info error =', error) // eslint-disable-line no-console - this.accountAuthorizationDialog = true + if ([ErrorTypes.INVALID_USER_EMAIL, ErrorTypes.INVALID_USER_PHONE].includes(error.message)) { + this.accountContactMissingDialog = true + } else { + this.accountAuthorizationDialog = true + } throw error // go to catch() }) @@ -966,6 +978,7 @@ export default class App extends Mixins(CommonMixin, DateMixin, FilingTemplateMi this.nameRequestInvalidErrorDialog = false this.invalidFilingDialog = false this.accountAuthorizationDialog = false + this.accountContactMissingDialog = false this.fetchErrorDialog = false this.filingSurveyDialog = false this.paymentErrorDialog = false @@ -996,7 +1009,7 @@ export default class App extends Mixins(CommonMixin, DateMixin, FilingTemplateMi // NB: will throw if API error const userInfo = await AuthServices.fetchUserInfo() - if (!userInfo) throw new Error('Invalid user info') + if (!userInfo) throw new Error(ErrorTypes.INVALID_USER_INFO) if (userInfo.contacts?.length > 0 && userInfo.contacts[0].email) { // this is a BCSC user @@ -1005,7 +1018,7 @@ export default class App extends Mixins(CommonMixin, DateMixin, FilingTemplateMi // this is an IDIR user this.setUserEmail(userInfo.email) } else if (userInfo.type !== this.STAFF_ROLE && userInfo.type !== this.GOV_ACCOUNT_USER) { - throw new Error('Invalid user email') + throw new Error(ErrorTypes.INVALID_USER_EMAIL) } if (userInfo.contacts?.length > 0 && userInfo.contacts[0].phone) { @@ -1019,8 +1032,8 @@ export default class App extends Mixins(CommonMixin, DateMixin, FilingTemplateMi console.info('Invalid user phone') // eslint-disable-line no-console } - if (!userInfo.firstname) throw new Error('Invalid user first name') - if (!userInfo.lastname) throw new Error('Invalid user last name') + if (!userInfo.firstname) throw new Error(ErrorTypes.INVALID_USER_FIRST_NAME) + if (!userInfo.lastname) throw new Error(ErrorTypes.INVALID_USER_LAST_NAME) this.setUserFirstName(userInfo.firstname) this.setUserLastName(userInfo.lastname) diff --git a/src/dialogs/AccountContactMissingDialog.vue b/src/dialogs/AccountContactMissingDialog.vue new file mode 100644 index 000000000..f7da634e7 --- /dev/null +++ b/src/dialogs/AccountContactMissingDialog.vue @@ -0,0 +1,66 @@ + + + diff --git a/src/dialogs/index.ts b/src/dialogs/index.ts index 078604141..f27934037 100644 --- a/src/dialogs/index.ts +++ b/src/dialogs/index.ts @@ -4,6 +4,7 @@ */ export { default as AccountAuthorizationDialog } from './AccountAuthorizationDialog.vue' +export { default as AccountContactMissingDialog } from './AccountContactMissingDialog.vue' export { default as FetchErrorDialog } from './FetchErrorDialog.vue' export { default as FileAndPayInvalidNameRequestDialog } from './FileAndPayInvalidNameRequestDialog.vue' export { default as FilingSurveyDialog } from './FilingSurveyDialog.vue' diff --git a/src/enums/errorTypes.ts b/src/enums/errorTypes.ts new file mode 100644 index 000000000..e458c3c40 --- /dev/null +++ b/src/enums/errorTypes.ts @@ -0,0 +1,7 @@ +export enum ErrorTypes { + INVALID_USER_INFO='Invalid user info', + INVALID_USER_EMAIL='Invalid user email', + INVALID_USER_FIRST_NAME='Invalid user first name', + INVALID_USER_LAST_NAME = 'Invalid user last name', + INVALID_USER_PHONE='Invalid user phone' +} diff --git a/src/enums/index.ts b/src/enums/index.ts index 8db70ff41..60629de01 100644 --- a/src/enums/index.ts +++ b/src/enums/index.ts @@ -13,6 +13,7 @@ export * from './pdfPageSize' export * from './routeNames' export * from './ruleIds' export * from './views' +export * from './errorTypes' // external enums export { CorpTypeCd } from '@bcrs-shared-components/corp-type-module' diff --git a/tests/unit/AccountContactMissingDialog.spec.ts b/tests/unit/AccountContactMissingDialog.spec.ts new file mode 100644 index 000000000..d16212b26 --- /dev/null +++ b/tests/unit/AccountContactMissingDialog.spec.ts @@ -0,0 +1,56 @@ +import { shallowMount } from '@vue/test-utils' +import AccountContactMissingDialog from '@/dialogs/AccountContactMissingDialog.vue' +import Vuetify from 'vuetify' +import Vue from 'vue' + +Vue.use(Vuetify) + +// Prevent the warning "[Vuetify] Unable to locate target [data-app]" +document.body.setAttribute('data-app', 'true') + +describe('AccountContactMissingDialog.vue', () => { + let vuetify: any + + beforeEach(() => { + vuetify = new Vuetify() + }) + + it('renders the dialog', () => { + const wrapper = shallowMount(AccountContactMissingDialog, { + vuetify, + propsData: { dialog: true } + }) + expect(wrapper.find('#dialog-title').text()).toBe('Account Error') + }) + + it('redirects to user profile on OK click', () => { + // Mocking sessionStorage + const sessionStorageMock = { + getItem () { + return 'https://dev.account.bcregistry.gov.bc.ca' + } + } + Object.defineProperty(window, 'sessionStorage', { value: sessionStorageMock }) + + // Mounting the component + const wrapper = shallowMount(AccountContactMissingDialog, { + vuetify, + propsData: { dialog: true } + }) + + // Override window.location.href + let redirectedUrl = '' + // eslint-disable-next-line accessor-pairs + Object.defineProperty(window.location, 'href', { + set (url: string) { + redirectedUrl = url + } + }) + + // Calling the method directly + wrapper.vm.redirectToUserProfile() + + // Checking the logic inside the method + expect(redirectedUrl).toBe('https://dev.account.bcregistry.gov.bc.ca/userprofile') + }) +})