Skip to content

Commit 4aac5ec

Browse files
authored
fix(uk) - handle exempt case that doesn't present file uploads (#714)
* fix(uk) - handle exempt case that doesn't present file uploads * add test
1 parent 048f779 commit 4aac5ec

2 files changed

Lines changed: 110 additions & 5 deletions

File tree

src/flows/ContractorOnboarding/api.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,15 @@ export const useUpdateUKandSaudiFields = (
348348
employmentId: employmentId,
349349
payload: ir35ContractDetailsPayload,
350350
});
351-
return uploadFileMutationAsync({
352-
employment_id: employmentId,
353-
file: ir35SdsFile,
354-
sub_type: IR35_FILE_SUBTYPE,
355-
});
351+
352+
if (ir35SdsFile) {
353+
return uploadFileMutationAsync({
354+
employment_id: employmentId,
355+
file: ir35SdsFile,
356+
sub_type: IR35_FILE_SUBTYPE,
357+
});
358+
}
359+
return Promise.resolve();
356360
}
357361
if (saudiNationalityStatus) {
358362
return createContractorContractDocumentMutationAsync({

src/flows/ContractorOnboarding/tests/ContractorOnboarding.test.tsx

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,5 +1946,106 @@ describe('ContractorOnboardingFlow', () => {
19461946
expect(fileDisplay).toBeInTheDocument();
19471947
});
19481948
});
1949+
1950+
it('should not call uploadFileMutationAsync when ir35 status is exempt', async () => {
1951+
const postSpy = vi.fn();
1952+
const contractDocumentSpy = vi.fn();
1953+
const uploadSpy = vi.fn();
1954+
1955+
server.use(
1956+
http.post('*/v1/employments', async ({ request }) => {
1957+
const requestBody = await request.json();
1958+
postSpy(requestBody);
1959+
return HttpResponse.json(mockContractorEmploymentResponse);
1960+
}),
1961+
http.post(
1962+
'*/v1/contractors/employments/*/contract-documents',
1963+
async ({ request }) => {
1964+
const requestBody = await request.json();
1965+
contractDocumentSpy(requestBody);
1966+
return HttpResponse.json(mockContractDocumentCreatedResponse);
1967+
},
1968+
),
1969+
http.post('*/v1/documents', async () => {
1970+
uploadSpy();
1971+
return HttpResponse.json({
1972+
data: {
1973+
file: {
1974+
id: 'ad8a15a5-88a5-4fb6-9225-2c4ec3e9a809',
1975+
name: 'test-file.pdf',
1976+
type: 'other',
1977+
inserted_at: '2026-01-16T15:33:28Z',
1978+
},
1979+
},
1980+
});
1981+
}),
1982+
);
1983+
1984+
mockRender.mockImplementation(
1985+
({
1986+
contractorOnboardingBag,
1987+
components,
1988+
}: ContractorOnboardingRenderProps) => {
1989+
const currentStepIndex =
1990+
contractorOnboardingBag.stepState.currentStep.index;
1991+
1992+
const steps: Record<number, string> = {
1993+
[0]: 'Basic Information',
1994+
[1]: 'Pricing Plan',
1995+
[2]: 'Contract Details',
1996+
[3]: 'Contract Preview',
1997+
[4]: 'Review',
1998+
};
1999+
2000+
return (
2001+
<>
2002+
<h1>Step: {steps[currentStepIndex]}</h1>
2003+
<MultiStepFormWithoutCountry
2004+
contractorOnboardingBag={contractorOnboardingBag}
2005+
components={components}
2006+
/>
2007+
</>
2008+
);
2009+
},
2010+
);
2011+
2012+
render(
2013+
<ContractorOnboardingFlow
2014+
countryCode='GBR'
2015+
skipSteps={['select_country']}
2016+
{...defaultProps}
2017+
/>,
2018+
{ wrapper: TestProviders },
2019+
);
2020+
2021+
await screen.findByText(/Step: Basic Information/i);
2022+
await waitForElementToBeRemoved(() => screen.getByTestId('spinner'));
2023+
2024+
// Fill basic information
2025+
await fillBasicInformation();
2026+
2027+
// Select IR35 status as 'exempt' (no file upload required)
2028+
const ir35Select = screen.getByLabelText(/IR35 Status/i);
2029+
fireEvent.change(ir35Select, { target: { value: 'exempt' } });
2030+
2031+
// Verify file upload field does NOT appear
2032+
await waitFor(() => {
2033+
const fileUploadField = screen.queryByLabelText(/Upload SDS/i);
2034+
expect(fileUploadField).not.toBeInTheDocument();
2035+
});
2036+
2037+
const nextButton = screen.getByText(/Next Step/i);
2038+
nextButton.click();
2039+
2040+
await waitFor(() => {
2041+
// Verify contract document was created with exempt status
2042+
expect(contractDocumentSpy).toHaveBeenCalled();
2043+
2044+
// Verify file upload was NOT called
2045+
expect(uploadSpy).not.toHaveBeenCalled();
2046+
});
2047+
2048+
await screen.findByText(/Step: Pricing Plan/i);
2049+
});
19492050
});
19502051
});

0 commit comments

Comments
 (0)