Silownie: dolaczenie do prywatnej silowni odrzucane (403) - tylko zaproszenia
This commit is contained in:
@@ -158,10 +158,11 @@ export async function rateGym(
|
||||
return { vote: existing?.vote === vote ? null : vote, up, down };
|
||||
}
|
||||
|
||||
/** Join an existing gym (creates a MEMBER membership). */
|
||||
/** Join an existing gym (creates a MEMBER membership). Private gyms are invitation-only. */
|
||||
export async function joinGym(prisma: PrismaClient, userId: string, gymId: string) {
|
||||
const gym = await prisma.gym.findUnique({ where: { id: gymId } });
|
||||
if (!gym) throw notFound('Gym not found');
|
||||
if (gym.isPrivate) throw forbidden('Private gyms are invitation-only');
|
||||
const existing = await prisma.gymMembership.findUnique({
|
||||
where: { userId_gymId: { userId, gymId } },
|
||||
});
|
||||
|
||||
@@ -90,6 +90,21 @@ describe('virtual gyms — creation, listing and ratings', () => {
|
||||
expect(res.body.gym.isPrivate).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects joining a private virtual gym with 403 (invitation only)', async () => {
|
||||
const app = buildApp();
|
||||
const created = await app
|
||||
.post('/api/v1/gyms')
|
||||
.set('Authorization', `Bearer ${userToken}`)
|
||||
.send({ name: `Locked Gym ${rand()}`, location: 'Gdańsk', isPrivate: true });
|
||||
expect(created.status).toBe(201);
|
||||
const outsider = await createUser();
|
||||
const outsiderToken = (await loginViaApi(outsider.user.email, PASSWORD)).token;
|
||||
const res = await app
|
||||
.post(`/api/v1/gyms/${created.body.gym.id}/join`)
|
||||
.set('Authorization', `Bearer ${outsiderToken}`);
|
||||
expect(res.status).toBe(403);
|
||||
});
|
||||
|
||||
it('rejects isPrivate=true on a REAL gym via PATCH with 400', async () => {
|
||||
const app = buildApp();
|
||||
const created = await app
|
||||
|
||||
Reference in New Issue
Block a user