test: assert Survey execution authorization is retired in F4

This commit is contained in:
2026-09-08 09:17:30 -03:00
parent 38742bf140
commit 9fab773090
@@ -1,18 +1,24 @@
import 'reflect-metadata';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import test from 'node:test';
import { REQUIRED_PERMISSIONS_KEY } from '../../src/authorization/decorators/require-permissions.decorator';
import { SurveyExecutionController } from '../../src/survey-execution/survey-execution.controller';
function permissionFor(method: string): string[] {
const controller = SurveyExecutionController.prototype;
const handler = controller[method as keyof typeof controller];
return Reflect.getMetadata(REQUIRED_PERMISSIONS_KEY, handler) as string[];
}
const root = process.cwd();
const migration = fs.readFileSync(
path.join(root, 'src/database/migrations/1790000300000-f4-remove-survey-subsystem.ts'),
'utf8',
);
test('survey report endpoints separate reading, capture and review', () => {
assert.deepEqual(permissionFor('get'), ['surveys.read_reports']);
assert.deepEqual(permissionFor('save'), ['surveys.capture']);
assert.deepEqual(permissionFor('submit'), ['surveys.capture']);
assert.deepEqual(permissionFor('review'), ['surveys.review']);
test('F4 removes the Survey execution controller from the active API', () => {
assert.equal(fs.existsSync(path.join(root, 'src/survey-execution/survey-execution.controller.ts')), false);
assert.equal(fs.existsSync(path.join(root, 'src/survey-execution/survey-execution.service.ts')), false);
});
test('F4 removes Survey execution and review permissions from active authorization', () => {
assert.match(migration, /'surveys\.execute'/);
assert.match(migration, /'surveys\.read_reports'/);
assert.match(migration, /'surveys\.capture'/);
assert.match(migration, /'surveys\.review'/);
assert.match(migration, /DELETE FROM role_permissions/);
assert.match(migration, /DELETE FROM permissions/);
});