mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-05 10:24:05 +00:00
test(db): run the atlas and backup suites on the real database module
They reset through resetDatabase and seed through the ORM factories instead of the SQLite snapshot mock, so they run in the Postgres lane as well.
This commit is contained in:
@@ -53,9 +53,7 @@
|
|||||||
"tests/e2e/vacay.e2e.test.ts": 1,
|
"tests/e2e/vacay.e2e.test.ts": 1,
|
||||||
"tests/e2e/weather.e2e.test.ts": 1,
|
"tests/e2e/weather.e2e.test.ts": 1,
|
||||||
"tests/integration/admin.test.ts": 1,
|
"tests/integration/admin.test.ts": 1,
|
||||||
"tests/integration/atlas.test.ts": 1,
|
|
||||||
"tests/integration/auth.test.ts": 1,
|
"tests/integration/auth.test.ts": 1,
|
||||||
"tests/integration/backup.test.ts": 1,
|
|
||||||
"tests/integration/collab.test.ts": 1,
|
"tests/integration/collab.test.ts": 1,
|
||||||
"tests/integration/dayReorder.test.ts": 1,
|
"tests/integration/dayReorder.test.ts": 1,
|
||||||
"tests/integration/files.test.ts": 1,
|
"tests/integration/files.test.ts": 1,
|
||||||
|
|||||||
@@ -3,14 +3,15 @@
|
|||||||
* Covers ATLAS-001 to ATLAS-008.
|
* Covers ATLAS-001 to ATLAS-008.
|
||||||
*/
|
*/
|
||||||
import { buildApp } from '../../src/bootstrap';
|
import { buildApp } from '../../src/bootstrap';
|
||||||
import { db as testDb } from '../../src/db/database';
|
|
||||||
import { PlaceRegions } from '../../src/db/entities/PlaceRegions.entity';
|
import { PlaceRegions } from '../../src/db/entities/PlaceRegions.entity';
|
||||||
import { authCookie } from '../helpers/auth';
|
import { authCookie } from '../helpers/auth';
|
||||||
import { createUser, createTrip } from '../helpers/factories';
|
|
||||||
import type { FactoryOrm } from '../helpers/factories/context';
|
import type { FactoryOrm } from '../helpers/factories/context';
|
||||||
import { makePlace } from '../helpers/factories/places';
|
import { makePlace } from '../helpers/factories/places';
|
||||||
import { findRow } from '../helpers/factories/rows';
|
import { findRow } from '../helpers/factories/rows';
|
||||||
import { resetTestDb, resetRateLimits } from '../helpers/test-db';
|
import { makeTrip } from '../helpers/factories/trips';
|
||||||
|
import { makeUser } from '../helpers/factories/users';
|
||||||
|
import { resetDatabase } from '../helpers/reset-database';
|
||||||
|
import { resetRateLimits } from '../helpers/test-db';
|
||||||
import { MikroORM } from '@mikro-orm/core';
|
import { MikroORM } from '@mikro-orm/core';
|
||||||
import type { INestApplication } from '@nestjs/common';
|
import type { INestApplication } from '@nestjs/common';
|
||||||
|
|
||||||
@@ -18,11 +19,6 @@ import type { Application } from 'express';
|
|||||||
import request from 'supertest';
|
import request from 'supertest';
|
||||||
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
|
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
|
||||||
|
|
||||||
vi.mock('../../src/db/database', async () => {
|
|
||||||
const { createSnapshotTestDb, buildDbMock } = await import('../helpers/db-mock');
|
|
||||||
return buildDbMock(createSnapshotTestDb());
|
|
||||||
});
|
|
||||||
|
|
||||||
let nestApp: INestApplication;
|
let nestApp: INestApplication;
|
||||||
let app: Application;
|
let app: Application;
|
||||||
/** The app's own ORM, which the factories seed and read through. */
|
/** The app's own ORM, which the factories seed and read through. */
|
||||||
@@ -55,19 +51,18 @@ beforeAll(async () => {
|
|||||||
}, 60_000);
|
}, 60_000);
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
resetTestDb(testDb);
|
await resetDatabase(orm());
|
||||||
await resetRateLimits(nestApp);
|
await resetRateLimits(nestApp);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
vi.unstubAllGlobals();
|
vi.unstubAllGlobals();
|
||||||
await nestApp.close();
|
await nestApp.close();
|
||||||
testDb.close();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Atlas stats', () => {
|
describe('Atlas stats', () => {
|
||||||
it('ATLAS-001 — GET /api/atlas/stats returns stats object', async () => {
|
it('ATLAS-001 — GET /api/atlas/stats returns stats object', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const res = await request(app).get('/api/addons/atlas/stats').set('Cookie', authCookie(user.id));
|
const res = await request(app).get('/api/addons/atlas/stats').set('Cookie', authCookie(user.id));
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
@@ -76,11 +71,19 @@ describe('Atlas stats', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-014 — a future trip is returned as planned and excluded from totalCountries (#1048)', async () => {
|
it('ATLAS-014 — a future trip is returned as planned and excluded from totalCountries (#1048)', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
// Offsets from today rather than literal dates, so this cannot expire.
|
// Offsets from today rather than literal dates, so this cannot expire.
|
||||||
const iso = (days: number) => new Date(Date.now() + days * 86_400_000).toISOString().slice(0, 10);
|
const iso = (days: number) => new Date(Date.now() + days * 86_400_000).toISOString().slice(0, 10);
|
||||||
const past = createTrip(testDb, user.id, { title: 'Rome, last month', start_date: iso(-40), end_date: iso(-30) });
|
const past = await makeTrip(orm(), user.id, {
|
||||||
const future = createTrip(testDb, user.id, { title: 'Tokyo, next month', start_date: iso(30), end_date: iso(40) });
|
title: 'Rome, last month',
|
||||||
|
start_date: iso(-40),
|
||||||
|
end_date: iso(-30),
|
||||||
|
});
|
||||||
|
const future = await makeTrip(orm(), user.id, {
|
||||||
|
title: 'Tokyo, next month',
|
||||||
|
start_date: iso(30),
|
||||||
|
end_date: iso(40),
|
||||||
|
});
|
||||||
// No coordinates and no category: the country has to come from the address.
|
// No coordinates and no category: the country has to come from the address.
|
||||||
const unplaced = { lat: null, lng: null, category: null };
|
const unplaced = { lat: null, lng: null, category: null };
|
||||||
await makePlace(orm(), past.id, { ...unplaced, name: 'Colosseum', address: 'Piazza del Colosseo, Rome, Italy' });
|
await makePlace(orm(), past.id, { ...unplaced, name: 'Colosseum', address: 'Piazza del Colosseo, Rome, Italy' });
|
||||||
@@ -99,7 +102,7 @@ describe('Atlas stats', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-002 — GET /api/atlas/country/:code returns places in country', async () => {
|
it('ATLAS-002 — GET /api/atlas/country/:code returns places in country', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const res = await request(app).get('/api/addons/atlas/country/FR').set('Cookie', authCookie(user.id));
|
const res = await request(app).get('/api/addons/atlas/country/FR').set('Cookie', authCookie(user.id));
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
@@ -109,7 +112,7 @@ describe('Atlas stats', () => {
|
|||||||
|
|
||||||
describe('Mark/unmark country', () => {
|
describe('Mark/unmark country', () => {
|
||||||
it('ATLAS-003 — POST /country/:code/mark marks country as visited', async () => {
|
it('ATLAS-003 — POST /country/:code/mark marks country as visited', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const res = await request(app).post('/api/addons/atlas/country/DE/mark').set('Cookie', authCookie(user.id));
|
const res = await request(app).post('/api/addons/atlas/country/DE/mark').set('Cookie', authCookie(user.id));
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
@@ -122,7 +125,7 @@ describe('Mark/unmark country', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-004 — DELETE /country/:code/mark unmarks country', async () => {
|
it('ATLAS-004 — DELETE /country/:code/mark unmarks country', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
await request(app).post('/api/addons/atlas/country/IT/mark').set('Cookie', authCookie(user.id));
|
await request(app).post('/api/addons/atlas/country/IT/mark').set('Cookie', authCookie(user.id));
|
||||||
|
|
||||||
@@ -134,7 +137,7 @@ describe('Mark/unmark country', () => {
|
|||||||
|
|
||||||
describe('Bucket list', () => {
|
describe('Bucket list', () => {
|
||||||
it('ATLAS-005 — POST /bucket-list creates a bucket list item', async () => {
|
it('ATLAS-005 — POST /bucket-list creates a bucket list item', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
.post('/api/addons/atlas/bucket-list')
|
.post('/api/addons/atlas/bucket-list')
|
||||||
@@ -145,7 +148,7 @@ describe('Bucket list', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-005 — POST without name returns 400', async () => {
|
it('ATLAS-005 — POST without name returns 400', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
.post('/api/addons/atlas/bucket-list')
|
.post('/api/addons/atlas/bucket-list')
|
||||||
@@ -155,7 +158,7 @@ describe('Bucket list', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-005 — POST the same item twice returns 409 and keeps one row (#1898)', async () => {
|
it('ATLAS-005 — POST the same item twice returns 409 and keeps one row (#1898)', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
const body = { name: 'Japan', country_code: 'JP' };
|
const body = { name: 'Japan', country_code: 'JP' };
|
||||||
|
|
||||||
const first = await request(app)
|
const first = await request(app)
|
||||||
@@ -176,7 +179,7 @@ describe('Bucket list', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-005 — POST the same item for another target date is allowed (#1898)', async () => {
|
it('ATLAS-005 — POST the same item for another target date is allowed (#1898)', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const undated = await request(app)
|
const undated = await request(app)
|
||||||
.post('/api/addons/atlas/bucket-list')
|
.post('/api/addons/atlas/bucket-list')
|
||||||
@@ -195,7 +198,7 @@ describe('Bucket list', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-006 — GET /bucket-list returns items', async () => {
|
it('ATLAS-006 — GET /bucket-list returns items', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
await request(app)
|
await request(app)
|
||||||
.post('/api/addons/atlas/bucket-list')
|
.post('/api/addons/atlas/bucket-list')
|
||||||
@@ -208,7 +211,7 @@ describe('Bucket list', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-007 — PUT /bucket-list/:id updates item', async () => {
|
it('ATLAS-007 — PUT /bucket-list/:id updates item', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const create = await request(app)
|
const create = await request(app)
|
||||||
.post('/api/addons/atlas/bucket-list')
|
.post('/api/addons/atlas/bucket-list')
|
||||||
@@ -225,7 +228,7 @@ describe('Bucket list', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-007 — PUT onto an existing wish returns 409 and leaves the row alone (#1898)', async () => {
|
it('ATLAS-007 — PUT onto an existing wish returns 409 and leaves the row alone (#1898)', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
await request(app)
|
await request(app)
|
||||||
.post('/api/addons/atlas/bucket-list')
|
.post('/api/addons/atlas/bucket-list')
|
||||||
.set('Cookie', authCookie(user.id))
|
.set('Cookie', authCookie(user.id))
|
||||||
@@ -247,7 +250,7 @@ describe('Bucket list', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-008 — DELETE /bucket-list/:id removes item', async () => {
|
it('ATLAS-008 — DELETE /bucket-list/:id removes item', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const create = await request(app)
|
const create = await request(app)
|
||||||
.post('/api/addons/atlas/bucket-list')
|
.post('/api/addons/atlas/bucket-list')
|
||||||
@@ -264,7 +267,7 @@ describe('Bucket list', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-008 — DELETE non-existent item returns 404', async () => {
|
it('ATLAS-008 — DELETE non-existent item returns 404', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const res = await request(app).delete('/api/addons/atlas/bucket-list/99999').set('Cookie', authCookie(user.id));
|
const res = await request(app).delete('/api/addons/atlas/bucket-list/99999').set('Cookie', authCookie(user.id));
|
||||||
expect(res.status).toBe(404);
|
expect(res.status).toBe(404);
|
||||||
@@ -273,7 +276,7 @@ describe('Bucket list', () => {
|
|||||||
|
|
||||||
describe('Mark/unmark region', () => {
|
describe('Mark/unmark region', () => {
|
||||||
it('ATLAS-009 — POST /region/:code/mark marks a region as visited', async () => {
|
it('ATLAS-009 — POST /region/:code/mark marks a region as visited', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
.post('/api/addons/atlas/region/DE-NW/mark')
|
.post('/api/addons/atlas/region/DE-NW/mark')
|
||||||
@@ -285,7 +288,7 @@ describe('Mark/unmark region', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-009 — POST /region/:code/mark without name returns 400', async () => {
|
it('ATLAS-009 — POST /region/:code/mark without name returns 400', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
.post('/api/addons/atlas/region/DE-NW/mark')
|
.post('/api/addons/atlas/region/DE-NW/mark')
|
||||||
@@ -296,7 +299,7 @@ describe('Mark/unmark region', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-009 — POST /region/:code/mark without country_code returns 400', async () => {
|
it('ATLAS-009 — POST /region/:code/mark without country_code returns 400', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
.post('/api/addons/atlas/region/DE-NW/mark')
|
.post('/api/addons/atlas/region/DE-NW/mark')
|
||||||
@@ -307,7 +310,7 @@ describe('Mark/unmark region', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-009 — marking a region also auto-marks the parent country', async () => {
|
it('ATLAS-009 — marking a region also auto-marks the parent country', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
await request(app)
|
await request(app)
|
||||||
.post('/api/addons/atlas/region/DE-NW/mark')
|
.post('/api/addons/atlas/region/DE-NW/mark')
|
||||||
@@ -321,7 +324,7 @@ describe('Mark/unmark region', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-009 — marking the same region twice is idempotent', async () => {
|
it('ATLAS-009 — marking the same region twice is idempotent', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
await request(app)
|
await request(app)
|
||||||
.post('/api/addons/atlas/region/DE-NW/mark')
|
.post('/api/addons/atlas/region/DE-NW/mark')
|
||||||
@@ -337,7 +340,7 @@ describe('Mark/unmark region', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-010 — GET /regions returns marked regions grouped by country', async () => {
|
it('ATLAS-010 — GET /regions returns marked regions grouped by country', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
await request(app)
|
await request(app)
|
||||||
.post('/api/addons/atlas/region/DE-NW/mark')
|
.post('/api/addons/atlas/region/DE-NW/mark')
|
||||||
@@ -361,7 +364,7 @@ describe('Mark/unmark region', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-011 — DELETE /region/:code/mark unmarks a region', async () => {
|
it('ATLAS-011 — DELETE /region/:code/mark unmarks a region', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
await request(app)
|
await request(app)
|
||||||
.post('/api/addons/atlas/region/DE-NW/mark')
|
.post('/api/addons/atlas/region/DE-NW/mark')
|
||||||
@@ -381,7 +384,7 @@ describe('Mark/unmark region', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-011 — unmark last region in country also unmarks the parent country', async () => {
|
it('ATLAS-011 — unmark last region in country also unmarks the parent country', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
await request(app)
|
await request(app)
|
||||||
.post('/api/addons/atlas/region/DE-NW/mark')
|
.post('/api/addons/atlas/region/DE-NW/mark')
|
||||||
@@ -397,7 +400,7 @@ describe('Mark/unmark region', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-011 — unmark one region keeps country when another region remains', async () => {
|
it('ATLAS-011 — unmark one region keeps country when another region remains', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
await request(app)
|
await request(app)
|
||||||
.post('/api/addons/atlas/region/DE-NW/mark')
|
.post('/api/addons/atlas/region/DE-NW/mark')
|
||||||
@@ -418,7 +421,7 @@ describe('Mark/unmark region', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-011: unmark last region keeps a country the user marked visited itself (#2597)', async () => {
|
it('ATLAS-011: unmark last region keeps a country the user marked visited itself (#2597)', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
const cookie = authCookie(user.id);
|
const cookie = authCookie(user.id);
|
||||||
|
|
||||||
await request(app).post('/api/addons/atlas/country/NO/mark').set('Cookie', cookie);
|
await request(app).post('/api/addons/atlas/country/NO/mark').set('Cookie', cookie);
|
||||||
@@ -437,7 +440,7 @@ describe('Mark/unmark region', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-011: a country first reached through a region stays once it is marked itself (#2597)', async () => {
|
it('ATLAS-011: a country first reached through a region stays once it is marked itself (#2597)', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
const cookie = authCookie(user.id);
|
const cookie = authCookie(user.id);
|
||||||
|
|
||||||
await request(app)
|
await request(app)
|
||||||
@@ -455,8 +458,8 @@ describe('Mark/unmark region', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-011 — regions are isolated between users', async () => {
|
it('ATLAS-011 — regions are isolated between users', async () => {
|
||||||
const { user: user1 } = createUser(testDb);
|
const { user: user1 } = await makeUser(orm());
|
||||||
const { user: user2 } = createUser(testDb);
|
const { user: user2 } = await makeUser(orm());
|
||||||
|
|
||||||
await request(app)
|
await request(app)
|
||||||
.post('/api/addons/atlas/region/DE-NW/mark')
|
.post('/api/addons/atlas/region/DE-NW/mark')
|
||||||
@@ -473,7 +476,7 @@ describe('Mark/unmark region', () => {
|
|||||||
|
|
||||||
describe('Regions geo', () => {
|
describe('Regions geo', () => {
|
||||||
it('ATLAS-012 — GET /regions/geo without countries param returns empty FeatureCollection', async () => {
|
it('ATLAS-012 — GET /regions/geo without countries param returns empty FeatureCollection', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const res = await request(app).get('/api/addons/atlas/regions/geo').set('Cookie', authCookie(user.id));
|
const res = await request(app).get('/api/addons/atlas/regions/geo').set('Cookie', authCookie(user.id));
|
||||||
|
|
||||||
@@ -482,7 +485,7 @@ describe('Regions geo', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-013 — GET /regions/geo?countries=DE,FR returns FeatureCollection', async () => {
|
it('ATLAS-013 — GET /regions/geo?countries=DE,FR returns FeatureCollection', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
.get('/api/addons/atlas/regions/geo?countries=DE,FR')
|
.get('/api/addons/atlas/regions/geo?countries=DE,FR')
|
||||||
@@ -496,7 +499,7 @@ describe('Regions geo', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-016 — GET /regions/geo/:code serves that country gzipped, cached for a day', async () => {
|
it('ATLAS-016 — GET /regions/geo/:code serves that country gzipped, cached for a day', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
.get('/api/addons/atlas/regions/geo/no')
|
.get('/api/addons/atlas/regions/geo/no')
|
||||||
@@ -514,7 +517,7 @@ describe('Regions geo', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-017 — GET /regions/geo/:code answers a country without regions with an empty FeatureCollection', async () => {
|
it('ATLAS-017 — GET /regions/geo/:code answers a country without regions with an empty FeatureCollection', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const res = await request(app).get('/api/addons/atlas/regions/geo/ZZ').set('Cookie', authCookie(user.id));
|
const res = await request(app).get('/api/addons/atlas/regions/geo/ZZ').set('Cookie', authCookie(user.id));
|
||||||
|
|
||||||
@@ -523,7 +526,7 @@ describe('Regions geo', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-018 — GET /regions/geo/:code refuses a code that is not two letters with a 400', async () => {
|
it('ATLAS-018 — GET /regions/geo/:code refuses a code that is not two letters with a 400', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
|
|
||||||
const codes = ['NOR', '..%2Fadmin0'];
|
const codes = ['NOR', '..%2Fadmin0'];
|
||||||
const answers = await Promise.all(
|
const answers = await Promise.all(
|
||||||
@@ -560,8 +563,8 @@ describe('A place that moves takes its Atlas country with it (#2527)', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
it('ATLAS-015: correcting a place from France to Germany moves it on the Atlas', async () => {
|
it('ATLAS-015: correcting a place from France to Germany moves it on the Atlas', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
const trip = createTrip(testDb, user.id, {
|
const trip = await makeTrip(orm(), user.id, {
|
||||||
title: 'Wrongly imported',
|
title: 'Wrongly imported',
|
||||||
start_date: '2025-05-01',
|
start_date: '2025-05-01',
|
||||||
end_date: '2025-05-05',
|
end_date: '2025-05-05',
|
||||||
@@ -597,8 +600,8 @@ describe('A place that moves takes its Atlas country with it (#2527)', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ATLAS-015: an edit that leaves the location alone keeps the cached country', async () => {
|
it('ATLAS-015: an edit that leaves the location alone keeps the cached country', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm());
|
||||||
const trip = createTrip(testDb, user.id, { title: 'Paris', start_date: '2025-05-01', end_date: '2025-05-05' });
|
const trip = await makeTrip(orm(), user.id, { title: 'Paris', start_date: '2025-05-01', end_date: '2025-05-05' });
|
||||||
const place = await makePlace(orm(), trip.id, {
|
const place = await makePlace(orm(), trip.id, {
|
||||||
name: 'Louvre',
|
name: 'Louvre',
|
||||||
lat: 48.8606,
|
lat: 48.8606,
|
||||||
|
|||||||
@@ -7,12 +7,13 @@
|
|||||||
* but the service should handle gracefully.
|
* but the service should handle gracefully.
|
||||||
*/
|
*/
|
||||||
import { buildApp } from '../../src/bootstrap';
|
import { buildApp } from '../../src/bootstrap';
|
||||||
import { db as testDb } from '../../src/db/database';
|
|
||||||
import * as backupService from '../../src/nest/backup/backup.impl';
|
import * as backupService from '../../src/nest/backup/backup.impl';
|
||||||
import { DEFAULT_BACKUPS_ROOT } from '../../src/nest/storage/storage-paths';
|
import { DEFAULT_BACKUPS_ROOT } from '../../src/nest/storage/storage-paths';
|
||||||
import { authCookie } from '../helpers/auth';
|
import { authCookie } from '../helpers/auth';
|
||||||
import { createAdmin, createUser } from '../helpers/factories';
|
import { makeAdmin, makeUser } from '../helpers/factories/users';
|
||||||
import { resetTestDb, resetRateLimits } from '../helpers/test-db';
|
import { resetDatabase } from '../helpers/reset-database';
|
||||||
|
import { resetRateLimits } from '../helpers/test-db';
|
||||||
|
import { MikroORM } from '@mikro-orm/core';
|
||||||
import type { INestApplication } from '@nestjs/common';
|
import type { INestApplication } from '@nestjs/common';
|
||||||
|
|
||||||
import type { Application } from 'express';
|
import type { Application } from 'express';
|
||||||
@@ -22,11 +23,6 @@ import path from 'path';
|
|||||||
import request from 'supertest';
|
import request from 'supertest';
|
||||||
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
|
import { describe, it, expect, vi, beforeAll, beforeEach, afterAll } from 'vitest';
|
||||||
|
|
||||||
vi.mock('../../src/db/database', async () => {
|
|
||||||
const { createSnapshotTestDb, buildDbMock } = await import('../helpers/db-mock');
|
|
||||||
return buildDbMock(createSnapshotTestDb());
|
|
||||||
});
|
|
||||||
|
|
||||||
// Mock filesystem-dependent service functions to avoid real disk I/O in tests
|
// Mock filesystem-dependent service functions to avoid real disk I/O in tests
|
||||||
vi.mock('../../src/nest/backup/backup.impl', async () => {
|
vi.mock('../../src/nest/backup/backup.impl', async () => {
|
||||||
const actual = await vi.importActual<typeof import('../../src/nest/backup/backup.impl')>(
|
const actual = await vi.importActual<typeof import('../../src/nest/backup/backup.impl')>(
|
||||||
@@ -71,25 +67,26 @@ vi.mock('../../src/nest/backup/auto-backup.settings', async () => {
|
|||||||
|
|
||||||
let nestApp: INestApplication;
|
let nestApp: INestApplication;
|
||||||
let app: Application;
|
let app: Application;
|
||||||
|
let orm: MikroORM;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
nestApp = await buildApp();
|
nestApp = await buildApp();
|
||||||
app = nestApp.getHttpAdapter().getInstance();
|
app = nestApp.getHttpAdapter().getInstance();
|
||||||
|
orm = nestApp.get(MikroORM);
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
resetTestDb(testDb);
|
await resetDatabase(orm);
|
||||||
await resetRateLimits(nestApp);
|
await resetRateLimits(nestApp);
|
||||||
});
|
});
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
await nestApp.close();
|
await nestApp.close();
|
||||||
testDb.close();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Backup access control', () => {
|
describe('Backup access control', () => {
|
||||||
it('non-admin cannot access backup routes', async () => {
|
it('non-admin cannot access backup routes', async () => {
|
||||||
const { user } = createUser(testDb);
|
const { user } = await makeUser(orm);
|
||||||
|
|
||||||
const res = await request(app).get('/api/backup/list').set('Cookie', authCookie(user.id));
|
const res = await request(app).get('/api/backup/list').set('Cookie', authCookie(user.id));
|
||||||
expect(res.status).toBe(403);
|
expect(res.status).toBe(403);
|
||||||
@@ -98,7 +95,7 @@ describe('Backup access control', () => {
|
|||||||
|
|
||||||
describe('Backup list', () => {
|
describe('Backup list', () => {
|
||||||
it('BACKUP-001 — GET /backup/list returns backups array', async () => {
|
it('BACKUP-001 — GET /backup/list returns backups array', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
|
|
||||||
const res = await request(app).get('/api/backup/list').set('Cookie', authCookie(admin.id));
|
const res = await request(app).get('/api/backup/list').set('Cookie', authCookie(admin.id));
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
@@ -108,7 +105,7 @@ describe('Backup list', () => {
|
|||||||
|
|
||||||
describe('Backup creation', () => {
|
describe('Backup creation', () => {
|
||||||
it('BACKUP-001 — POST /backup/create creates a backup', async () => {
|
it('BACKUP-001 — POST /backup/create creates a backup', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
|
|
||||||
const res = await request(app).post('/api/backup/create').set('Cookie', authCookie(admin.id));
|
const res = await request(app).post('/api/backup/create').set('Cookie', authCookie(admin.id));
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
@@ -120,7 +117,7 @@ describe('Backup creation', () => {
|
|||||||
|
|
||||||
describe('Auto-backup settings', () => {
|
describe('Auto-backup settings', () => {
|
||||||
it('BACKUP-008 — GET /backup/auto-settings returns current config', async () => {
|
it('BACKUP-008 — GET /backup/auto-settings returns current config', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
|
|
||||||
const res = await request(app).get('/api/backup/auto-settings').set('Cookie', authCookie(admin.id));
|
const res = await request(app).get('/api/backup/auto-settings').set('Cookie', authCookie(admin.id));
|
||||||
expect(res.status).toBe(200);
|
expect(res.status).toBe(200);
|
||||||
@@ -129,7 +126,7 @@ describe('Auto-backup settings', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('BACKUP-008 — PUT /backup/auto-settings updates settings', async () => {
|
it('BACKUP-008 — PUT /backup/auto-settings updates settings', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
|
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
.put('/api/backup/auto-settings')
|
.put('/api/backup/auto-settings')
|
||||||
@@ -144,7 +141,7 @@ describe('Auto-backup settings', () => {
|
|||||||
|
|
||||||
describe('Backup security', () => {
|
describe('Backup security', () => {
|
||||||
it('BACKUP-007 — Download with path traversal filename is rejected', async () => {
|
it('BACKUP-007 — Download with path traversal filename is rejected', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
|
|
||||||
const res = await request(app).get('/api/backup/download/../../etc/passwd').set('Cookie', authCookie(admin.id));
|
const res = await request(app).get('/api/backup/download/../../etc/passwd').set('Cookie', authCookie(admin.id));
|
||||||
// Express normalises the URL before routing; path traversal gets resolved
|
// Express normalises the URL before routing; path traversal gets resolved
|
||||||
@@ -153,7 +150,7 @@ describe('Backup security', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('BACKUP-007 — Delete with path traversal filename is rejected', async () => {
|
it('BACKUP-007 — Delete with path traversal filename is rejected', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
|
|
||||||
const res = await request(app).delete('/api/backup/../../../etc/passwd').set('Cookie', authCookie(admin.id));
|
const res = await request(app).delete('/api/backup/../../../etc/passwd').set('Cookie', authCookie(admin.id));
|
||||||
// Express normalises the URL, stripping traversal → no route match → 404
|
// Express normalises the URL, stripping traversal → no route match → 404
|
||||||
@@ -183,7 +180,7 @@ describe('Backup download', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('BACKUP-INT-001 — GET /backup/download/:filename returns 200 with content-disposition', async () => {
|
it('BACKUP-INT-001 — GET /backup/download/:filename returns 200 with content-disposition', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
// (Re)write the fixture immediately before the request that serves it.
|
// (Re)write the fixture immediately before the request that serves it.
|
||||||
fs.mkdirSync(DEFAULT_BACKUPS_ROOT, { recursive: true });
|
fs.mkdirSync(DEFAULT_BACKUPS_ROOT, { recursive: true });
|
||||||
fs.writeFileSync(downloadFixturePath, 'fake zip content');
|
fs.writeFileSync(downloadFixturePath, 'fake zip content');
|
||||||
@@ -199,7 +196,7 @@ describe('Backup download', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('BACKUP-INT-002 — GET /backup/download/:filename returns 400 for invalid filename', async () => {
|
it('BACKUP-INT-002 — GET /backup/download/:filename returns 400 for invalid filename', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
vi.mocked(backupService.backupFileExists).mockResolvedValue(false);
|
vi.mocked(backupService.backupFileExists).mockResolvedValue(false);
|
||||||
|
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
@@ -211,7 +208,7 @@ describe('Backup download', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('BACKUP-INT-003 — GET /backup/download/:filename returns 404 when file not found', async () => {
|
it('BACKUP-INT-003 — GET /backup/download/:filename returns 404 when file not found', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
vi.mocked(backupService.backupFileExists).mockResolvedValue(false);
|
vi.mocked(backupService.backupFileExists).mockResolvedValue(false);
|
||||||
|
|
||||||
const res = await request(app)
|
const res = await request(app)
|
||||||
@@ -229,7 +226,7 @@ describe('Backup download', () => {
|
|||||||
|
|
||||||
describe('Backup restore', () => {
|
describe('Backup restore', () => {
|
||||||
it('BACKUP-INT-004 — POST /backup/restore/:filename returns 200 on success', async () => {
|
it('BACKUP-INT-004 — POST /backup/restore/:filename returns 200 on success', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
const filename = 'backup-2026-04-06T12-00-00.zip';
|
const filename = 'backup-2026-04-06T12-00-00.zip';
|
||||||
|
|
||||||
vi.mocked(backupService.backupFileExists).mockResolvedValue(true);
|
vi.mocked(backupService.backupFileExists).mockResolvedValue(true);
|
||||||
@@ -243,7 +240,7 @@ describe('Backup restore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('BACKUP-INT-005 — POST /backup/restore/:filename returns 404 when backup not found', async () => {
|
it('BACKUP-INT-005 — POST /backup/restore/:filename returns 404 when backup not found', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
|
|
||||||
vi.mocked(backupService.backupFileExists).mockResolvedValue(false);
|
vi.mocked(backupService.backupFileExists).mockResolvedValue(false);
|
||||||
|
|
||||||
@@ -256,7 +253,7 @@ describe('Backup restore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('BACKUP-INT-006 — POST /backup/restore/:filename returns 400 for invalid filename', async () => {
|
it('BACKUP-INT-006 — POST /backup/restore/:filename returns 400 for invalid filename', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
|
|
||||||
const res = await request(app).post('/api/backup/restore/../../evil.zip').set('Cookie', authCookie(admin.id));
|
const res = await request(app).post('/api/backup/restore/../../evil.zip').set('Cookie', authCookie(admin.id));
|
||||||
|
|
||||||
@@ -265,7 +262,7 @@ describe('Backup restore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('BACKUP-INT-007 — POST /backup/restore/:filename returns 400 when the restore reports failure', async () => {
|
it('BACKUP-INT-007 — POST /backup/restore/:filename returns 400 when the restore reports failure', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
const filename = 'backup-2026-04-06T12-00-00.zip';
|
const filename = 'backup-2026-04-06T12-00-00.zip';
|
||||||
|
|
||||||
vi.mocked(backupService.backupFileExists).mockResolvedValue(true);
|
vi.mocked(backupService.backupFileExists).mockResolvedValue(true);
|
||||||
@@ -288,7 +285,7 @@ describe('Backup restore', () => {
|
|||||||
|
|
||||||
describe('Backup delete', () => {
|
describe('Backup delete', () => {
|
||||||
it('BACKUP-INT-008 — DELETE /backup/:filename returns 200 on success', async () => {
|
it('BACKUP-INT-008 — DELETE /backup/:filename returns 200 on success', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
const filename = 'backup-2026-04-06T12-00-00.zip';
|
const filename = 'backup-2026-04-06T12-00-00.zip';
|
||||||
|
|
||||||
vi.mocked(backupService.backupFileExists).mockResolvedValue(true);
|
vi.mocked(backupService.backupFileExists).mockResolvedValue(true);
|
||||||
@@ -303,7 +300,7 @@ describe('Backup delete', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('BACKUP-INT-009 — DELETE /backup/:filename returns 404 when not found', async () => {
|
it('BACKUP-INT-009 — DELETE /backup/:filename returns 404 when not found', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
|
|
||||||
vi.mocked(backupService.backupFileExists).mockResolvedValue(false);
|
vi.mocked(backupService.backupFileExists).mockResolvedValue(false);
|
||||||
|
|
||||||
@@ -316,7 +313,7 @@ describe('Backup delete', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('BACKUP-INT-010 — DELETE /backup/:filename returns 400 for invalid filename', async () => {
|
it('BACKUP-INT-010 — DELETE /backup/:filename returns 400 for invalid filename', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
|
|
||||||
const res = await request(app).delete('/api/backup/not-a-backup.tar.gz').set('Cookie', authCookie(admin.id));
|
const res = await request(app).delete('/api/backup/not-a-backup.tar.gz').set('Cookie', authCookie(admin.id));
|
||||||
|
|
||||||
@@ -331,7 +328,7 @@ describe('Backup delete', () => {
|
|||||||
|
|
||||||
describe('Backup rate limiter', () => {
|
describe('Backup rate limiter', () => {
|
||||||
it('BACKUP-INT-011 — POST /backup/create returns 429 after 3 requests', async () => {
|
it('BACKUP-INT-011 — POST /backup/create returns 429 after 3 requests', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
|
|
||||||
// Allow first 3 calls, then block
|
// Allow first 3 calls, then block
|
||||||
let callCount = 0;
|
let callCount = 0;
|
||||||
@@ -359,7 +356,7 @@ describe('Backup rate limiter', () => {
|
|||||||
|
|
||||||
describe('Backup upload-restore', () => {
|
describe('Backup upload-restore', () => {
|
||||||
it('BACKUP-INT-012 — POST /backup/upload-restore with zip file returns 200', async () => {
|
it('BACKUP-INT-012 — POST /backup/upload-restore with zip file returns 200', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
|
|
||||||
vi.mocked(backupService.restoreFromZip).mockResolvedValue({ success: true });
|
vi.mocked(backupService.restoreFromZip).mockResolvedValue({ success: true });
|
||||||
|
|
||||||
@@ -377,7 +374,7 @@ describe('Backup upload-restore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('BACKUP-INT-013 — POST /backup/upload-restore with no file returns 400', async () => {
|
it('BACKUP-INT-013 — POST /backup/upload-restore with no file returns 400', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
|
|
||||||
const res = await request(app).post('/api/backup/upload-restore').set('Cookie', authCookie(admin.id));
|
const res = await request(app).post('/api/backup/upload-restore').set('Cookie', authCookie(admin.id));
|
||||||
|
|
||||||
@@ -386,7 +383,7 @@ describe('Backup upload-restore', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('BACKUP-INT-014 — POST /backup/upload-restore returns 400 when restore fails', async () => {
|
it('BACKUP-INT-014 — POST /backup/upload-restore returns 400 when restore fails', async () => {
|
||||||
const { user: admin } = createAdmin(testDb);
|
const { user: admin } = await makeAdmin(orm);
|
||||||
|
|
||||||
vi.mocked(backupService.restoreFromZip).mockResolvedValue({
|
vi.mocked(backupService.restoreFromZip).mockResolvedValue({
|
||||||
success: false,
|
success: false,
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
[
|
[
|
||||||
"tests/integration/admin.test.ts",
|
"tests/integration/admin.test.ts",
|
||||||
"tests/integration/atlas.test.ts",
|
|
||||||
"tests/integration/auth.test.ts",
|
"tests/integration/auth.test.ts",
|
||||||
"tests/integration/backup.test.ts",
|
|
||||||
"tests/integration/collab.test.ts",
|
"tests/integration/collab.test.ts",
|
||||||
"tests/integration/files.test.ts",
|
"tests/integration/files.test.ts",
|
||||||
"tests/integration/journey-place-order.test.ts",
|
"tests/integration/journey-place-order.test.ts",
|
||||||
|
|||||||
Reference in New Issue
Block a user