mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 05:26:47 +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.
51 lines
2.1 KiB
TypeScript
51 lines
2.1 KiB
TypeScript
import { checkBackupDatabase } from '../../../src/nest/backup/backup-archive';
|
|
|
|
import Database from 'better-sqlite3';
|
|
import fs from 'node:fs';
|
|
import os from 'node:os';
|
|
import path from 'node:path';
|
|
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
|
|
describe('checkBackupDatabase and the release that made the backup', () => {
|
|
let dir: string;
|
|
|
|
beforeEach(() => {
|
|
dir = fs.mkdtempSync(path.join(os.tmpdir(), 'trek-backup-version-'));
|
|
});
|
|
afterEach(() => {
|
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
});
|
|
|
|
const backupWith = (recorded: string[]): void => {
|
|
const db = new Database(path.join(dir, 'travel.db'));
|
|
for (const table of ['users', 'trips', 'trip_members', 'places', 'days'])
|
|
db.exec(`CREATE TABLE ${table} (id INTEGER)`);
|
|
db.exec('CREATE TABLE mikro_orm_migrations (id INTEGER PRIMARY KEY, name TEXT, executed_at TEXT)');
|
|
// test-sql-allow: a bare backup file before any boot, which no ORM is bound to.
|
|
const insert = db.prepare('INSERT INTO mikro_orm_migrations (name) VALUES (?)');
|
|
for (const name of recorded) insert.run(name);
|
|
db.close();
|
|
};
|
|
|
|
it('BACKUPVER-001: refuses a backup a newer TREK made, before anything is swapped', () => {
|
|
backupWith(['Migration20200101000000_baseline_schema', 'Migration20990101000000_from_a_newer_release']);
|
|
expect(checkBackupDatabase(dir)).toEqual({
|
|
error: 'This backup was made by a newer TREK version. Update TREK before restoring it.',
|
|
status: 400,
|
|
});
|
|
});
|
|
|
|
it('BACKUPVER-002: accepts a backup this release or an older one made', () => {
|
|
backupWith(['Migration20200101000000_baseline_schema', 'Migration20200101042000_tours']);
|
|
expect(checkBackupDatabase(dir)).toBeNull();
|
|
});
|
|
|
|
it('BACKUPVER-003: accepts a pre-ORM backup without the migrations table', () => {
|
|
const db = new Database(path.join(dir, 'travel.db'));
|
|
for (const table of ['users', 'trips', 'trip_members', 'places', 'days'])
|
|
db.exec(`CREATE TABLE ${table} (id INTEGER)`);
|
|
db.close();
|
|
expect(checkBackupDatabase(dir)).toBeNull();
|
|
});
|
|
});
|