Skip to content

Commit

Permalink
feat: adding test for createCart (user)
Browse files Browse the repository at this point in the history
  • Loading branch information
Antoine D committed Oct 6, 2024
1 parent a9bc61c commit 96c4b12
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions tests/users/createCart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,19 @@ describe('POST /users/current/carts', () => {
.expect(404, { error: Error.ItemNotFound });
});

it('should fail as the user is not a player or a coach or a spectator', async () => {
const attendantUser = await createFakeUser({ type: UserType.attendant });

await request(app)
.post(`/users/current/carts`)
.set('Authorization', `Bearer ${token}`)
.send({
tickets: { userIds: [attendantUser.id] },
supplements: [],
})
.expect(403, { error: Error.NotPlayerOrCoachOrSpectator });
});

it('should fail as the user is already paid', async () => {
const paidUser = await createFakeUser({ paid: true, type: UserType.player });

Expand All @@ -327,6 +340,20 @@ describe('POST /users/current/carts', () => {
await database.user.delete({ where: { id: paidUser.id } });
});

it('should fail as the user is not in the same team', async () => {
const userInOtherTeam = await createFakeUser({ type: UserType.player });
const tokenInOtherTeam = generateToken(userInOtherTeam);

await request(app)
.post(`/users/current/carts`)
.set('Authorization', `Bearer ${tokenInOtherTeam}`)
.send({
tickets: { userIds: [] },
supplements: [],
})
.expect(403, { error: Error.NotInSameTeam });
});

it('should fail with an internal server error (inner try/catch)', () => {
sandbox.stub(cartOperations, 'createCart').throws('Unexpected error');

Expand Down

0 comments on commit 96c4b12

Please sign in to comment.