Skip to content

Conversation

@swarkewalia
Copy link

ℹ️ Issue SSF-52
Closes https://vidushimisra.atlassian.net/browse/SSF-52

📝 Description
Added jest tests to the backend for /pantries, specifically for pantries.controller.ts and pantries.service.ts.

✔️ Verification
Ensured all tests are passing

@swarkewalia swarkewalia changed the title jest tests for pantries controller/service files [SSF-52] jest tests for pantries controller/service files Oct 16, 2025
@Juwang110 Juwang110 self-requested a review October 29, 2025 15:03
Copy link

@Juwang110 Juwang110 left a comment

Choose a reason for hiding this comment

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

Overall structure looks good! requires some refactoring though based on comments and using jest-mock-extended

});

// Get pantries with pending status
describe('getPendingPantries', () => {

Choose a reason for hiding this comment

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

Add a pantry that is not pending to assert this only gets pending ones

Choose a reason for hiding this comment

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

On second glance I don't think this is possible/easy since we are relying on repository filtering logic with "where", so this test is fine

@Juwang110 Juwang110 self-requested a review November 21, 2025 18:41
Copy link

@Juwang110 Juwang110 left a comment

Choose a reason for hiding this comment

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

besides one comment lgtm

Copy link
Collaborator

@sam-schu sam-schu left a comment

Choose a reason for hiding this comment

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

Looking good!

import { mock } from 'jest-mock-extended';
import { PantryApplicationDto } from './dtos/pantry-application.dto';

jest.mock('../utils/validation.utils', () => ({
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since validateId is a basic utils function that doesn't rely on the database, we shouldn't have to mock it in tests

Leaving the below here as a note for the future - don't worry about doing this now since service tests will have to be updated later to use the mock database
Also, for the service functions that call validateId, can we check that calling them with an ID that causes (the real implementation of) validateId to throw an error also causes the service function to error?


await service.addPantry(mockPantryApplication);

expect(mockRepository.save).toHaveBeenCalledWith(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add the rest of the application fields here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants