mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 13:10:29 +00:00
724c88c201
A mechanical prettier --write over server/src, server/tests, server/scripts and shared/src with the workspaces' .prettierrc; nothing but layout and import order changes, and every file keeps the same set of imports. shared is formatted throughout and its format baseline is empty. The server baseline keeps the 35 files that Prettier would grow past their lint:size limit (they need a split first, which is not a formatting change), and the generated entity files stay as their generator writes them.
83 lines
3.7 KiB
TypeScript
83 lines
3.7 KiB
TypeScript
/**
|
|
* Atlas repositories — M3 branch ratchet (task-7-review.md). Plan 3f Task 1
|
|
* added empty-array short-circuits and not-found/no-op ternaries across
|
|
* these repositories with no test exercising the empty/no-op arm. One
|
|
* seeded world per repository (shared `testDb`, reset between tests).
|
|
*/
|
|
import {
|
|
createTestPlaceRegionsRepo,
|
|
createTestVisitedCountriesRepo,
|
|
createTestBucketListRepo,
|
|
} from '../../../helpers/atlas-repos';
|
|
import { createSnapshotTestDb } from '../../../helpers/db-mock';
|
|
import { createUser } from '../../../helpers/factories';
|
|
import { createTestSchoolHolidayCountriesRepo } from '../../../helpers/school-holidays-repos';
|
|
import { resetTestDb } from '../../../helpers/test-db';
|
|
import { createTestReservationEndpointsRepo } from '../../../helpers/test-uow';
|
|
|
|
import { afterAll, beforeEach, describe, expect, it } from 'vitest';
|
|
|
|
const testDb = createSnapshotTestDb();
|
|
beforeEach(() => resetTestDb(testDb));
|
|
afterAll(() => testDb.close());
|
|
|
|
describe('PlaceRegionsRepository — empty-array short-circuits (AT3/AT28/AT23)', () => {
|
|
it('listCountryCodesForPlaceIds/listForPlaceIds/listDistinctRegionCodesForCountryAndPlaces all return [] for an empty id list, without querying', async () => {
|
|
const repo = await createTestPlaceRegionsRepo(testDb);
|
|
expect(await repo.listCountryCodesForPlaceIds([])).toEqual([]);
|
|
expect(await repo.listForPlaceIds([])).toEqual([]);
|
|
expect(await repo.listDistinctRegionCodesForCountryAndPlaces('FR', [])).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('VisitedCountriesRepository.markVisited — the ON CONFLICT DO NOTHING return (AT12)', () => {
|
|
it('returns false on a repeat mark (no row actually inserted the second time), true on the first', async () => {
|
|
const repo = await createTestVisitedCountriesRepo(testDb);
|
|
const { user } = createUser(testDb);
|
|
expect(await repo.markVisited(user.id, 'FR', 'manual')).toBe(true);
|
|
expect(await repo.markVisited(user.id, 'FR', 'manual')).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('ReservationEndpointsRepository.listOwnedEndpointsForTrips — empty-array short-circuit (AT6)', () => {
|
|
it('returns [] for an empty tripIds list, without querying', async () => {
|
|
const repo = await createTestReservationEndpointsRepo(testDb);
|
|
const { user } = createUser(testDb);
|
|
expect(await repo.listOwnedEndpointsForTrips([], user.id)).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('BucketListRepository.update — the no-op empty-patch branch (AT35)', () => {
|
|
it('an empty write leaves the row untouched', async () => {
|
|
const repo = await createTestBucketListRepo(testDb);
|
|
const { user } = createUser(testDb);
|
|
const id = await repo.insertItem({
|
|
user_id: user.id,
|
|
name: 'Kyoto',
|
|
lat: null,
|
|
lng: null,
|
|
country_code: null,
|
|
notes: null,
|
|
target_date: null,
|
|
region_code: null,
|
|
});
|
|
|
|
await repo.update(id, user.id, {});
|
|
|
|
const row = await repo.findById(id);
|
|
expect(row?.name).toBe('Kyoto');
|
|
});
|
|
});
|
|
|
|
// Folded in for the aggregate `src/db/repositories/**` gate (task-7-review.md
|
|
// M3: "the 3e-carried lines belong to 3e's own ratchet but block CI all the
|
|
// same. Fold them in, or name the owner.") — the same ON CONFLICT DO NOTHING
|
|
// affected-row-count pattern as VisitedCountriesRepository.markVisited above.
|
|
describe('SchoolHolidayCountriesRepository.insertIgnore — the ON CONFLICT DO NOTHING return', () => {
|
|
it('returns false on a repeat insert of the same code, true on the first', async () => {
|
|
const repo = await createTestSchoolHolidayCountriesRepo(testDb);
|
|
expect(await repo.insertIgnore({ code: 'US', name: 'United States' })).toBe(true);
|
|
expect(await repo.insertIgnore({ code: 'US', name: 'United States' })).toBe(false);
|
|
});
|
|
});
|