mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-23 21:33:19 +00:00
chore(lint): keep the fixes within the lint ratchets
No promise in a condition, sequential awaits through a reduce instead of a loop, no non-null assertions or any in the new tests, an awaited act, one options object for a stop edit and a handled rejection for the offline copy.
This commit is contained in:
@@ -29,10 +29,15 @@ describe('HelpGuideView: links', () => {
|
||||
})
|
||||
|
||||
it('takes an admin guide to the tab its settings sit under', () => {
|
||||
const { unmount } = render(<HelpGuideView guide={getHelpGuide('instance-keys')!} />)
|
||||
const guideOf = (id: string) => {
|
||||
const guide = getHelpGuide(id)
|
||||
if (!guide) throw new Error(`no guide ${id}`)
|
||||
return guide
|
||||
}
|
||||
const { unmount } = render(<HelpGuideView guide={guideOf('instance-keys')} />)
|
||||
expect(screen.getByRole('link', { name: /^Go to/ })).toHaveAttribute('href', '/admin?tab=services')
|
||||
unmount()
|
||||
render(<HelpGuideView guide={getHelpGuide('auth-methods')!} />)
|
||||
render(<HelpGuideView guide={guideOf('auth-methods')} />)
|
||||
expect(screen.getByRole('link', { name: /^Go to/ })).toHaveAttribute('href', '/admin?tab=settings')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -18,6 +18,11 @@ const prefersReducedMotion = (): boolean =>
|
||||
const stepMedia = (guide: HelpGuide, n: number): string =>
|
||||
guide.media.clips?.includes(n) && !prefersReducedMotion() ? helpMedia.clip(guide.id, n) : helpMedia.step(guide.id, n)
|
||||
|
||||
/** Where a guide's "go to" link leads: its own route, else its screen's. */
|
||||
function routeOf(guide: HelpGuide, screen: ReturnType<typeof getHelpContext>): string | undefined {
|
||||
return guide.route ?? screen?.route
|
||||
}
|
||||
|
||||
/**
|
||||
* One guide, top to bottom: a header card that says where you are and how big
|
||||
* the task is, the steps as a numbered rail with a picture each, what the
|
||||
@@ -38,7 +43,7 @@ export default function HelpGuideView({ guide }: { guide: HelpGuide }): React.Re
|
||||
const related = (guide.related ?? []).map(getHelpGuide).filter((g): g is HelpGuide => g !== null)
|
||||
const Icon = helpIcon(guide.icon)
|
||||
const ScreenIcon = screen ? helpIcon(screen.icon) : Icon
|
||||
const screenRoute = useScreenRoute(guide.route ?? screen?.route)
|
||||
const screenRoute = useScreenRoute(routeOf(guide, screen))
|
||||
|
||||
return (
|
||||
<div className="trek-help-view flex flex-col gap-6">
|
||||
|
||||
@@ -208,7 +208,9 @@ describe('NativeImportSheet', () => {
|
||||
answer = () => resolve([]);
|
||||
})
|
||||
);
|
||||
act(() => void useTripAddonsStore.getState().load(1));
|
||||
await act(async () => {
|
||||
void useTripAddonsStore.getState().load(1);
|
||||
});
|
||||
expect(screen.getByRole('button', { name: /Japan/ })).toBeInTheDocument();
|
||||
await act(async () => answer());
|
||||
expect(screen.getByRole('button', { name: /Japan/ })).toBeInTheDocument();
|
||||
|
||||
@@ -1031,9 +1031,13 @@ describe('useAdmin', () => {
|
||||
await waitFor(() => expect(result.current.admin.isLoading).toBe(false));
|
||||
expect(result.current.admin.activeTab).toBe('security');
|
||||
|
||||
act(() => void result.current.navigate('/admin?tab=services'));
|
||||
await act(async () => {
|
||||
await result.current.navigate('/admin?tab=services');
|
||||
});
|
||||
expect(result.current.admin.activeTab).toBe('services');
|
||||
act(() => void result.current.navigate('/admin?tab=settings'));
|
||||
await act(async () => {
|
||||
await result.current.navigate('/admin?tab=settings');
|
||||
});
|
||||
expect(result.current.admin.activeTab).toBe('security');
|
||||
act(() => result.current.admin.setActiveTab('audit'));
|
||||
expect(result.current.admin.activeTab).toBe('audit');
|
||||
|
||||
@@ -49,8 +49,12 @@ async function writeEditedStop(
|
||||
tripId: PlannerBase['tripId'],
|
||||
assignments: TripStoreState['assignments'],
|
||||
{ placeId, assignmentId, dwellMinutes: before }: { placeId: number; assignmentId?: number; dwellMinutes?: number },
|
||||
{ stopType, dwellMinutes }: { stopType: RoadtripStopType | null; dwellMinutes: number },
|
||||
{ mayEditVisit, refused }: { mayEditVisit: boolean; refused: string },
|
||||
{
|
||||
stopType,
|
||||
dwellMinutes,
|
||||
mayEditVisit,
|
||||
refused,
|
||||
}: { stopType: RoadtripStopType | null; dwellMinutes: number; mayEditVisit: boolean; refused: string },
|
||||
): Promise<void> {
|
||||
const visitDayId = savedVisitDayOf(assignments, assignmentId)
|
||||
if (assignmentId == null || visitDayId === null) {
|
||||
@@ -101,7 +105,9 @@ export function useRoadtripStopEdits(options: RoadtripStopEditsOptions) {
|
||||
}
|
||||
try {
|
||||
if (stopDraft.editing) {
|
||||
await writeEditedStop(tripActions, tripId, assignments, stopDraft.editing, { stopType, dwellMinutes }, {
|
||||
await writeEditedStop(tripActions, tripId, assignments, stopDraft.editing, {
|
||||
stopType,
|
||||
dwellMinutes,
|
||||
mayEditVisit: can('day_edit', trip),
|
||||
refused: t('trip.journal.errorForbidden'),
|
||||
})
|
||||
|
||||
@@ -70,7 +70,11 @@ export const useTripAddonsStore = create<TripAddonsState>((set, get) => ({
|
||||
// A push that landed meanwhile is newer than this answer and stays, in the
|
||||
// store and in the device's copy the answer was written over.
|
||||
if (current && current.rev !== rev) {
|
||||
if (addons && current.addons) void tripAddonsRepo.remember(tripId, current.addons).catch(() => {});
|
||||
if (addons && current.addons)
|
||||
void tripAddonsRepo.remember(tripId, current.addons).catch(() => {
|
||||
// The device copy stays one answer behind until the next read of this trip writes it.
|
||||
return undefined;
|
||||
});
|
||||
return current.addons;
|
||||
}
|
||||
const entry: TripAddonsEntry = addons
|
||||
|
||||
@@ -362,11 +362,14 @@ export class DawarichSyncService {
|
||||
* @txIndependent one stay at a time after its network read.
|
||||
*/
|
||||
private async rereadUnnamed(nameStay: StayNamer): Promise<void> {
|
||||
for (const stay of nameStay.unnamed.slice(0, MAX_UNNAMED_STAY_REREADS)) {
|
||||
// One after another: a read that finds the budget spent stops the rest.
|
||||
await nameStay.unnamed.slice(0, MAX_UNNAMED_STAY_REREADS).reduce<Promise<boolean>>(async (going, stay) => {
|
||||
if (!(await going)) return false;
|
||||
const found = await nameStay.read(stay.startedAt, stay.endedAt);
|
||||
if (found === undefined) return;
|
||||
if (found === undefined) return false;
|
||||
if (found !== null) await this.suggestions.renameNewVisit(stay.id, found);
|
||||
}
|
||||
return true;
|
||||
}, Promise.resolve(true));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -47,7 +47,7 @@ export function tripEventSink(addons: AddonsService, orm: MikroORM | undefined,
|
||||
return (tripId, event, meta) => {
|
||||
const addonId = tripAddonOfEvent(event);
|
||||
const before = queues.get(tripId);
|
||||
if (!addonId && !before) return deliver(tripId, event, meta);
|
||||
if (!addonId && before === undefined) return deliver(tripId, event, meta);
|
||||
const ask = () => (addonId ? addons.isEnabledForTrip(tripId, addonId) : Promise.resolve(true));
|
||||
const on = (orm && addonId ? withRequestContext(orm, ask) : ask()).catch(() => false);
|
||||
const queued = (before ?? Promise.resolve())
|
||||
|
||||
@@ -82,10 +82,7 @@ afterAll(async () => {
|
||||
|
||||
describe('Postgres backup round trip', () => {
|
||||
it('PGRT-001: a dump restores over a changed schema, dropping what came later, views and functions included', async (ctx) => {
|
||||
if (unfit) {
|
||||
console.log(`PGRT-001 skipped: ${unfit}`);
|
||||
ctx.skip();
|
||||
}
|
||||
if (unfit) ctx.skip(`PGRT-001 skipped: ${unfit}`);
|
||||
await asOwner((run) =>
|
||||
oneByOne(
|
||||
[
|
||||
|
||||
@@ -54,9 +54,9 @@ describe('script-settings', () => {
|
||||
'SCRIPTSET-001: a PostgreSQL %i server gets the script without SET transaction_timeout, and nothing else changes',
|
||||
async (major) => {
|
||||
const expected = SCRIPT.replace('SET transaction_timeout = 0;\n', '');
|
||||
for (const size of [1, 3, 7, 64, 1 << 20]) {
|
||||
expect(await filtered(SCRIPT, major, size), `chunks of ${size}`).toBe(expected);
|
||||
}
|
||||
const sizes = [1, 3, 7, 64, 1 << 20];
|
||||
const results = await Promise.all(sizes.map((size) => filtered(SCRIPT, major, size)));
|
||||
results.forEach((result, i) => expect(result, `chunks of ${sizes[i]}`).toBe(expected));
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
@@ -459,7 +459,7 @@ describe('migrate-encryption.ts rotates the stores the app writes', () => {
|
||||
token: string | null;
|
||||
}>;
|
||||
after.close();
|
||||
expect(decryptWith('new-key', rows[0].token!)).toBe('wanderer-token');
|
||||
expect(decryptWith('new-key', String(rows[0].token))).toBe('wanderer-token');
|
||||
expect(rows[1].token).toBeNull();
|
||||
}, 30000);
|
||||
|
||||
|
||||
@@ -688,7 +688,7 @@ describe('Tool: upload_trip_file', () => {
|
||||
name: 'upload_trip_file',
|
||||
arguments: { tripId: trip.id, filename: 'receipt.pdf', content: pdf, budget_item_id: expense.id },
|
||||
}),
|
||||
) as any;
|
||||
) as { file: { id: number } };
|
||||
expect((await linkRows(data.file.id)).map((l) => l.budget_item_id)).toEqual([expense.id]);
|
||||
const foreign = await h.client.callTool({
|
||||
name: 'upload_trip_file',
|
||||
@@ -713,8 +713,8 @@ describe('Tool: upload_trip_file', () => {
|
||||
name: 'upload_trip_file',
|
||||
arguments: { tripId: trip.id, filename: 'ticket.pdf', content: pdf },
|
||||
}),
|
||||
) as any
|
||||
).file.id as number;
|
||||
) as { file: { id: number } }
|
||||
).file.id;
|
||||
const receipt = await upload();
|
||||
const refused = await h.client.callTool({
|
||||
name: 'update_trip_file',
|
||||
|
||||
@@ -386,8 +386,12 @@ describe('listFiles', () => {
|
||||
|
||||
const files = (await svc.listFiles(trip.id, false, true)) as Record<string, unknown>[];
|
||||
expect(files.map((f) => f.id).sort()).toEqual([onBooking.id, onPlace.id, receipt.id].sort());
|
||||
expect(await svc.isAttached((await svc.getFileById(receipt.id, trip.id))!)).toBe(true);
|
||||
expect(await svc.isAttached((await svc.getFileById(loose.id, trip.id))!)).toBe(false);
|
||||
const [receiptRow, looseRow] = await Promise.all([
|
||||
svc.getFileById(receipt.id, trip.id),
|
||||
svc.getFileById(loose.id, trip.id),
|
||||
]);
|
||||
expect(receiptRow && (await svc.isAttached(receiptRow))).toBe(true);
|
||||
expect(looseRow && (await svc.isAttached(looseRow))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -129,14 +129,16 @@ describe('the mail tools', () => {
|
||||
|
||||
it('are listed only while the import is on, since every call needs it', async () => {
|
||||
expect(tools).toHaveLength(7);
|
||||
for (const name of tools) {
|
||||
// One tool after another: each takes the next answer of the settings stub.
|
||||
await tools.reduce(async (previous, name) => {
|
||||
await previous;
|
||||
const entry = getEntry(MailIngestMcp as unknown as ClassRef, name);
|
||||
const when = entry?.kind === 'tool' ? entry.options.when : undefined;
|
||||
expect(when, name).toBeTypeOf('function');
|
||||
settings.isAvailable.mockResolvedValueOnce(false);
|
||||
expect(await when?.(ctx, mcp()), name).toBe(false);
|
||||
expect(await when?.(ctx, mcp()), name).toBe(true);
|
||||
}
|
||||
}, Promise.resolve());
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1548,10 +1548,12 @@ describe('ReservationsService — referenced ids stay inside the trip', () => {
|
||||
const foreignDay = await findRow(orm, Days, { trip: theirs.id }) as { id: number };
|
||||
const foreignAcc = createDayAccommodation(testDb, theirs.id, foreignPlace.id, foreignDay.id, foreignDay.id);
|
||||
|
||||
for (const accommodation_id of [3000000000, foreignAcc.id]) {
|
||||
const dropped = async (accommodation_id: number) => {
|
||||
const { reservation } = await svc.create(String(mine.id), { title: 'Hotel', type: 'hotel', accommodation_id });
|
||||
expect(await findRow(orm, Reservations, { id: reservation.id })).toMatchObject({ accommodation_id: null });
|
||||
}
|
||||
};
|
||||
await dropped(3000000000);
|
||||
await dropped(foreignAcc.id);
|
||||
});
|
||||
|
||||
it('RESV-SCOPE-011: a stay whose refs resolve to nothing is refused, never written and never dropped in silence', async () => {
|
||||
|
||||
Reference in New Issue
Block a user