mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 03:50:30 +00:00
feat(collections): edit a saved place's provider ids, website, phone and price (#2646)
The update contract takes google_place_id, google_ftid, osm_id, website, phone, price and currency like saving does, website with the same normalisation and refusal. REST and update_collection_place share it, so an agent can correct a place instead of re-saving it and losing its labels, ratings, position and id. The assistant's change card names the new fields.
This commit is contained in:
@@ -208,6 +208,66 @@ describe('Collections e2e (real auth guard + real service + temp SQLite)', () =>
|
||||
expect(await countRows(orm, CollectionPlaces, { collection: col.id })).toBe(0);
|
||||
});
|
||||
|
||||
// #2646: saving took the provider ids, website, phone and price while editing
|
||||
// did not, so fixing one meant deleting and re-saving the place, which lost its
|
||||
// labels, ratings, position and id.
|
||||
it('COLLECTIONS-E2E-091: PATCH sets and clears the provider ids, website, phone and price', async () => {
|
||||
const col = (
|
||||
await request(server)
|
||||
.post('/api/addons/collections')
|
||||
.set('Cookie', sessionCookie(ownerId))
|
||||
.send({ name: 'Listings' })
|
||||
).body;
|
||||
const saved = await request(server)
|
||||
.post('/api/addons/collections/places')
|
||||
.set('Cookie', sessionCookie(ownerId))
|
||||
.send({ collection_id: col.id, name: 'Septime', phone: '+33 1 43 67 38 29', price: 40, currency: 'EUR' });
|
||||
expect(saved.status).toBe(200);
|
||||
const placeId = saved.body.place.id;
|
||||
const patch = (body: Record<string, unknown>) =>
|
||||
request(server)
|
||||
.patch(`/api/addons/collections/places/${placeId}`)
|
||||
.set('Cookie', sessionCookie(ownerId))
|
||||
.send(body);
|
||||
|
||||
const patched = await patch({
|
||||
google_place_id: 'ChIJseptime',
|
||||
google_ftid: '0x47e6:0x1b2',
|
||||
osm_id: 'node/42',
|
||||
website: 'septime-charonne.fr',
|
||||
price: 55,
|
||||
});
|
||||
expect(patched.status).toBe(200);
|
||||
// A bare domain gets https:// as on save; what the update leaves out stays.
|
||||
expect(patched.body).toMatchObject({
|
||||
id: placeId,
|
||||
google_place_id: 'ChIJseptime',
|
||||
google_ftid: '0x47e6:0x1b2',
|
||||
osm_id: 'node/42',
|
||||
website: 'https://septime-charonne.fr',
|
||||
phone: '+33 1 43 67 38 29',
|
||||
price: 55,
|
||||
currency: 'EUR',
|
||||
});
|
||||
|
||||
const refused = await patch({ website: 'javascript:alert(1)' });
|
||||
expect(refused.status).toBe(400);
|
||||
expect(refused.body.error).toMatch(/^website: /);
|
||||
expect((await findRow(orm, CollectionPlaces, { id: placeId }))?.website).toBe('https://septime-charonne.fr');
|
||||
|
||||
const cleared = await patch({ website: null, phone: null, price: null, currency: null, google_place_id: null });
|
||||
expect(cleared.status).toBe(200);
|
||||
expect(await findRow(orm, CollectionPlaces, { id: placeId })).toMatchObject({
|
||||
website: null,
|
||||
phone: null,
|
||||
price: null,
|
||||
currency: null,
|
||||
google_place_id: null,
|
||||
google_ftid: '0x47e6:0x1b2',
|
||||
osm_id: 'node/42',
|
||||
});
|
||||
});
|
||||
|
||||
// Regression for #1437: editing a place (PATCH without a status field) must NOT
|
||||
// reset a 'want'/'visited' place back to 'idea'.
|
||||
it('COLLECTIONS-E2E-012: PATCH without status leaves the saved status unchanged', async () => {
|
||||
|
||||
Reference in New Issue
Block a user