Skip to content

Commit 00db86c

Browse files
alexpmuleclaude
andcommitted
test: update tests for AMF v5 JSON-LD format
- AMF v5 outputs JSON-LD object with @graph instead of array - Add assertValidAmfModel() helper to validate AMF v5 format - Update all tests to expect @graph property with array of elements - Update flattened tests to expect @context in AMF v5 - All tests passing (19/19) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 7904d11 commit 00db86c

1 file changed

Lines changed: 32 additions & 21 deletions

File tree

test/api-generation.test.js

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ const generator = require('../');
77

88
/** @typedef {import('../types').ApiConfiguration} ApiConfiguration */
99

10+
/**
11+
* Helper to validate AMF v5 JSON-LD output format
12+
* @param {any} data
13+
*/
14+
function assertValidAmfModel(data) {
15+
assert.typeOf(data, 'object', 'data is an object');
16+
assert.property(data, '@graph', 'has @graph property');
17+
assert.typeOf(data['@graph'], 'array', '@graph is an array');
18+
assert.isAbove(data['@graph'].length, 0, '@graph has elements');
19+
}
20+
1021
describe('API generation', () => {
1122
const dest = path.join('test', 'playground');
1223
const srcDir = 'test/';
@@ -34,7 +45,7 @@ describe('API generation', () => {
3445
const exists = await fs.pathExists(modelFile);
3546
assert.isTrue(exists, 'model file exists');
3647
const data = await fs.readJson(modelFile);
37-
assert.typeOf(data, 'array');
48+
assertValidAmfModel(data);
3849
});
3950

4051
it('Generates data model for compact model', async () => {
@@ -43,7 +54,7 @@ describe('API generation', () => {
4354
const exists = await fs.pathExists(compactModelFile);
4455
assert.isTrue(exists, 'model file exists');
4556
const data = await fs.readJson(compactModelFile);
46-
assert.typeOf(data, 'array');
57+
assertValidAmfModel(data);
4758
});
4859

4960
it('generates model with options (Object)', async () => {
@@ -56,7 +67,7 @@ describe('API generation', () => {
5667
const exists = await fs.pathExists(compactModelFile);
5768
assert.isTrue(exists, 'model file exists');
5869
const data = await fs.readJson(compactModelFile);
59-
assert.typeOf(data, 'array');
70+
assertValidAmfModel(data);
6071
});
6172

6273
it('uses default values (Object)', async () => {
@@ -67,7 +78,7 @@ describe('API generation', () => {
6778
const exists = await fs.pathExists(compactModelFile);
6879
assert.isTrue(exists, 'model file exists');
6980
const data = await fs.readJson(compactModelFile);
70-
assert.typeOf(data, 'array');
81+
assertValidAmfModel(data);
7182
});
7283

7384
it('generates model with options (Array)', async () => {
@@ -76,7 +87,7 @@ describe('API generation', () => {
7687
const exists = await fs.pathExists(compactModelFile);
7788
assert.isTrue(exists, 'model file exists');
7889
const data = await fs.readJson(compactModelFile);
79-
assert.typeOf(data, 'array');
90+
assertValidAmfModel(data);
8091
});
8192

8293
it('uses default values (Array)', async () => {
@@ -85,7 +96,7 @@ describe('API generation', () => {
8596
const exists = await fs.pathExists(compactModelFile);
8697
assert.isTrue(exists, 'model file exists');
8798
const data = await fs.readJson(compactModelFile);
88-
assert.typeOf(data, 'array');
99+
assertValidAmfModel(data);
89100
});
90101
});
91102

@@ -111,15 +122,15 @@ describe('API generation', () => {
111122
.then((exists) => assert.isTrue(exists))
112123
.then(() => fs.readJson(modelFile))
113124
.then((data) => {
114-
assert.typeOf(data, 'array');
125+
assertValidAmfModel(data);
115126
}));
116127

117128
it('Generates data model for compact model', () => generator(files, opts)
118129
.then(() => fs.pathExists(compactModelFile))
119130
.then((exists) => assert.isTrue(exists))
120131
.then(() => fs.readJson(compactModelFile))
121132
.then((data) => {
122-
assert.typeOf(data, 'array');
133+
assertValidAmfModel(data);
123134
}));
124135
});
125136

@@ -142,15 +153,15 @@ describe('API generation', () => {
142153
.then((exists) => assert.isTrue(exists))
143154
.then(() => fs.readJson(modelFile))
144155
.then((data) => {
145-
assert.typeOf(data, 'array');
156+
assertValidAmfModel(data);
146157
}));
147158

148159
it('Generates data model for compact model', () => generator(configFile, opts)
149160
.then(() => fs.pathExists(compactModelFile))
150161
.then((exists) => assert.isTrue(exists))
151162
.then(() => fs.readJson(compactModelFile))
152163
.then((data) => {
153-
assert.typeOf(data, 'array');
164+
assertValidAmfModel(data);
154165
}));
155166
});
156167

@@ -168,15 +179,15 @@ describe('API generation', () => {
168179
.then((exists) => assert.isTrue(exists))
169180
.then(() => fs.readJson(modelFile))
170181
.then((data) => {
171-
assert.typeOf(data, 'array');
182+
assertValidAmfModel(data);
172183
}));
173184

174185
it('Generates flattened data model for compact model', () => generator(configFile)
175186
.then(() => fs.pathExists(compactModelFile))
176187
.then((exists) => assert.isTrue(exists))
177188
.then(() => fs.readJson(compactModelFile))
178189
.then((data) => {
179-
assert.typeOf(data, 'array');
190+
assertValidAmfModel(data);
180191
}));
181192

182193
it('Generates flattened data model for regular model', () => generator(configFile)
@@ -187,7 +198,7 @@ describe('API generation', () => {
187198
const graph = data['@graph'];
188199
assert.isDefined(graph);
189200
const ctx = data['@context'];
190-
assert.isUndefined(ctx);
201+
assert.isDefined(ctx, '@context should exist in AMF v5');
191202
}));
192203

193204
it('Generates flattened data model for compact model', () => generator(configFile)
@@ -217,9 +228,9 @@ describe('API generation', () => {
217228
.then((exists) => assert.isTrue(exists))
218229
.then(() => fs.readJson(modelFile))
219230
.then((data) => {
220-
assert.typeOf(data, 'array');
221-
const ctx = data[0]['@context'];
222-
assert.isUndefined(ctx);
231+
assertValidAmfModel(data);
232+
const ctx = data['@context'];
233+
assert.isDefined(ctx, '@context should exist in AMF v5');
223234
}));
224235

225236
it('Generates data model for compact model', () => generator(configFile, {
@@ -229,8 +240,8 @@ describe('API generation', () => {
229240
.then((exists) => assert.isTrue(exists))
230241
.then(() => fs.readJson(compactModelFile))
231242
.then((data) => {
232-
assert.typeOf(data, 'array');
233-
const ctx = data[0]['@context'];
243+
assertValidAmfModel(data);
244+
const ctx = data['@context'];
234245
assert.typeOf(ctx, 'object');
235246
}));
236247
});
@@ -258,7 +269,7 @@ describe('API generation', () => {
258269
const exists = await fs.pathExists(modelFile);
259270
assert.isTrue(exists, 'model file exists');
260271
const data = await fs.readJson(modelFile);
261-
assert.typeOf(data, 'array');
272+
assertValidAmfModel(data);
262273
});
263274

264275
it('Generates data model for compact model', async () => {
@@ -267,7 +278,7 @@ describe('API generation', () => {
267278
const exists = await fs.pathExists(compactModelFile);
268279
assert.isTrue(exists, 'model file exists');
269280
const data = await fs.readJson(compactModelFile);
270-
assert.typeOf(data, 'array');
281+
assertValidAmfModel(data);
271282
});
272283
});
273284

@@ -293,7 +304,7 @@ describe('API generation', () => {
293304
const exists = await fs.pathExists(modelFile);
294305
assert.isTrue(exists, 'model file exists');
295306
const data = await fs.readJson(modelFile);
296-
assert.typeOf(data, 'array');
307+
assertValidAmfModel(data);
297308
});
298309
});
299310
});

0 commit comments

Comments
 (0)