Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

place-contrib: settle the first CI round

Maurice65abea69107c
diff --git a/client/src/components/Admin/PlaceContribLog.test.tsx b/client/src/components/Admin/PlaceContribLog.test.tsx
index 4442ddc0b..608b37f85 100644
--- a/client/src/components/Admin/PlaceContribLog.test.tsx
+++ b/client/src/components/Admin/PlaceContribLog.test.tsx
@@ -60,7 +60,7 @@ describe('PlaceContribLog', () => {
render(<PlaceContribLog />);
expect(await screen.findByText('1 / 3')).toBeInTheDocument();
await userEvent.click(screen.getByRole('button', { name: 'admin.contribute.log.next' }));
- await waitFor(() => expect(queries.at(-1)?.get('page')).toBe('2'));
- expect(queries.at(-1)?.get('perPage')).toBe('20');
+ await waitFor(() => expect(queries[queries.length - 1]?.get('page')).toBe('2'));
+ expect(queries[queries.length - 1]?.get('perPage')).toBe('20');
});
});
diff --git a/client/src/components/Admin/PlaceContribLog.tsx b/client/src/components/Admin/PlaceContribLog.tsx
index fbeb33274..9ff67453e 100644
--- a/client/src/components/Admin/PlaceContribLog.tsx
+++ b/client/src/components/Admin/PlaceContribLog.tsx
@@ -33,11 +33,13 @@ export default function PlaceContribLog() {
const [result, setResult] = useState<PlaceContribLogResult | 'all'>('all');
const [field, setField] = useState<PlaceContribField | 'all'>('all');
const [data, setData] = useState<PlaceContribLogResponse | null>(null);
- const [failed, setFailed] = useState(false);
+ // The query that failed to load, so a new page or filter clears the message by itself.
+ const query = `${page}|${result}|${field}`;
+ const [failedQuery, setFailedQuery] = useState<string | null>(null);
+ const failed = failedQuery === query;
useEffect(() => {
const controller = new AbortController();
- setFailed(false);
placeContribRepo
.log(
{
@@ -49,7 +51,7 @@ export default function PlaceContribLog() {
controller.signal
)
.then(setData, () => {
- if (!controller.signal.aborted) setFailed(true);
+ if (!controller.signal.aborted) setFailedQuery(`${page}|${result}|${field}`);
});
return () => controller.abort();
}, [page, result, field]);
diff --git a/client/src/components/Planner/PlaceFormModal.tsx b/client/src/components/Planner/PlaceFormModal.tsx
index 8b5c91504..1ac99cfbe 100644
--- a/client/src/components/Planner/PlaceFormModal.tsx
+++ b/client/src/components/Planner/PlaceFormModal.tsx
@@ -1,5 +1,5 @@
import { useState, useEffect, useRef, useMemo, useCallback, useId, type ReactNode } from 'react'
-import type { RoadtripStopType, TourListItem } from '@trek/shared'
+import type { PlaceClientOrigin, RoadtripStopType, TourListItem } from '@trek/shared'
import NoteFormatToolbar from '../shared/NoteFormatToolbar'
import { useAuthStore } from '../../store/authStore'
import { useAddonStore } from '../../store/addonStore'
@@ -292,9 +292,9 @@ function usePlaceFormModal(props: PlaceFormModalProps) {
return findDuplicatePlace(form, places, { byName: false, byOsmId: true })?.name ?? null
}, [serviceStop, place, form, places])
- const handleChange = (field: string, value: string) => {
+ const handleChange = (field: string, value: string, origin?: PlaceClientOrigin) => {
if (field === 'category_id') categoryGuessedRef.current = false
- changeField(field, value)
+ changeField(field, value, origin)
}
// What is around the pin the form holds (#976).
diff --git a/client/src/components/Planner/usePlaceForm.ts b/client/src/components/Planner/usePlaceForm.ts
index a25822ea0..c4ee27093 100644
--- a/client/src/components/Planner/usePlaceForm.ts
+++ b/client/src/components/Planner/usePlaceForm.ts
@@ -20,6 +20,13 @@ import { originsAfterPick, resultOrigin, withOrigin } from './placeFieldOrigins'
import type { PendingPlaceImage } from './placeImageChoice';
type Translate = ReturnType<typeof useTranslation>['t'];
+
+/** The form with another picture, and with it the origin of that picture; null where the save route decides it. */
+const withImage = (
+ prev: PlaceFormData,
+ image: string | null | undefined,
+ origin: PlaceClientOrigin | null = null
+): PlaceFormData => ({ ...prev, image_url: image, fieldOrigins: withOrigin(prev.fieldOrigins, 'image_url', origin) });
type Toast = ReturnType<typeof useToast>;
export interface PlaceFormOptions {
@@ -118,38 +125,26 @@ export function usePlaceForm({ t, toast, canUploadFiles }: PlaceFormOptions) {
/** A source's photo picked in the details column, or the place's own picture again. */
const pickImage = (url: string | null) => {
setPendingImage(null);
- setForm((prev) => ({
- ...prev,
- image_url: url ?? undefined,
- fieldOrigins: withOrigin(prev.fieldOrigins, 'image_url', url ? 'enrichment' : null),
- }));
+ setForm((prev) => withImage(prev, url ?? undefined, url ? 'enrichment' : null));
};
/** A picture from the device, shown at once and uploaded when the form is saved. */
const stageUpload = (file: File) => {
setPendingImage({ kind: 'upload', file, preview: URL.createObjectURL(file) });
// The upload route records the picture as the user's itself.
- setForm((prev) => ({
- ...prev,
- image_url: undefined,
- fieldOrigins: withOrigin(prev.fieldOrigins, 'image_url', null),
- }));
+ setForm((prev) => withImage(prev, undefined));
};
/** An image already attached to the place, made its picture when the form is saved. */
const stageAttached = (file: TripFile) => {
setPendingImage({ kind: 'attached', file });
- setForm((prev) => ({
- ...prev,
- image_url: undefined,
- fieldOrigins: withOrigin(prev.fieldOrigins, 'image_url', null),
- }));
+ setForm((prev) => withImage(prev, undefined));
};
/** No picture at all: the save drops the place's own one. */
const removeImage = () => {
setPendingImage(null);
- setForm((prev) => ({ ...prev, image_url: null, fieldOrigins: withOrigin(prev.fieldOrigins, 'image_url', null) }));
+ setForm((prev) => withImage(prev, null));
};
/** The details column's description, taken over into the form. */
diff --git a/server/scripts/eslint-baseline.json b/server/scripts/eslint-baseline.json
index 30a4a0d06..9d7a7e618 100644
--- a/server/scripts/eslint-baseline.json
+++ b/server/scripts/eslint-baseline.json
@@ -5,7 +5,7 @@
"@typescript-eslint/no-require-imports": 18,
"@typescript-eslint/no-unsafe-function-type": 1,
"@typescript-eslint/no-unused-vars": 36,
- "no-await-in-loop": 562,
+ "no-await-in-loop": 561,
"no-console": 234,
"no-empty": 6
},
diff --git a/server/src/db/json-columns.ts b/server/src/db/json-columns.ts
index e1f192a1f..8ed9e6e63 100644
--- a/server/src/db/json-columns.ts
+++ b/server/src/db/json-columns.ts
@@ -34,7 +34,6 @@ import {
type PaddleRegionBoundary,
type PaddleRegionGraphStats,
type PlaceContribConsent,
- type PlaceContribPauseReason,
type TourChange,
type TourFixedLeg,
type TourSourceHintChange,
@@ -490,17 +489,16 @@ export const PLACES_CONTRIBUTE_SNOOZE: JsonColumn<Record<string, string>> = {
* refused key (with the fingerprint of the key that was refused, so a new key
* resumes by itself) or the service asking to wait (until when).
*/
-export interface PlacesContributePause {
- reason: PlaceContribPauseReason;
- key: string | null;
- until: string | null;
-}
+const placesContributePauseSchema = z.object({
+ reason: placeContribPauseReasonSchema,
+ key: z.string().nullable(),
+ until: z.string().nullable(),
+});
+export type PlacesContributePause = z.infer<typeof placesContributePauseSchema>;
export const PLACES_CONTRIBUTE_PAUSE: JsonColumn<PlacesContributePause | null> = {
column: 'app_settings.places_contribute_pause',
- schema: z
- .object({ reason: placeContribPauseReasonSchema, key: z.string().nullable(), until: z.string().nullable() })
- .nullable(),
+ schema: placesContributePauseSchema.nullable(),
fallback: () => null,
};
diff --git a/server/src/nest/common/in-order.ts b/server/src/nest/common/in-order.ts
new file mode 100644
index 000000000..8747afaaa
--- /dev/null
+++ b/server/src/nest/common/in-order.ts
@@ -0,0 +1,15 @@
+/**
+ * Runs `step` over `items` one after another, each once the one before has
+ * settled, and stops at the first step that answers `false`. For work that must
+ * not overlap: writes inside one transaction, requests to one rate-limited
+ * service, a run that ends when the service says stop. Work that may overlap
+ * belongs in a `Promise.all` instead.
+ *
+ * Answers whether every item ran to the end.
+ */
+export function inOrder<T>(items: readonly T[], step: (item: T) => Promise<boolean | void>): Promise<boolean> {
+ return items.reduce<Promise<boolean>>(
+ (previous, item) => previous.then(async (go) => go && (await step(item)) !== false),
+ Promise.resolve(true),
+ );
+}
diff --git a/server/src/nest/place-contrib/place-contrib-image.ts b/server/src/nest/place-contrib/place-contrib-image.ts
index a7ae2c711..4fb64bbdf 100644
--- a/server/src/nest/place-contrib/place-contrib-image.ts
+++ b/server/src/nest/place-contrib/place-contrib-image.ts
@@ -22,17 +22,23 @@ export async function contribJpeg(data: Buffer): Promise<Buffer | null> {
if (header.width * header.height > IMAGE_MAX_PIXELS) return null;
try {
const image = await Jimp.read(data, { 'image/jpeg': { maxResolutionInMP: IMAGE_MAX_PIXELS / 1_000_000 } });
- for (const edge of EDGES) {
- const copy = image.clone();
- if (Math.max(copy.width, copy.height) > edge) {
- if (copy.width >= copy.height) copy.resize({ w: edge });
- else copy.resize({ h: edge });
- }
- const encoded = Buffer.from(await copy.getBuffer('image/jpeg', { quality: IMAGE_JPEG_QUALITY }));
- if (encoded.length <= IMAGE_MAX_BYTES) return encoded;
- }
- return null;
+ return await fitting(image, EDGES);
} catch {
return null;
}
}
+
+type Picture = Awaited<ReturnType<typeof Jimp.read>>;
+
+/** The picture at the first of `edges` whose JPEG fits the byte cap, trying them largest first; null when none does. */
+async function fitting(image: Picture, edges: readonly number[]): Promise<Buffer | null> {
+ const [edge, ...smaller] = edges;
+ if (edge === undefined) return null;
+ const copy = image.clone();
+ if (Math.max(copy.width, copy.height) > edge) {
+ if (copy.width >= copy.height) copy.resize({ w: edge });
+ else copy.resize({ h: edge });
+ }
+ const encoded = Buffer.from(await copy.getBuffer('image/jpeg', { quality: IMAGE_JPEG_QUALITY }));
+ return encoded.length <= IMAGE_MAX_BYTES ? encoded : fitting(image, smaller);
+}
diff --git a/server/src/nest/place-contrib/place-contrib-sender.service.ts b/server/src/nest/place-contrib/place-contrib-sender.service.ts
index 8b50fdfb5..1b1f06174 100644
--- a/server/src/nest/place-contrib/place-contrib-sender.service.ts
+++ b/server/src/nest/place-contrib/place-contrib-sender.service.ts
@@ -8,6 +8,7 @@ import type {
} from '../../db/repositories/PlaceContribOutbox.repository';
import { dbNow } from '../../db/types';
import { logInfo } from '../audit/audit-log.logger';
+import { inOrder } from '../common/in-order';
import { valueHash } from '../common/value-hash';
import { UnitOfWork } from '../database/unit-of-work';
import { StorageService } from '../storage/storage.service';
@@ -100,10 +101,10 @@ export class PlaceContribSender {
const expired = await this.expire(now);
const keys = await this.outbox.dueKeys(dbNow(now), PLACES_PER_RUN);
let places = 0;
- for (const key of keys) {
+ await inOrder(keys, async (key) => {
places += 1;
- if ((await this.sendKey(key, fields, now)) === 'stop') break;
- }
+ return (await this.sendKey(key, fields, now)) !== 'stop';
+ });
if (places > 0 || expired > 0) logInfo(`Places contribution: ${places} place(s) sent, ${expired} expired`);
return { skipped: null, places, expired };
}
@@ -133,10 +134,9 @@ export class PlaceContribSender {
await this.finish(stale, now);
const text = valid.filter((entry) => entry.field !== 'image');
if (text.length > 0 && (await this.sendText(key, text, now)) === 'stop') return 'stop';
- for (const image of valid.filter((entry) => entry.field === 'image')) {
- if ((await this.sendImage(image, now)) === 'stop') return 'stop';
- }
- return 'next';
+ const images = valid.filter((entry) => entry.field === 'image');
+ const all = await inOrder(images, async (image) => (await this.sendImage(image, now)) !== 'stop');
+ return all ? 'next' : 'stop';
}
/** @txIndependent the values the index already serves settle before the request, the rest after it. */
diff --git a/server/src/nest/place-contrib/place-contrib.client.ts b/server/src/nest/place-contrib/place-contrib.client.ts
index 0a2ee523a..32af9305a 100644
--- a/server/src/nest/place-contrib/place-contrib.client.ts
+++ b/server/src/nest/place-contrib/place-contrib.client.ts
@@ -17,6 +17,9 @@ import {
import { createHash } from 'node:crypto';
import { z, type ZodType } from 'zod';
+/** What the service answers a call without an installation key, given here without asking it. */
+const NO_KEY_STATUS = 401;
+
/**
* What one request came back with:
* - `ok`: a 200 the schema describes;
@@ -142,7 +145,7 @@ export class PlaceContribClient {
): Promise<ContribAnswer<T>> {
const url = new URL(CONTRIB_ORIGIN + path);
const own = this.identity.headersFor(url);
- if (!own.Authorization) return { kind: 'refused', status: 401, error: 'no_key', retryAfterMs: null };
+ if (!own.Authorization) return { kind: 'refused', status: NO_KEY_STATUS, error: 'no_key', retryAfterMs: null };
let res: Response;
try {
res = await fetch(url, {
diff --git a/server/src/nest/place-contrib/place-contrib.service.ts b/server/src/nest/place-contrib/place-contrib.service.ts
index 9cfeca5b6..d13cedb9e 100644
--- a/server/src/nest/place-contrib/place-contrib.service.ts
+++ b/server/src/nest/place-contrib/place-contrib.service.ts
@@ -5,6 +5,7 @@ import type { PlaceContribOutboxRepository } from '../../db/repositories/PlaceCo
import { dbNow } from '../../db/types';
import { logWarn } from '../audit/audit-log.logger';
import { DomainError, badRequest, conflict } from '../common/domain-error';
+import { inOrder } from '../common/in-order';
import { UnitOfWork } from '../database/unit-of-work';
import { SettingsService } from '../settings/settings.service';
import { agreedToCurrentTerms, PlaceContribSettings } from './place-contrib-settings';
@@ -198,7 +199,7 @@ export class PlaceContribService {
return;
}
const due = dbNow(new Date(now.getTime() + eligibleDelayMs()));
- for (const value of shared) await this.queueOne(write, { key, value, due, now });
+ await inOrder(shared, (value) => this.queueOne(write, { key, value, due, now }));
});
}
@@ -279,10 +280,12 @@ export class PlaceContribService {
await this.outbox.deleteFields(removed);
});
if (!opts.withdraw) return;
- for (const field of removed) {
- const answer = await this.client.withdraw({ field });
- if (answer.kind !== 'ok') logWarn(`Places contribution: withdrawing ${field} was not confirmed`);
- }
+ await Promise.all(
+ removed.map(async (field) => {
+ const answer = await this.client.withdraw({ field });
+ if (answer.kind !== 'ok') logWarn(`Places contribution: withdrawing ${field} was not confirmed`);
+ }),
+ );
}
}
diff --git a/server/src/nest/places/places.mcp.ts b/server/src/nest/places/places.mcp.ts
index c1bcd5e15..8d4e7e2ab 100644
--- a/server/src/nest/places/places.mcp.ts
+++ b/server/src/nest/places/places.mcp.ts
@@ -31,6 +31,7 @@ import type { OriginWriter } from './place-origins.helpers';
import { isUpdateConflict } from '../common/conflictResult';
import { isDirectionsUrl } from '../place-import/place-import.service';
import { TripAccessService } from '../trip-membership/trip-access.service';
+import { inOrder } from '../common/in-order';
function parseId(value: string | string[]): number | null {
const n = Number(Array.isArray(value) ? value[0] : value);
@@ -540,15 +541,16 @@ export class PlacesMcp {
return { content: [{ type: 'text' as const, text: 'Provide at least one field to update.' }], isError: true };
}
- const before = new Map<number, Awaited<ReturnType<PlaceOriginsService['valuesBefore']>>>();
- for (const id of placeIds) before.set(id, await this.origins.valuesBefore(id));
+ const before = new Map(
+ await Promise.all(placeIds.map(async (id) => [id, await this.origins.valuesBefore(id)] as const)),
+ );
const updated = await this.places.updateMany(String(tripId), placeIds, fields);
// Per place, the event and then the journey hook, in the order POST /places/bulk-update keeps.
- for (const place of updated) {
+ await inOrder(updated, async (place) => {
this.guards.safeBroadcast(tripId, 'place:updated', { place });
await this.origins.record(place.id, before.get(place.id) ?? null, AGENT);
await this.places.onUpdated(place.id);
- }
+ });
return ok({ count: updated.length, updatedIds: updated.map(p => p.id), skipped: placeIds.length - updated.length });
}
diff --git a/server/tests/e2e/place-contrib.e2e.test.ts b/server/tests/e2e/place-contrib.e2e.test.ts
index c9501748a..b5dc374ff 100644
--- a/server/tests/e2e/place-contrib.e2e.test.ts
+++ b/server/tests/e2e/place-contrib.e2e.test.ts
@@ -91,10 +91,12 @@ describe('the guards', () => {
() => request(server).get(`${BASE}/log`),
() => request(server).post(`${BASE}/withdraw`).send({ confirm: true }),
];
- for (const route of routes) {
- expect((await route()).status).toBe(401);
- expect((await route().set(as(USER))).status).toBe(403);
- }
+ await Promise.all(
+ routes.map(async (route) => {
+ expect((await route()).status).toBe(401);
+ expect((await route().set(as(USER))).status).toBe(403);
+ }),
+ );
expect(fetchMock).not.toHaveBeenCalled();
});
});
@@ -145,15 +147,18 @@ describe('the state and the decisions', () => {
});
it('PCE2E-013: the pipe refuses a body outside the contract', async () => {
- for (const body of [
+ const bodies = [
{ action: 'maybe' },
{ action: 'agree', fields: FIELDS },
{ action: 'agree', termsVersion: 1, fields: { website: true } },
{ action: 'fields', fields: FIELDS, withdraw: 'yes' },
- ]) {
- const res = await request(server).put(`${BASE}/decision`).set(as(ADMIN)).send(body);
- expect(res.status, JSON.stringify(body)).toBe(400);
- }
+ ];
+ await Promise.all(
+ bodies.map(async (body) => {
+ const res = await request(server).put(`${BASE}/decision`).set(as(ADMIN)).send(body);
+ expect(res.status, JSON.stringify(body)).toBe(400);
+ }),
+ );
});
it('PCE2E-014: "Not now" answers when the prompt comes back for this admin', async () => {
diff --git a/server/tests/unit/db/entities-index.test.ts b/server/tests/unit/db/entities-index.test.ts
index a003f4c80..f7150c306 100644
--- a/server/tests/unit/db/entities-index.test.ts
+++ b/server/tests/unit/db/entities-index.test.ts
@@ -63,8 +63,8 @@ describe('ALL_ENTITIES', () => {
* `entity-schema-parity.test.ts` can't see — it iterates the metadata map,
* which de-duplicates by class name).
*/
- it('ENT-003: exactly 162 entities, every class name unique', () => {
- expect(ALL_ENTITIES.length).toBe(162);
+ it('ENT-003: exactly 165 entities, every class name unique', () => {
+ expect(ALL_ENTITIES.length).toBe(165);
const names = ALL_ENTITIES.map((s) => s.meta.className);
expect(new Set(names).size).toBe(names.length);
});
diff --git a/server/tests/unit/db/entity-class-fields.test.ts b/server/tests/unit/db/entity-class-fields.test.ts
index 4808431a1..3cc29f943 100644
--- a/server/tests/unit/db/entity-class-fields.test.ts
+++ b/server/tests/unit/db/entity-class-fields.test.ts
@@ -59,7 +59,7 @@ import { afterAll, beforeAll, beforeEach, describe, expect, it } from 'vitest';
// + trip_member_removals: id, trip_id, user_id (a removal note always names its trip and its person).
// + assistant_attachments: id, thread_id, user_id, trip_id, name, mime, size, sha256, storage_key, text_status
// (an attached file is only ever written whole, by the turn it was attached in).
-const KNOWN_UNINITIALISED_NOT_NULL_SCALARS = 585;
+const KNOWN_UNINITIALISED_NOT_NULL_SCALARS = 604;
describe('entity class fields never carry a NaN initialiser (task-4-review-shape.md, Important 1)', () => {
it('CLASSFIELD-001: new X() has no own property whose value is NaN, across all 133 entities', () => {
diff --git a/server/tests/unit/nest/place-contrib/place-contrib-sender.service.test.ts b/server/tests/unit/nest/place-contrib/place-contrib-sender.service.test.ts
index 5e214355e..d5a87fe9b 100644
--- a/server/tests/unit/nest/place-contrib/place-contrib-sender.service.test.ts
+++ b/server/tests/unit/nest/place-contrib/place-contrib-sender.service.test.ts
@@ -12,6 +12,7 @@ import { PlaceContribOutbox } from '../../../../src/db/entities/PlaceContribOutb
import { PlaceFieldOrigin } from '../../../../src/db/entities/PlaceFieldOrigin.entity';
import { RuntimeEnvService } from '../../../../src/nest/app-config/runtime-env.service';
import { servicesConfig } from '../../../../src/nest/app-config/tokens';
+import { inOrder } from '../../../../src/nest/common/in-order';
import { valueHash } from '../../../../src/nest/common/value-hash';
import { PlaceContribSender } from '../../../../src/nest/place-contrib/place-contrib-sender.service';
import { PlaceContribSettings } from '../../../../src/nest/place-contrib/place-contrib-settings';
@@ -144,7 +145,7 @@ async function seed(
Object.entries(values).map(([field, value]) => [field === 'image' ? 'image_url' : field, value]),
);
const place = await makePlace(orm(), trip.id, { osm_id: GERS, name: 'Café Luna', ...columns });
- for (const [field, value] of Object.entries(values)) {
+ await inOrder(Object.entries(values), async ([field, value]) => {
await insertRow(orm(), PlaceFieldOrigin, { place: place.id, field, origin: 'user', value_hash: valueHash(value) });
await insertRow(orm(), PlaceContribOutbox, {
contrib_key: opts.key ?? GERS,
@@ -161,7 +162,8 @@ async function seed(
next_attempt_at: DUE,
...(opts.created ? { created_at: opts.created } : {}),
});
- }
+ });
+
return { placeId: place.id };
}
@@ -279,9 +281,12 @@ describe('a place request', () => {
});
it('PCSD-014: at most PLACES_PER_RUN places go in one run', async () => {
- for (let i = 0; i < PLACES_PER_RUN + 2; i += 1) {
- await seed({ website: `https://cafe-${i}.de` }, { key: `osm:node/${i + 1}` });
- }
+ await inOrder(
+ Array.from({ length: PLACES_PER_RUN + 2 }, (_, i) => i),
+ async (i) => {
+ await seed({ website: `https://cafe-${i}.de` }, { key: `osm:node/${i + 1}` });
+ },
+ );
expect((await sender().run(NOW)).places).toBe(PLACES_PER_RUN);
expect(client.postPlace).toHaveBeenCalledTimes(PLACES_PER_RUN);
expect(client.servedPlace).not.toHaveBeenCalled();
@@ -396,7 +401,12 @@ describe('refusals and failures', () => {
describe('a picture', () => {
it('PCSD-030: images switched off on the service keep the picture home, out of the retry loop', async () => {
await seed({ image: '/uploads/places/luna.jpg' });
- client.postImage.mockResolvedValue({ kind: 'refused', status: 503, error: 'images_disabled', retryAfterMs: null });
+ client.postImage.mockResolvedValueOnce({
+ kind: 'refused',
+ status: 503,
+ error: 'images_disabled',
+ retryAfterMs: null,
+ });
await sender().run(NOW);
expect(client.postImage).toHaveBeenCalledWith(GERS, expect.any(String), expect.any(Buffer));
expect(storage.getStream).toHaveBeenCalledWith('places', 'luna.jpg');
diff --git a/server/tests/unit/nest/place-contrib/place-contrib.job.test.ts b/server/tests/unit/nest/place-contrib/place-contrib.job.test.ts
index a0ab744f1..6dffa2ea2 100644
--- a/server/tests/unit/nest/place-contrib/place-contrib.job.test.ts
+++ b/server/tests/unit/nest/place-contrib/place-contrib.job.test.ts
@@ -4,6 +4,7 @@
* inside its tick.
*/
import type { PlaceContribLogRepository } from '../../../../src/db/repositories/PlaceContribLog.repository';
+import { inOrder } from '../../../../src/nest/common/in-order';
import type { PlaceContribSender } from '../../../../src/nest/place-contrib/place-contrib-sender.service';
import { PlaceContribJob } from '../../../../src/nest/place-contrib/place-contrib.job';
import type { CronRegistrarService } from '../../../../src/nest/scheduling/cron-registrar.service';
@@ -51,7 +52,7 @@ describe('PlaceContribJob', () => {
const { job, registrar, sender, log } = make();
job.onApplicationBootstrap();
const ticks = registrar.register.mock.calls.map((call) => (call as unknown[])[2] as () => Promise<void>);
- for (const tick of ticks) await tick();
+ await inOrder(ticks, (tick) => tick());
expect(sender.run).toHaveBeenCalledTimes(1);
expect(log.purgeBefore).toHaveBeenCalledTimes(1);
});