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/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), 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) ); } diff --git a/frontend/src/pages/FormStaffPage.vue b/frontend/src/pages/FormStaffPage.vue index 3e70b90f37..d449af37b4 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", @@ -76,12 +80,15 @@ const clientTypesList: CodeNameType[] = [ { code: "F", name: "Ministry of Forests", - }, - { + } +]; + +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 7635a6aa67..672f843337 100644 --- a/frontend/tests/unittests/pages/FormStaffPage.spec.ts +++ b/frontend/tests/unittests/pages/FormStaffPage.spec.ts @@ -1,34 +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 '@/helpers/ForestClientUserSession'; -describe('FormStaffPage', () => { +// Mocking the ForestClientUserSession +vi.mock('@/helpers/ForestClientUserSession', () => ({ + default: { + authorities: [] + } +})); - it('renders the clientType dropdown with the expected order of elements', async () => { - const router = createRouter({ - history: createMemoryHistory(), - routes: [{ path: '/', component: FormStaffPage },], - }); +describe('FormStaffPage', () => { + 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'); + + const dropdownValues = Array.from(dropdownItems).map(item => item.textContent.trim()); + + const expectedDropdownValues = [ + 'Individual', + 'BC registered business', + 'First Nation', + 'Government', + 'Ministry of Forests', + ]; + + 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'); - // 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']); + + const expectedDropdownValues = [ + 'Individual', + 'BC registered business', + 'First Nation', + 'Government', + 'Ministry of Forests', + 'Unregistered company', + ]; + + expect(dropdownValues).toEqual(expectedDropdownValues); }); -}); \ No newline at end of file +});