Skip to content

Commit

Permalink
feat: adding test for createCart (user) (#250)
Browse files Browse the repository at this point in the history
* feat: adding test for createCart (user)

* Update createCart.test.ts

* fix: seems to be good

* fix: respo ssl not full access

* feat: vieux are invite

* fix: invite does not exist in this branche

---------

Co-authored-by: Antoine D <[email protected]>
  • Loading branch information
Suboyyy and Antoine D authored Oct 7, 2024
1 parent a9bc61c commit c59d028
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/controllers/admin/badges/generateBadges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@ const getCommisionPermission = (commissionRole: string, commissionId: string) =>
if (commissionRole === 'respo') return 'fullaccess';
}

case 'ssl': {
if (commissionRole === 'respo') return 'fullaccess';
}

default: {
return 'orgaprice';
}
Expand Down
38 changes: 38 additions & 0 deletions tests/users/createCart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,24 @@ 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 });

// 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 () => {
const paidUser = await createFakeUser({ paid: true, type: UserType.player });

Expand All @@ -327,6 +345,26 @@ 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 otherTeam = await createFakeTeam({ members: 1, tournament: 'ssbu', name: 'reallydontcare' });
const userInOtherTeam = getCaptain(otherTeam);

await request(app)
.post(`/users/current/carts`)
.set('Authorization', `Bearer ${token}`)
.send({
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.team.delete({ where: { captainId: userInOtherTeam.id } });
await database.user.delete({ where: { id: userInOtherTeam.id } });
});

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

Expand Down

0 comments on commit c59d028

Please sign in to comment.