Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/backend/src/services/reimbursement-requests.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,13 +699,19 @@ export default class ReimbursementRequestService {
if (reimbursementRequest.organizationId !== organization.organizationId)
throw new InvalidOrganizationException('Reimbursement Request');

const existingWithSaboNumber = await prisma.reimbursement_Request.findFirst({
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add backend tests pls

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed those, and added some tests!

where: { saboId: saboNumber, organizationId: organization.organizationId }
});
if (existingWithSaboNumber) {
throw new HttpException(400, 'This SABO number is already assigned to another reimbursement request.');
}

const reimbursementRequestWithSaboNumber = await prisma.reimbursement_Request.update({
where: { reimbursementRequestId },
data: {
saboId: saboNumber
}
});

return reimbursementRequestWithSaboNumber;
}

Expand Down
24 changes: 24 additions & 0 deletions src/backend/tests/unit/reimbursement-requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -785,4 +785,28 @@ describe('Reimbursement Requests', () => {
).rejects.toThrow(new NotFoundException('Reimbursement Product Other Reason', 'bad id'));
});
});

describe('Setting the SABO number on a reimbursement request', () => {
test('Fails when SABO number is already assigned to a request', async () => {
await ReimbursementRequestService.setSaboNumber(
reimbursementRequest.reimbursementRequestId,
'SABO-001',
createdUser,
org
);
await expect(
ReimbursementRequestService.setSaboNumber(reimbursementRequest.reimbursementRequestId, 'SABO-001', createdUser, org)
).rejects.toThrow(new HttpException(400, 'This SABO number is already assigned to another reimbursement request.'));
});

test('Successfully sets the SABO number', async () => {
const result = await ReimbursementRequestService.setSaboNumber(
reimbursementRequest.reimbursementRequestId,
'SABO-001',
createdUser,
org
);
expect(result.saboId).toEqual('SABO-001');
});
});
});
2 changes: 1 addition & 1 deletion src/frontend/src/apis/finance.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ export const getPendingAdvisorList = () => {
* @param saboNumber the SABO number to set
*/
export const setSaboNumber = async (requestId: string, saboNumber: string) => {
axios.post(apiUrls.financeSetSaboNumber(requestId), {
return axios.post(apiUrls.financeSetSaboNumber(requestId), {
saboNumber
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ const AddSABONumberModal = ({ modalShow, onHide, reimbursementRequestId }: AddSA
const onSubmit = async (data: { saboNumber: string }) => {
try {
await setSaboNumber(data);
onHide();
} catch (error: unknown) {
if (error instanceof Error) {
toast.error(error.message);
}
}
onHide();
};

return (
Expand Down
Loading