Skip to content

Commit c51188b

Browse files
authored
Update createCart.test.ts
1 parent 96c4b12 commit c51188b

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

tests/users/createCart.test.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@ describe('POST /users/current/carts', () => {
320320
supplements: [],
321321
})
322322
.expect(403, { error: Error.NotPlayerOrCoachOrSpectator });
323+
324+
// Delete the user to not make the results wrong for the success test
325+
await database.cartItem.deleteMany({ where: { forUserId: attendantUser.id } });
326+
await database.cart.deleteMany({ where: { userId: attendantUser.id } });
327+
await database.user.delete({ where: { id: attendantUser.id } });
323328
});
324329

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

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

347353
await request(app)
348354
.post(`/users/current/carts`)
349-
.set('Authorization', `Bearer ${tokenInOtherTeam}`)
355+
.set('Authorization', `Bearer ${token}`)
350356
.send({
351-
tickets: { userIds: [] },
357+
tickets: { userIds: [userInOtherTeam.id] },
352358
supplements: [],
353359
})
354360
.expect(403, { error: Error.NotInSameTeam });
361+
362+
// Delete the user to not make the results wrong for the success test
363+
await database.cartItem.deleteMany({ where: { forUserId: userInOtherTeam.id } });
364+
await database.cart.deleteMany({ where: { userId: userInOtherTeam.id } });
365+
await database.user.delete({ where: { id: userInOtherTeam.id } });
355366
});
356367

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

0 commit comments

Comments
 (0)