-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtasks.openapi-operationid.unit.tests.js
More file actions
29 lines (26 loc) · 1.11 KB
/
tasks.openapi-operationid.unit.tests.js
File metadata and controls
29 lines (26 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { describe, test, expect } from '@jest/globals';
import yaml from 'js-yaml';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
describe('modules/tasks/doc/tasks.yml — OpenAPI operationIds:', () => {
const specPath = path.resolve(__dirname, '../doc/tasks.yml');
const spec = yaml.load(fs.readFileSync(specPath, 'utf8'));
test('every operation has a unique operationId', () => {
const operationIds = [];
for (const [, pathItem] of Object.entries(spec.paths ?? {})) {
for (const [method, operation] of Object.entries(pathItem)) {
if (['get', 'post', 'put', 'patch', 'delete'].includes(method)) {
expect(operation.operationId).toBeDefined();
expect(typeof operation.operationId).toBe('string');
operationIds.push(operation.operationId);
}
}
}
// Uniqueness check
expect(new Set(operationIds).size).toBe(operationIds.length);
// At least one operationId (tasks.yml is not empty)
expect(operationIds.length).toBeGreaterThan(0);
});
});