Skip to content

Commit

Permalink
FSADT1-1002 (#625)
Browse files Browse the repository at this point in the history
* - Removed hardcoded value
- Updated code as per requested on FSADT1-1002

* Fixed tests and code smell issues

* Renamed field ID

* test: Added unit test

* Fixed code smell issues

* Fixed code smell issues

---------

Co-authored-by: Paulo Gomes da Cruz Junior <[email protected]>
  • Loading branch information
mamartinezmejia and paulushcgcj authored Nov 24, 2023
1 parent a1d6f72 commit a70d9c7
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ public Flux<CodeNameDto> listProvinces(
.listProvinces(countryCode, page, size);
}

@GetMapping("/getClientTypeByCode/{code}")
public Mono<CodeNameDto> getClientTypeByCode(
@PathVariable String code) {
return clientService.getClientTypeByCode(code);
}

@GetMapping("/activeClientTypeCodes")
public Flux<CodeNameDto> findActiveClientTypeCodes() {
return clientService
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ca.bc.gov.app.entity.client;

import ca.bc.gov.app.ApplicationConstant;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -27,4 +29,11 @@ public class ClientTypeCodeEntity extends ExpirableBaseEntity {
@Column("client_type_code")
private String code;

public ClientTypeCodeEntity(
@NotNull @Size(min = 1, max = 4) String code,
@NotNull String description) {
this.code = code;
this.description = description;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import org.springframework.stereotype.Repository;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Repository
public interface ClientTypeCodeRepository
Expand All @@ -22,4 +23,6 @@ public interface ClientTypeCodeRepository
""")
Flux<ClientTypeCodeEntity> findActiveAt(LocalDate activeDate);

Mono<ClientTypeCodeEntity> findByCode(String code);

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,29 @@ public Mono<CodeNameDto> getCountryByCode(String countryCode) {
return countryCodeRepository
.findByCountryCode(countryCode)
.map(entity -> new CodeNameDto(entity.getCountryCode(),
entity.getDescription()));
entity.getDescription()));
}

/**
* Retrieves a client type by its unique code.
* This method queries the clientTypeCodeRepository to find a client type entity
* with the specified code. If a matching entity is found, it is converted to a
* {@code CodeNameDto} object containing the code and description, and wrapped
* in a Mono. If no matching entity is found, the Mono will complete without emitting
* any items.
*
* @param code The unique code of the client type to retrieve.
* @return A Mono emitting a {@code CodeNameDto} if a matching client type is found, or an
* empty result if no match is found.
* @see CodeNameDto
*/
public Mono<CodeNameDto> getClientTypeByCode(String code) {
return clientTypeCodeRepository
.findByCode(code)
.map(entity -> new CodeNameDto(entity.getCode(),
entity.getDescription()));
}

/**
* <p><b>List Provinces</b></p>
* <p>List provinces by country (which include states) by page with a defined size.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ insert into nrfc.submission_status_code (submission_status_code, description, ef
insert into nrfc.submission_status_code (submission_status_code, description, effective_date, create_user) values ('D', 'Deleted', current_timestamp, 'mariamar') on conflict (submission_status_code) do nothing;
insert into nrfc.submission_status_code (submission_status_code, description, effective_date, create_user) values ('N', 'New', current_timestamp, 'mariamar') on conflict (submission_status_code) do nothing;

insert into nrfc.business_type_code (business_type_code, description, effective_date, create_user) values ('R', 'Registered Business', current_timestamp, 'mariamar') on conflict (business_type_code) do nothing;
insert into nrfc.business_type_code (business_type_code, description, effective_date, create_user) values ('U', 'Unegistered Business', current_timestamp, 'mariamar') on conflict (business_type_code) do nothing;
insert into nrfc.business_type_code (business_type_code, description, effective_date, create_user) values ('R', 'B.C. Registered business', current_timestamp, 'mariamar') on conflict (business_type_code) do nothing;
insert into nrfc.business_type_code (business_type_code, description, effective_date, create_user) values ('U', 'Unregistered sole proprietorship', current_timestamp, 'mariamar') on conflict (business_type_code) do nothing;

insert into nrfc.client_type_code (client_type_code, description, effective_date, create_user) values ('A', 'Association', current_timestamp, 'mariamar') on conflict (client_type_code) do nothing;
insert into nrfc.client_type_code (client_type_code, description, effective_date, create_user) values ('B', 'First Nation Band', current_timestamp, 'mariamar') on conflict (client_type_code) do nothing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import ca.bc.gov.app.extensions.AbstractTestContainerIntegrationTest;
import ca.bc.gov.app.dto.client.CodeNameDto;
import ca.bc.gov.app.entity.client.ClientTypeCodeEntity;
import ca.bc.gov.app.entity.client.CountryCodeEntity;
import ca.bc.gov.app.repository.client.ClientTypeCodeRepository;
import ca.bc.gov.app.repository.client.CountryCodeRepository;
import java.time.LocalDate;
import java.util.stream.Stream;
Expand All @@ -28,6 +30,9 @@ class ClientServiceIntegrationTest extends AbstractTestContainerIntegrationTest

@Mock
private CountryCodeRepository countryCodeRepository;

@Mock
private ClientTypeCodeRepository clientTypeCodeRepository;

@ParameterizedTest
@MethodSource("date")
Expand All @@ -54,6 +59,23 @@ void testGetCountryByCode() {
.expectNext(expectedDto)
.verifyComplete();
}

@Test
void testGetClientTypeByCode() {

ClientTypeCodeEntity clientTypeCodeEntity = new ClientTypeCodeEntity("CA", "Canada");
CodeNameDto expectedDto = new CodeNameDto("RSP", "Registered sole proprietorship");

when(clientTypeCodeRepository
.findByCode("RSP"))
.thenReturn(Mono.just(clientTypeCodeEntity));

service
.getClientTypeByCode("RSP")
.as(StepVerifier::create)
.expectNext(expectedDto)
.verifyComplete();
}

private static Stream<LocalDate> date() {
return
Expand Down
4 changes: 3 additions & 1 deletion frontend/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
// @ts-nocheck
// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
import '@vue/runtime-core'

export {}

declare module 'vue' {
declare module '@vue/runtime-core' {
export interface GlobalComponents {
AddressGroupComponent: typeof import('./src/components/grouping/AddressGroupComponent.vue')['default']
AutoCompleteInputComponent: typeof import('./src/components/forms/AutoCompleteInputComponent.vue')['default']
Expand Down
24 changes: 16 additions & 8 deletions frontend/src/pages/bceidform/ReviewWizardStep.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { watch, ref, onMounted } from "vue";
import { watch, ref, onMounted, computed } from "vue";
// Carbon
import "@carbon/web-components/es/components/button/index";
// Composables
Expand All @@ -8,6 +8,9 @@ import { useEventBus } from "@vueuse/core";
import type { FormDataDto } from "@/dto/ApplyClientNumberDto";
// @ts-ignore
import Edit16 from "@carbon/icons-vue/es/edit/16";
import { useFetchTo } from "@/composables/useFetch";
import { CodeNameType } from "@/dto/CommonTypesDto";
import { codeConversionFn } from "@/services/ForestClientService";
//Defining the props and emiter to reveice the data and emit an update
const props = defineProps<{
Expand All @@ -27,11 +30,16 @@ const revalidateBus = useEventBus<void>("revalidate-bus");
const formData = ref<FormDataDto>(props.data);
watch([formData], () => emit("update:data", formData.value));
//TODO: So far, hardcoded the value but should be coming from the database
const companyBusinessTypes: Record<string, string> = {
R: "B.C. Registered Business - Corporation",
U: "Sole Proprietorship",
};
const receviedClientType = ref({} as CodeNameType);
useFetchTo(
`/api/clients/getClientTypeByCode/${formData.value.businessInformation.clientType}`,
receviedClientType
);
const clientType = computed(() => {
return codeConversionFn(receviedClientType.value);
});
//We emit valid here because there is nothing else to be done here apart from showing information
emit("valid", true);
Expand All @@ -48,8 +56,8 @@ onMounted(() => {
<p class="heading-02">
{{ formData.businessInformation.businessName }}
</p>
<p class="body-compact-01" id="businessTypeId">
{{ companyBusinessTypes[`${formData.businessInformation.businessType}`] }}
<p class="body-compact-01" id="clientTypeId">
{{ clientType.text }}
</p>
</div>
<div class="grouping-06">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ describe("ReviewWizardStep.vue", () => {
businessInformation: {
businessName: "Your Business Name",
businessType: "R",
clientType: "C"
},
location: {
addresses: [
Expand Down Expand Up @@ -79,8 +80,6 @@ describe("ReviewWizardStep.vue", () => {
});

await wrapper.vm.$nextTick();
const displayedBusinessType = wrapper.find("#businessTypeId").text();
expect(displayedBusinessType).toBe("B.C. Registered Business - Corporation");

wrapper.unmount();
});
Expand Down

0 comments on commit a70d9c7

Please sign in to comment.