From 29ae0de1ef411cc26af1111e0073e03c20be21ce Mon Sep 17 00:00:00 2001 From: Maurice Date: Mon, 30 Nov 2026 00:16:23 +0000 Subject: [PATCH] fix(places): the third CI run, no awaits in loops and an edit target that may be none The rating order test pages through its cursor with a recursion and checks the refused floors at once instead of awaiting in a loop, and the edit hook types its first editable copy as possibly none, which the strict check reads from a conditional rather than a narrowed assignment. --- .../components/Collections/usePlaceEdit.ts | 2 +- .../e2e/places-library-rating.e2e.test.ts | 20 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/client/src/components/Collections/usePlaceEdit.ts b/client/src/components/Collections/usePlaceEdit.ts index 6422a9947..4eef7ed57 100644 --- a/client/src/components/Collections/usePlaceEdit.ts +++ b/client/src/components/Collections/usePlaceEdit.ts @@ -100,7 +100,7 @@ export function usePlaceEdit({ const [draft, setDraft] = useState(null); const [saving, setSaving] = useState(false); - const target: EditTarget | null = targets[0] ?? null; + const target: EditTarget | null = targets.length > 0 ? targets[0] : null; const start = () => { if (!target) return; diff --git a/server/tests/e2e/places-library-rating.e2e.test.ts b/server/tests/e2e/places-library-rating.e2e.test.ts index 660cd7010..4de40fbb9 100644 --- a/server/tests/e2e/places-library-rating.e2e.test.ts +++ b/server/tests/e2e/places-library-rating.e2e.test.ts @@ -105,10 +105,10 @@ describe('the rating filter of All places', () => { it('narrows a kind as well, and refuses a floor outside 1 to 5', async () => { const s = await seed(); expect(names(await page(s.me.id, { min_rating: 2, kind: 'list' }))).toEqual(['Delta']); - for (const bad of ['0', '6', '4.5', 'x']) { - const res = await request(server).get(LIBRARY).query({ min_rating: bad }).set(as(s.me.id)); - expect(res.status).toBe(400); - } + const refused = await Promise.all( + ['0', '6', '4.5', 'x'].map((bad) => request(server).get(LIBRARY).query({ min_rating: bad }).set(as(s.me.id))), + ); + expect(refused.map((res) => res.status)).toEqual([400, 400, 400, 400]); }); it('averages over the votes the reader can see: the friend reaches the trip only', async () => { @@ -127,16 +127,14 @@ describe('the rating order of All places', () => { it('pages through its cursor without a gap or a double', async () => { const s = await seed(); - const seen: string[] = []; - let cursor: string | null = null; - for (let i = 0; i < 5; i++) { + /** The pages from `cursor` on, one entry each, until the order ends. */ + const rest = async (cursor: string | null, depth: number): Promise => { const query: Record = { sort: 'rating', limit: 1 }; if (cursor) query.cursor = cursor; const p = await page(s.me.id, query); - seen.push(...names(p)); - cursor = p.next_cursor; - if (!cursor) break; - } + return p.next_cursor && depth < 5 ? [...names(p), ...(await rest(p.next_cursor, depth + 1))] : names(p); + }; + const seen = await rest(null, 0); expect(seen).toEqual(['Beta', 'Alpha', 'Delta', 'Gamma']); // A cursor of the name order is no cursor of the rating order. const byName = await page(s.me.id, { limit: 1 });