26 lines
899 B
TypeScript
26 lines
899 B
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { ConflictException } from '@nestjs/common';
|
|
import type { EntityManager } from 'typeorm';
|
|
import { assertAdministrativeRecoveryRemains } from '../../src/administration/common/administration-audit';
|
|
|
|
function managerWithCount(count: number): EntityManager {
|
|
return {
|
|
query: async () => [{ count }],
|
|
} as unknown as EntityManager;
|
|
}
|
|
|
|
test('administrative integrity accepts at least one recovery administrator', async () => {
|
|
await assert.doesNotReject(
|
|
assertAdministrativeRecoveryRemains(managerWithCount(1)),
|
|
);
|
|
});
|
|
|
|
test('administrative integrity prevents removing the last recovery administrator', async () => {
|
|
await assert.rejects(
|
|
assertAdministrativeRecoveryRemains(managerWithCount(0)),
|
|
(error: unknown) =>
|
|
error instanceof ConflictException && error.getStatus() === 409,
|
|
);
|
|
});
|