Skip to content

[SSF-52] jest tests for pantries controller/service files#55

Merged
swarkewalia merged 20 commits intomainfrom
sk/SSF-52-backend-pantries-tests
Feb 1, 2026
Merged

[SSF-52] jest tests for pantries controller/service files#55
swarkewalia merged 20 commits intomainfrom
sk/SSF-52-backend-pantries-tests

Conversation

@swarkewalia
Copy link
Copy Markdown

ℹ️ 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
Copy Markdown

@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', () => {
Copy link
Copy Markdown

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

Copy link
Copy Markdown

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
Copy Markdown

@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
Copy Markdown
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
Copy Markdown
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?

@sam-schu sam-schu added blocked and removed blocked labels Jan 22, 2026
@swarkewalia swarkewalia requested a review from sam-schu January 30, 2026 01:04
@swarkewalia swarkewalia requested a review from sam-schu February 1, 2026 04:26
Copy link
Copy Markdown
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.

LGTM!

@swarkewalia swarkewalia merged commit e176666 into main Feb 1, 2026
3 of 4 checks passed
@swarkewalia swarkewalia deleted the sk/SSF-52-backend-pantries-tests branch February 1, 2026 19:40
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.

5 participants