feat(tags): add tags to test cases (#299)

This commit is contained in:
Eliezer Castro
2025-10-15 19:18:09 -03:00
committed by GitHub
parent 8fe288e875
commit 1ebf1a1572
17 changed files with 567 additions and 1 deletions

View File

@@ -24,11 +24,20 @@ vi.mock('../../middleware/verifyVisible.js', () => ({
// mock defineCase
const mockCase = {
findAll: vi.fn(),
belongsToMany: vi.fn(),
};
vi.mock('../../models/cases.js', () => ({
default: () => mockCase,
}));
const mockTags = {
belongsToMany: vi.fn(),
};
vi.mock('../../models/tags.js', () => ({
default: () => mockTags,
}));
describe('GET /cases', () => {
let app;
const sequelize = new Sequelize({
@@ -54,7 +63,16 @@ describe('GET /cases', () => {
mockCase.findAll.mockResolvedValue([{ id: 1 }]);
const res = await request(app).get('/cases?folderId=1');
expect(res.status).toBe(200);
expect(mockCase.findAll).toHaveBeenCalledWith({ where: { folderId: '1' } });
expect(mockCase.findAll).toHaveBeenCalledWith({
where: { folderId: '1' },
include: [
{
model: mockTags,
attributes: ['id', 'name'],
through: { attributes: [] },
},
],
});
expect(res.body).toEqual([{ id: 1 }]);
});
@@ -69,6 +87,13 @@ describe('GET /cases', () => {
priority: { [Op.in]: [1, 2] },
type: { [Op.in]: [3] },
},
include: [
{
model: mockTags,
attributes: ['id', 'name'],
through: { attributes: [] },
},
],
});
});
});