API: adres strukturalny w endpoints /gyms (REAL wymaga ulicy/kodu/miasta, location derivowane, merge przy PATCH)
This commit is contained in:
@@ -209,7 +209,13 @@ describe('gyms — selection and management', () => {
|
||||
const created = await app
|
||||
.post('/api/v1/gyms')
|
||||
.set('Authorization', `Bearer ${token}`)
|
||||
.send({ name: `Remove Gym ${rand()}`, location: 'Warsaw', kind: 'REAL' });
|
||||
.send({
|
||||
name: `Remove Gym ${rand()}`,
|
||||
kind: 'REAL',
|
||||
addressLine1: 'Złota 5',
|
||||
postalCode: '00-100',
|
||||
city: 'Warszawa',
|
||||
});
|
||||
const gymId = created.body.gym.id as string;
|
||||
const kettlebell = await createEquipment('Kettlebell');
|
||||
await app
|
||||
|
||||
@@ -51,9 +51,49 @@ describe('virtual gyms — creation, listing and ratings', () => {
|
||||
const res = await app
|
||||
.post('/api/v1/gyms')
|
||||
.set('Authorization', `Bearer ${adminToken}`)
|
||||
.send({ name: `Admin Real ${rand()}`, location: 'Wrocław', kind: 'REAL' });
|
||||
.send({
|
||||
name: `Admin Real ${rand()}`,
|
||||
kind: 'REAL',
|
||||
addressLine1: 'Kazimierza 8',
|
||||
postalCode: '50-001',
|
||||
city: 'Wrocław',
|
||||
});
|
||||
expect(res.status).toBe(201);
|
||||
expect(res.body.gym).toMatchObject({ kind: 'REAL', isPrivate: false });
|
||||
expect(res.body.gym).toMatchObject({
|
||||
kind: 'REAL',
|
||||
isPrivate: false,
|
||||
location: 'Kazimierza 8, 50-001 Wrocław',
|
||||
});
|
||||
});
|
||||
|
||||
it('rejects a REAL gym without a structured address with 400', async () => {
|
||||
const app = buildApp();
|
||||
const res = await app
|
||||
.post('/api/v1/gyms')
|
||||
.set('Authorization', `Bearer ${adminToken}`)
|
||||
.send({ name: `No Addr ${rand()}`, kind: 'REAL', location: 'Wrocław' });
|
||||
expect(res.status).toBe(400);
|
||||
});
|
||||
|
||||
it('recomputes location when the owner updates the address', async () => {
|
||||
const app = buildApp();
|
||||
const created = await app
|
||||
.post('/api/v1/gyms')
|
||||
.set('Authorization', `Bearer ${adminToken}`)
|
||||
.send({
|
||||
name: `Addr Edit ${rand()}`,
|
||||
kind: 'REAL',
|
||||
addressLine1: 'Krótka 1',
|
||||
postalCode: '00-001',
|
||||
city: 'Warszawa',
|
||||
});
|
||||
const gymId = created.body.gym.id as string;
|
||||
const res = await app
|
||||
.patch(`/api/v1/gyms/${gymId}`)
|
||||
.set('Authorization', `Bearer ${adminToken}`)
|
||||
.send({ postalCode: '02-500' });
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.body.gym).toMatchObject({ location: 'Krótka 1, 02-500 Warszawa' });
|
||||
});
|
||||
|
||||
it('lets an admin create a private VIRTUAL gym', async () => {
|
||||
@@ -110,7 +150,13 @@ describe('virtual gyms — creation, listing and ratings', () => {
|
||||
const created = await app
|
||||
.post('/api/v1/gyms')
|
||||
.set('Authorization', `Bearer ${adminToken}`)
|
||||
.send({ name: `Real Patch ${rand()}`, location: 'Wrocław', kind: 'REAL' });
|
||||
.send({
|
||||
name: `Real Patch ${rand()}`,
|
||||
kind: 'REAL',
|
||||
addressLine1: 'Swobodna 2',
|
||||
postalCode: '50-002',
|
||||
city: 'Wrocław',
|
||||
});
|
||||
const gymId = created.body.gym.id as string;
|
||||
const res = await app
|
||||
.patch(`/api/v1/gyms/${gymId}`)
|
||||
|
||||
Reference in New Issue
Block a user