Skip to content

Commit

Permalink
Update createCart.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
Suboyyy authored Oct 6, 2024
1 parent 96c4b12 commit c51188b
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions tests/users/createCart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,11 @@ describe('POST /users/current/carts', () => {
supplements: [],
})
.expect(403, { error: Error.NotPlayerOrCoachOrSpectator });

// Delete the user to not make the results wrong for the success test
await database.cartItem.deleteMany({ where: { forUserId: attendantUser.id } });
await database.cart.deleteMany({ where: { userId: attendantUser.id } });
await database.user.delete({ where: { id: attendantUser.id } });
});

it('should fail as the user is already paid', async () => {
Expand All @@ -341,17 +346,23 @@ describe('POST /users/current/carts', () => {
});

it('should fail as the user is not in the same team', async () => {
const userInOtherTeam = await createFakeUser({ type: UserType.player });
const tokenInOtherTeam = generateToken(userInOtherTeam);
const otherTeam = await createFakeTeam({ members: 1, tournament: tournament.id, name: 'reallydontcare' });
const userInOtherTeam = getCaptain(otherTeam);

Check warning on line 351 in tests/users/createCart.test.ts

View workflow job for this annotation

GitHub Actions / lint (18)

Delete `····⏎`

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

// Delete the user to not make the results wrong for the success test
await database.cartItem.deleteMany({ where: { forUserId: userInOtherTeam.id } });
await database.cart.deleteMany({ where: { userId: userInOtherTeam.id } });
await database.user.delete({ where: { id: userInOtherTeam.id } });
});

it('should fail with an internal server error (inner try/catch)', () => {
Expand Down

0 comments on commit c51188b

Please sign in to comment.