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

import { Pantry } from './pantries.entity';
import { User } from '../users/user.entity';
import { Role } from '../users/types';

Choose a reason for hiding this comment

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

Take a look at https://github.com/Code-4-Community/ssf/pull/40/files or other similar testing code changes. Sorry if this wasn't made clear but to be consistent we are using { mock } from 'jest-mock-extended' to construct type safe mocks with easier creation. You will need to refactor this and the service test file to do this but it shouldn't be that much effort.

questions: '',
itemsInStock: '',
needMoreOptions: '',
} as unknown as Pantry;

Choose a reason for hiding this comment

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

What does as unknown do? Is this necessary

import { NotFoundException } from '@nestjs/common';
import { User } from '../users/user.entity';
import { Role } from '../users/types';

Choose a reason for hiding this comment

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

Same thing, refactor to use 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


await expect(controller.denyPantry(999)).rejects.toThrow();
expect(service.deny).toHaveBeenCalledWith(999);
});

Choose a reason for hiding this comment

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

Test for submitPantryApplication?

await expect(service.findSSFRep(999)).rejects.toThrow(NotFoundException);
await expect(service.findSSFRep(999)).rejects.toThrow(
'Pantry 999 not found',
);

Choose a reason for hiding this comment

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

Add a test for addPantry

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants