Skip to content

Commit 1e79761

Browse files
alexpmuleclaude
andcommitted
test: add gRPC test coverage
- Add test/apis/grpc-test.proto for gRPC testing - Add 3 new tests for gRPC data model generation - Regular model generation - Compact model generation - Verify gRPC produces WebAPI nodes - All tests passing (22/22) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 00db86c commit 1e79761

2 files changed

Lines changed: 65 additions & 0 deletions

File tree

test/api-generation.test.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,55 @@ describe('API generation', () => {
282282
});
283283
});
284284

285+
describe('gRPC data model generation', () => {
286+
let files;
287+
let opts;
288+
289+
const modelFile = path.join(dest, 'grpc-test.json');
290+
const compactModelFile = path.join(dest, 'grpc-test-compact.json');
291+
292+
beforeEach(() => {
293+
files = new Map();
294+
opts = {
295+
src: srcDir,
296+
dest,
297+
};
298+
});
299+
300+
afterEach(() => fs.remove(dest));
301+
302+
it('Generates data model for regular model', async () => {
303+
files.set('apis/grpc-test.proto', 'GRPC');
304+
await generator(files, opts);
305+
const exists = await fs.pathExists(modelFile);
306+
assert.isTrue(exists, 'model file exists');
307+
const data = await fs.readJson(modelFile);
308+
assertValidAmfModel(data);
309+
});
310+
311+
it('Generates data model for compact model', async () => {
312+
files.set('apis/grpc-test.proto', 'GRPC');
313+
await generator(files, opts);
314+
const exists = await fs.pathExists(compactModelFile);
315+
assert.isTrue(exists, 'model file exists');
316+
const data = await fs.readJson(compactModelFile);
317+
assertValidAmfModel(data);
318+
});
319+
320+
it('Generates data model with grpc string format', async () => {
321+
files.set('apis/grpc-test.proto', 'GRPC');
322+
await generator(files, opts);
323+
const exists = await fs.pathExists(modelFile);
324+
assert.isTrue(exists, 'model file exists');
325+
const data = await fs.readJson(modelFile);
326+
assertValidAmfModel(data);
327+
// Verify it's a gRPC/WebAPI model
328+
const graph = data['@graph'];
329+
const webApi = graph.find(node => node['@type'] && node['@type'].includes('apiContract:WebAPI'));
330+
assert.isDefined(webApi, 'Should contain WebAPI node');
331+
});
332+
});
333+
285334
describe('generator.generate()', () => {
286335
let opts;
287336

test/apis/grpc-test.proto

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
syntax = "proto3";
2+
3+
package test;
4+
5+
service TestService {
6+
rpc GetTest(TestRequest) returns (TestResponse);
7+
}
8+
9+
message TestRequest {
10+
string name = 1;
11+
}
12+
13+
message TestResponse {
14+
string message = 1;
15+
bool success = 2;
16+
}

0 commit comments

Comments
 (0)