From 69435d899b452ab57458a8f6dec2fdb4a895e4ea Mon Sep 17 00:00:00 2001 From: tisachi Date: Sun, 11 Oct 2026 16:17:29 +0200 Subject: [PATCH] Silownie: dolaczenie do prywatnej silowni odrzucane (403) - tylko zaproszenia --- api/src/services/gyms/core.ts | 3 ++- api/test/integration/virtual-gyms.test.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/api/src/services/gyms/core.ts b/api/src/services/gyms/core.ts index 6c53117..a13ed5f 100644 --- a/api/src/services/gyms/core.ts +++ b/api/src/services/gyms/core.ts @@ -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 } }, }); diff --git a/api/test/integration/virtual-gyms.test.ts b/api/test/integration/virtual-gyms.test.ts index 0d14cd9..36c89c5 100644 --- a/api/test/integration/virtual-gyms.test.ts +++ b/api/test/integration/virtual-gyms.test.ts @@ -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