Skip to content

Commit

Permalink
fix: 1698 changing status when editing seedlot on review page (#1699)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaseta authored Nov 7, 2024
1 parent 803112f commit eebf0a1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import ca.bc.gov.backendstartapi.dto.SeedlotFormSubmissionDto;
import ca.bc.gov.backendstartapi.dto.SeedlotStatusResponseDto;
import ca.bc.gov.backendstartapi.entity.seedlot.Seedlot;
import ca.bc.gov.backendstartapi.exception.InvalidSeedlotStatusException;
import ca.bc.gov.backendstartapi.response.DefaultSpringExceptionResponse;
import ca.bc.gov.backendstartapi.response.ValidationExceptionResponse;
import ca.bc.gov.backendstartapi.security.RoleAccessConfig;
Expand Down Expand Up @@ -193,10 +192,6 @@ public ResponseEntity<SeedlotStatusResponseDto> submitSeedlotForm(
@RequestBody SeedlotFormSubmissionDto form) {
long started = Instant.now().toEpochMilli();
String formattedStatus = statusOnSave.toUpperCase();
if (!List.of("PND", "SUB", "APP").contains(formattedStatus)) {
throw new InvalidSeedlotStatusException(formattedStatus);
}

SeedlotStatusResponseDto updatedDto =
seedlotService.updateSeedlotWithForm(seedlotNumber, form, true, false, formattedStatus);
long finished = Instant.now().toEpochMilli();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,25 +244,4 @@ void editSeedlot_shouldFail() throws Exception {
.andExpect(status().isNotFound())
.andReturn();
}

@Test
@DisplayName("Edit seedlot should fail with invalid seedlot status.")
void editSeedlot_invalidStatus_shouldFail() throws Exception {
String seedlotNumber = "63999";
when(seedlotService.updateSeedlotWithForm(any(), any(), anyBoolean(), anyBoolean(), any()))
.thenThrow(new SeedlotNotFoundException());

mockMvc
.perform(
put(
"/api/tsc-admin/seedlots/{seedlotNumber}/edit?statusOnSave={statusOnSave}",
seedlotNumber,
"EXP")
.with(csrf().asHeader())
.header("Content-Type", MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.content(WHOLE_SEEDLOT_FORM_JSON))
.andExpect(status().isBadRequest())
.andReturn();
}
}
10 changes: 4 additions & 6 deletions frontend/src/api-service/tscAdminAPI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SeedlotsReturnType, TscSeedlotEditPayloadType } from '../types/SeedlotType';
import { SeedlotsReturnType, SeedlotStatusCode, TscSeedlotEditPayloadType } from '../types/SeedlotType';
import ApiConfig from './ApiConfig';
import api from './api';

Expand All @@ -12,17 +12,15 @@ export const getSeedlotToReview = (pageNumber: number, pageSize: number) => {
));
};

export type StatusOnSaveType = 'PND' | 'SUB' | 'APP';

export type PutTscSeedlotMutationObj = {
seedlotNum: string,
statusOnSave: StatusOnSaveType,
statusOnSave: SeedlotStatusCode,
payload: TscSeedlotEditPayloadType
}

export const putTscSeedlotWithStatus = (
seedlotNumber: string,
statusOnSave: StatusOnSaveType,
statusOnSave: SeedlotStatusCode,
payload: TscSeedlotEditPayloadType
) => {
const url = new URL(ApiConfig.tscSeedlotEdit.replace('{seedlotNumber}', seedlotNumber));
Expand All @@ -34,7 +32,7 @@ export const putTscSeedlotWithStatus = (

export const updateSeedlotStatus = (
seedlotNumber: string,
statusOnSave: StatusOnSaveType
statusOnSave: SeedlotStatusCode
) => {
const url = ApiConfig.tscSeedlotStatusUpdate.replace('{seedlotNumber}', seedlotNumber).replace('{status}', statusOnSave);

Expand Down
7 changes: 4 additions & 3 deletions frontend/src/views/Seedlot/SeedlotDetails/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import {

import { useQuery } from '@tanstack/react-query';
import { AxiosError } from 'axios';
import { SeedlotApplicantType, SeedlotDisplayType, SeedlotType } from '../../../types/SeedlotType';
import {
SeedlotApplicantType, SeedlotDisplayType, SeedlotStatusCode, SeedlotType
} from '../../../types/SeedlotType';

import PageTitle from '../../../components/PageTitle';
import ComboButton from '../../../components/ComboButton';
Expand All @@ -30,7 +32,6 @@ import { addParamToPath } from '../../../utils/PathUtils';
import { MEDIUM_SCREEN_WIDTH, MINISTRY_OF_FOREST_ID } from '../../../shared-constants/shared-constants';
import Breadcrumbs from '../../../components/Breadcrumbs';
import { getMultiOptList } from '../../../utils/MultiOptionsUtils';
import { StatusOnSaveType } from '../../../api-service/tscAdminAPI';
import AuthContext from '../../../contexts/AuthContext';

import SeedlotSummary from './SeedlotSummary';
Expand All @@ -51,7 +52,7 @@ const SeedlotDetails = () => {

const isSubmitSuccess = searchParams.get('isSubmitSuccess') === 'true';

const statusOnSave = searchParams.get('statusOnSave') as StatusOnSaveType | null;
const statusOnSave = searchParams.get('statusOnSave') as SeedlotStatusCode | null;

const viewOnlySeedlot: boolean = seedlotData?.seedlotStatus === 'Submitted'
|| seedlotData?.seedlotStatus === 'Expired'
Expand Down
16 changes: 10 additions & 6 deletions frontend/src/views/Seedlot/SeedlotReview/SeedlotReviewContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ import ExtractionStorageReviewEdit from '../../../components/SeedlotReviewSteps/
import AuditInfo from '../../../components/SeedlotReviewSteps/AuditInfo';

import {
PutTscSeedlotMutationObj, StatusOnSaveType, putTscSeedlotWithStatus,
PutTscSeedlotMutationObj, putTscSeedlotWithStatus,
updateSeedlotStatus
} from '../../../api-service/tscAdminAPI';
import {
SeedPlanZoneDto, SeedlotReviewElevationLatLongDto,
SeedlotReviewGeoInformationDto, TscSeedlotEditPayloadType
SeedlotReviewGeoInformationDto, SeedlotStatusCode, TscSeedlotEditPayloadType
} from '../../../types/SeedlotType';
import { ErrToastOption } from '../../../config/ToastifyConfig';
import AuthContext from '../../../contexts/AuthContext';
Expand Down Expand Up @@ -85,7 +85,7 @@ const SeedlotReviewContent = () => {
*/
const [isSaveStatusModalOpen, setIsSaveStatusModalOpen] = useState(false);

const [statusToUpdateTo, setStatusToUpdateTo] = useState<StatusOnSaveType>('PND');
const [statusToUpdateTo, setStatusToUpdateTo] = useState<SeedlotStatusCode>('PND');

const { seedlotNumber } = useParams();

Expand Down Expand Up @@ -462,15 +462,19 @@ const SeedlotReviewContent = () => {

if (isFormDataValid) {
const payload = generatePayload();
updateDraftMutation.mutate({ seedlotNum: seedlotNumber!, statusOnSave: 'SUB', payload });
updateDraftMutation.mutate({
seedlotNum: seedlotNumber!,
statusOnSave: seedlotData?.seedlotStatus.seedlotStatusCode ?? 'SUB',
payload
});
setIsReadMode(!isReadMode);
}
};

/**
* The handler for the send back to pending or approve buttons.
*/
const handleSaveAndStatus = (statusOnSave: StatusOnSaveType) => {
const handleSaveAndStatus = (statusOnSave: SeedlotStatusCode) => {
if (isReadMode) {
statusOnlyMutation.mutate({ seedlotNum: seedlotNumber!, statusOnSave });
} else {
Expand Down Expand Up @@ -498,7 +502,7 @@ const SeedlotReviewContent = () => {
setIsSaveStatusModalOpen(false);
};

const openSaveStatusModal = (status: StatusOnSaveType) => {
const openSaveStatusModal = (status: SeedlotStatusCode) => {
setStatusToUpdateTo(status);
setIsSaveStatusModalOpen(true);
};
Expand Down

0 comments on commit eebf0a1

Please sign in to comment.