From 058800e805e3a6499831f332340ee20edaa11b12 Mon Sep 17 00:00:00 2001 From: Maria Martinez Date: Tue, 13 Aug 2024 14:41:43 -0700 Subject: [PATCH 1/6] feat(FSADT1-1429): Unregistered business client type is only viewed by role ADMIN --- .../BusinessInformationBusinessNameValidator.java | 5 +++-- frontend/src/pages/FormStaffPage.vue | 10 +++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/ca/bc/gov/app/validator/business/BusinessInformationBusinessNameValidator.java b/backend/src/main/java/ca/bc/gov/app/validator/business/BusinessInformationBusinessNameValidator.java index 468dcab932..a851e9c752 100644 --- a/backend/src/main/java/ca/bc/gov/app/validator/business/BusinessInformationBusinessNameValidator.java +++ b/backend/src/main/java/ca/bc/gov/app/validator/business/BusinessInformationBusinessNameValidator.java @@ -5,6 +5,7 @@ import ca.bc.gov.app.dto.ValidationError; import ca.bc.gov.app.dto.client.BusinessTypeEnum; import ca.bc.gov.app.dto.client.ClientBusinessInformationDto; +import ca.bc.gov.app.dto.client.ClientTypeEnum; import ca.bc.gov.app.dto.client.ValidationSourceEnum; import ca.bc.gov.app.validator.ForestClientValidator; import io.micrometer.observation.annotation.Observed; @@ -44,8 +45,8 @@ public Mono validate(ClientBusinessInformationDto target, Integ } if ( - BusinessTypeEnum.U.equals( - BusinessTypeEnum.fromValue(target.businessType()) + ClientTypeEnum.USP.equals( + ClientTypeEnum.fromValue(target.clientType()) ) && !target.businessName().matches(".*\\s+.*") ) { return Mono.just( diff --git a/frontend/src/pages/FormStaffPage.vue b/frontend/src/pages/FormStaffPage.vue index 5e10d24293..657ef0084b 100644 --- a/frontend/src/pages/FormStaffPage.vue +++ b/frontend/src/pages/FormStaffPage.vue @@ -51,11 +51,15 @@ import LocationsWizardStep from "@/pages/staffform/LocationsWizardStep.vue"; import ContactsWizardStep from "@/pages/staffform/ContactsWizardStep.vue"; import ReviewWizardStep from "@/pages/staffform/ReviewWizardStep.vue"; +// Session +import ForestClientUserSession from "@/helpers/ForestClientUserSession"; + // @ts-ignore import ArrowRight16 from "@carbon/icons-vue/es/arrow--right/16"; -// @ts-ignore import Check16 from "@carbon/icons-vue/es/checkmark/16"; +const isAdminInd = ["CLIENT_ADMIN"].some(authority => ForestClientUserSession.authorities.includes(authority)); + const clientTypesList: CodeNameType[] = [ { code: "I", @@ -77,10 +81,10 @@ const clientTypesList: CodeNameType[] = [ code: "F", name: "Ministry of Forests", }, - { + ...(isAdminInd ? [{ code: "U", name: "Unregistered company", - }, + }] : []), ]; const notificationBus = useEventBus( From 2ab150d74c91eb0e67d75501258dffcb4482a8a9 Mon Sep 17 00:00:00 2001 From: Maria Martinez Date: Tue, 13 Aug 2024 15:16:57 -0700 Subject: [PATCH 2/6] fix: fixed test --- ...inessInformationBusinessNameValidatorTest.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/backend/src/test/java/ca/bc/gov/app/validator/business/BusinessInformationBusinessNameValidatorTest.java b/backend/src/test/java/ca/bc/gov/app/validator/business/BusinessInformationBusinessNameValidatorTest.java index a4e2a24647..9a2fea4a01 100644 --- a/backend/src/test/java/ca/bc/gov/app/validator/business/BusinessInformationBusinessNameValidatorTest.java +++ b/backend/src/test/java/ca/bc/gov/app/validator/business/BusinessInformationBusinessNameValidatorTest.java @@ -31,6 +31,7 @@ void shouldSupportAllValidationSources(ValidationSourceEnum source, boolean supp void shouldValidate( String businessName, String businessType, + String clientType, String expectedMessage ) { @@ -40,7 +41,7 @@ void shouldValidate( StringUtils.EMPTY, businessName, businessType, - StringUtils.EMPTY, + clientType, StringUtils.EMPTY, StringUtils.EMPTY, null, @@ -75,12 +76,12 @@ void shouldValidate( private static Stream validation() { return Stream.of( - Arguments.of(StringUtils.EMPTY, StringUtils.EMPTY, "You must enter a business name."), - Arguments.of(StringUtils.EMPTY, "R", "You must select your B.C. registered business name from the list."), - Arguments.of("Mainé", StringUtils.EMPTY, "Mainé has an invalid character."), - Arguments.of("Corporation".repeat(6), StringUtils.EMPTY, "This field has a 60 character limit."), - Arguments.of("Corporation", "U", "Business name must be composed of first and last name"), - Arguments.of("Corporation", "R", StringUtils.EMPTY) + Arguments.of(StringUtils.EMPTY, StringUtils.EMPTY, StringUtils.EMPTY, "You must enter a business name."), + Arguments.of(StringUtils.EMPTY, "R", StringUtils.EMPTY, "You must select your B.C. registered business name from the list."), + Arguments.of("Mainé", StringUtils.EMPTY, StringUtils.EMPTY, "Mainé has an invalid character."), + Arguments.of("Corporation".repeat(6), StringUtils.EMPTY, StringUtils.EMPTY, "This field has a 60 character limit."), + Arguments.of("Corporation", StringUtils.EMPTY, "USP", "Business name must be composed of first and last name"), + Arguments.of("Corporation", "R", StringUtils.EMPTY, StringUtils.EMPTY) ); } From f409515ebfa856595099fb2767695e2f4c6fffb6 Mon Sep 17 00:00:00 2001 From: Maria Martinez Date: Tue, 13 Aug 2024 15:26:55 -0700 Subject: [PATCH 3/6] fix: fixed test --- backend/src/test/java/ca/bc/gov/app/TestConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/src/test/java/ca/bc/gov/app/TestConstants.java b/backend/src/test/java/ca/bc/gov/app/TestConstants.java index 5f2ee8dc06..53766091b1 100644 --- a/backend/src/test/java/ca/bc/gov/app/TestConstants.java +++ b/backend/src/test/java/ca/bc/gov/app/TestConstants.java @@ -636,7 +636,7 @@ public class TestConstants { "", "forest1", "U", - "I", + "USP", "", "SP", LocalDate.of(1975, 1, 31), From ec85fbd39d75d3b6bff98b5c73251496d27a126b Mon Sep 17 00:00:00 2001 From: Maria Martinez Date: Tue, 13 Aug 2024 15:47:02 -0700 Subject: [PATCH 4/6] fix: fixed test --- .../tests/unittests/pages/FormStaffPage.spec.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/frontend/tests/unittests/pages/FormStaffPage.spec.ts b/frontend/tests/unittests/pages/FormStaffPage.spec.ts index 7635a6aa67..74bfdf8dff 100644 --- a/frontend/tests/unittests/pages/FormStaffPage.spec.ts +++ b/frontend/tests/unittests/pages/FormStaffPage.spec.ts @@ -2,6 +2,10 @@ import { createRouter, createMemoryHistory } from 'vue-router'; import { describe, it, expect } from "vitest"; import { mount } from '@vue/test-utils'; import FormStaffPage from '@/pages/FormStaffPage.vue'; +import ForestClientUserSession from '../../../src/helpers/ForestClientUserSession'; + + +const isAdminInd = ["CLIENT_ADMIN"].some(authority => ForestClientUserSession.authorities.includes(authority)); describe('FormStaffPage', () => { @@ -29,6 +33,12 @@ describe('FormStaffPage', () => { // Extract the text content from each dropdown item const dropdownValues = Array.from(dropdownItems).map(item => item.textContent.trim()); - expect(dropdownValues).toEqual(['Individual','BC registered business','First Nation','Government','Ministry of Forests','Unregistered company']); + expect(dropdownValues).toEqual([ + 'Individual', + 'BC registered business', + 'First Nation','Government', + 'Ministry of Forests', + ...(isAdminInd ? ['Unregistered company'] : []) + ]) }); -}); \ No newline at end of file +}); From c95dc5464523a72773a17bbd7c9c813927f656aa Mon Sep 17 00:00:00 2001 From: Maria Martinez Date: Wed, 14 Aug 2024 13:39:49 -0700 Subject: [PATCH 5/6] Changes after code reviews --- frontend/src/pages/FormStaffPage.vue | 11 ++- .../unittests/pages/FormStaffPage.spec.ts | 76 ++++++++++++++----- 2 files changed, 65 insertions(+), 22 deletions(-) diff --git a/frontend/src/pages/FormStaffPage.vue b/frontend/src/pages/FormStaffPage.vue index 657ef0084b..ffe984221b 100644 --- a/frontend/src/pages/FormStaffPage.vue +++ b/frontend/src/pages/FormStaffPage.vue @@ -80,12 +80,15 @@ const clientTypesList: CodeNameType[] = [ { code: "F", name: "Ministry of Forests", - }, - ...(isAdminInd ? [{ + } +]; + +if (isAdminInd) { + clientTypesList.push({ code: "U", name: "Unregistered company", - }] : []), -]; + }); +} const notificationBus = useEventBus( "error-notification" diff --git a/frontend/tests/unittests/pages/FormStaffPage.spec.ts b/frontend/tests/unittests/pages/FormStaffPage.spec.ts index 74bfdf8dff..34c7245234 100644 --- a/frontend/tests/unittests/pages/FormStaffPage.spec.ts +++ b/frontend/tests/unittests/pages/FormStaffPage.spec.ts @@ -1,44 +1,84 @@ import { createRouter, createMemoryHistory } from 'vue-router'; -import { describe, it, expect } from "vitest"; +import { describe, it, expect, vi } from "vitest"; import { mount } from '@vue/test-utils'; import FormStaffPage from '@/pages/FormStaffPage.vue'; import ForestClientUserSession from '../../../src/helpers/ForestClientUserSession'; - -const isAdminInd = ["CLIENT_ADMIN"].some(authority => ForestClientUserSession.authorities.includes(authority)); +// Mocking the ForestClientUserSession +vi.mock('../../../src/helpers/ForestClientUserSession', () => ({ + default: { + authorities: [] + } +})); describe('FormStaffPage', () => { + const router = createRouter({ + history: createMemoryHistory(), + routes: [{ path: '/', component: FormStaffPage }], + }); - it('renders the clientType dropdown with the expected order of elements', async () => { - const router = createRouter({ - history: createMemoryHistory(), - routes: [{ path: '/', component: FormStaffPage },], - }); - - const wrapper = mount(FormStaffPage, { + const mountComponent = () => { + return mount(FormStaffPage, { global: { plugins: [router], }, }); + }; + + it('renders the clientType dropdown with the expected order of elements for a non-admin user', async () => { + // Mock as non-admin user + ForestClientUserSession.authorities = []; + + const wrapper = mountComponent(); const clientTypeDropdown = wrapper.find('#clientType'); - + // Extract the innerHTML of the dropdown const dropdownHTML = clientTypeDropdown.element.innerHTML; - + // Parse the innerHTML to extract the text content of each dropdown item const parser = new DOMParser(); const doc = parser.parseFromString(`${dropdownHTML}`, 'text/html'); const dropdownItems = doc.querySelectorAll('cds-combo-box-item'); - // Extract the text content from each dropdown item const dropdownValues = Array.from(dropdownItems).map(item => item.textContent.trim()); - - expect(dropdownValues).toEqual([ + + const expectedDropdownValues = [ 'Individual', 'BC registered business', - 'First Nation','Government', + 'First Nation', + 'Government', 'Ministry of Forests', - ...(isAdminInd ? ['Unregistered company'] : []) - ]) + ]; + + expect(dropdownValues).toEqual(expectedDropdownValues); + }); + + it('renders the clientType dropdown with the expected order of elements for an admin user', async () => { + // Mock as admin user + ForestClientUserSession.authorities = ['CLIENT_ADMIN']; + + const wrapper = mountComponent(); + const clientTypeDropdown = wrapper.find('#clientType'); + + // Extract the innerHTML of the dropdown + const dropdownHTML = clientTypeDropdown.element.innerHTML; + + // Parse the innerHTML to extract the text content of each dropdown item + const parser = new DOMParser(); + const doc = parser.parseFromString(`${dropdownHTML}`, 'text/html'); + const dropdownItems = doc.querySelectorAll('cds-combo-box-item'); + + const dropdownValues = Array.from(dropdownItems).map(item => item.textContent.trim()); + + const expectedDropdownValues = [ + 'Individual', + 'BC registered business', + 'First Nation', + 'Government', + 'Ministry of Forests', + 'Unregistered company', + ]; + + expect(dropdownValues).toEqual(expectedDropdownValues); }); }); From 075c59a4fb33eb52823ccb2c586545afe55997c8 Mon Sep 17 00:00:00 2001 From: Maria Martinez Date: Wed, 14 Aug 2024 14:05:18 -0700 Subject: [PATCH 6/6] no message --- frontend/tests/unittests/pages/FormStaffPage.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/tests/unittests/pages/FormStaffPage.spec.ts b/frontend/tests/unittests/pages/FormStaffPage.spec.ts index 34c7245234..672f843337 100644 --- a/frontend/tests/unittests/pages/FormStaffPage.spec.ts +++ b/frontend/tests/unittests/pages/FormStaffPage.spec.ts @@ -2,10 +2,10 @@ import { createRouter, createMemoryHistory } from 'vue-router'; import { describe, it, expect, vi } from "vitest"; import { mount } from '@vue/test-utils'; import FormStaffPage from '@/pages/FormStaffPage.vue'; -import ForestClientUserSession from '../../../src/helpers/ForestClientUserSession'; +import ForestClientUserSession from '@/helpers/ForestClientUserSession'; // Mocking the ForestClientUserSession -vi.mock('../../../src/helpers/ForestClientUserSession', () => ({ +vi.mock('@/helpers/ForestClientUserSession', () => ({ default: { authorities: [] }