krona-staff/tests/unit/migration-checksum.test.ts
Ochenstarik d45bee960a
Some checks are pending
ci / verify (push) Waiting to run
fix: harden terminal recovery and deployment
2026-09-18 11:10:28 +07:00

27 lines
976 B
TypeScript

import { describe, expect, it } from 'vitest';
import {
assertAppliedMigrationsPresent,
assertMigrationChecksum,
migrationChecksum,
} from '../../scripts/migration-checksum.mjs';
describe('migration checksums', () => {
it('is stable for the exact migration bytes', () => {
const content = Buffer.from('SELECT 1;\n', 'utf8');
expect(migrationChecksum(content)).toBe(migrationChecksum(content));
});
it('rejects a modified applied migration', () => {
const expected = migrationChecksum(Buffer.from('SELECT 1;\n', 'utf8'));
const actual = migrationChecksum(Buffer.from('SELECT 2;\n', 'utf8'));
expect(() => assertMigrationChecksum('0001', expected, actual)).toThrow(
/Applied migration 0001 was modified/,
);
});
it('rejects an applied migration removed from the repository', () => {
expect(() => assertAppliedMigrationsPresent(['0001', '0002'], ['0002'])).toThrow(
/Applied migration 0001 is missing/,
);
});
});