mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
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.
This commit is contained in:
@@ -100,7 +100,7 @@ export function usePlaceEdit({
|
||||
const [draft, setDraft] = useState<Draft | null>(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;
|
||||
|
||||
@@ -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<string[]> => {
|
||||
const query: Record<string, string | number> = { 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 });
|
||||
|
||||
Reference in New Issue
Block a user