Skip to content

Commit

Permalink
feat: add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DevNono committed Sep 11, 2024
1 parent c6d3b82 commit 6a19835
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/admin/items/getItems.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,31 @@ describe('GET /admin/items', () => {
});

it('should return items list with proper stock and left value', async () => {
await database.item.update({
where: {
id: items[0].id,
},
data: {
display: false,
},
});

const { body } = await request(app).get(`/admin/items`).set('Authorization', `Bearer ${adminToken}`).expect(200);

expect(body).to.have.lengthOf(items.length);

for (const responseItem of body) {
expect(responseItem.left).to.be.equal(items.find((item) => item.name === responseItem.name)!.left);
expect(responseItem.stock).to.be.equal(items.find((item) => item.name === responseItem.name)!.stock);
}

await database.item.update({
where: {
id: items[0].id,
},
data: {
display: true,
},
});
});
});
27 changes: 27 additions & 0 deletions tests/items/getItems.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ describe('GET /items', () => {
await request(app).get('/items').expect(500, { error: Error.InternalServerError });
});

it('should not return the first item', async () => {
const items = await database.item.findMany();
const itemId = 'ticket-player';
await database.item.update({
where: {
id: itemId,
},
data: {
display: false,
},
});

const response = await request(app).get('/items').expect(200);

await database.item.update({
where: {
id: itemId,
},
data: {
display: true,
},
});
// without the "discount-switch-ssbu" item and the "ticket-player-ssbu", the "pc" (in rent category) and the 'ticket-player' item
expect(response.body).to.have.lengthOf(items.length - 4);
expect(response.body).not.to.have.deep.members([items[0]]);
});

it('should return 200 with an array of items', async () => {
const items = await database.item.findMany();
const response = await request(app).get('/items').expect(200);
Expand Down

0 comments on commit 6a19835

Please sign in to comment.