-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathjs-sdk-emitter.test.ts
More file actions
76 lines (69 loc) · 2.8 KB
/
Copy pathjs-sdk-emitter.test.ts
File metadata and controls
76 lines (69 loc) · 2.8 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { describe, expect, test } from 'vitest';
import {
createJsSdkEmitter,
jsSuiteFileName,
renderJsSuite,
} from '../../materializer/src/js-sdk/emitter.js';
import type { EndpointScenarioCollection, RequestStep } from '../../path-analyser/src/types.ts';
const SAMPLE_COLLECTION: EndpointScenarioCollection = {
endpoint: { operationId: 'getWidget', method: 'GET', path: '/widgets/{widgetId}' },
requiredSemanticTypes: [],
optionalSemanticTypes: [],
scenarios: [
{
id: 'sc1',
name: 'happy path',
description: 'Fetch a widget by ID',
operations: [{ operationId: 'getWidget', method: 'GET', path: '/widgets/{widgetId}' }],
producedSemanticTypes: [],
satisfiedSemanticTypes: [],
requestPlan: [
{
operationId: 'getWidget',
method: 'GET',
pathTemplate: '/widgets/{widgetId}',
pathParams: [{ name: 'widgetId', var: 'widgetIdVar' }],
expect: { status: 200 },
extract: [{ fieldPath: 'data.id', bind: 'widgetId' }],
} satisfies RequestStep,
],
},
],
};
describe('JavaScript SDK Emitter', () => {
test('factory creates emitter with correct metadata', () => {
const emitter = createJsSdkEmitter(undefined);
expect(emitter.id).toBe('js-sdk');
expect(emitter.name).toBe('JavaScript SDK');
expect(emitter.supportedConfigs).toEqual(['*']);
});
test('suite file name uses the operationId and feature mode', () => {
expect(jsSuiteFileName(SAMPLE_COLLECTION)).toBe('getWidget/getWidget.feature.test.ts');
});
test('emitter.emit returns one file with generated suite content', async () => {
const emitter = createJsSdkEmitter(undefined);
const files = await emitter.emit(SAMPLE_COLLECTION, {
outDir: '/unused',
suiteName: 'getWidget',
mode: 'feature',
configName: 'test',
emitterConfig: {},
resolveConfigPath: (rel) => rel,
});
expect(files).toHaveLength(1);
expect(files[0].relativePath).toBe('getWidget/getWidget.feature.test.ts');
expect(files[0].content).toContain(
"import { describe, it, expect, beforeEach } from 'vitest';",
);
expect(files[0].content).toContain(
"import type { ApiClient, RestClientError } from '@camunda8/sdk';",
);
});
test('rendered suite substitutes path params and renders extract bindings', () => {
const output = renderJsSuite(SAMPLE_COLLECTION, { mode: 'feature' });
// biome-ignore lint/suspicious/noTemplateCurlyInString: intentional — asserting the emitter produces this exact template-literal string in output
expect(output).toContain("const url1 = `/widgets/${ctx['widgetIdVar'] ?? '{widgetId}'}`;");
expect(output).toContain('expect(response1.status).toBe(200);');
expect(output).toContain("ctx['widgetId'] = response1.data?.data?.id;");
});
});