Skip to content

Commit 57e845f

Browse files
test: convert AppDirectory test to Jest and run in CI
Converts the standalone app-directory specification test into a proper Jest test that runs as part of CI. Changes: - Added test/AppDirectory.test.ts with tests for: - Valid API name and version - myApplication.json example validation - fdc3-workbench.json example validation - Added @apidevtools/swagger-parser and jsonschema to devDependencies - Removed src/app-directory/specification/test/ directory Closes #1716
1 parent 92016b2 commit 57e845f

5 files changed

Lines changed: 52 additions & 326 deletions

File tree

packages/fdc3-standard/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@finos/fdc3-schema": "2.2.0"
3939
},
4040
"devDependencies": {
41+
"@apidevtools/swagger-parser": "^10.1.1",
4142
"@eslint/eslintrc": "^3.2.0",
4243
"@eslint/js": "^9.19.0",
4344
"@types/jest": "29.5.13",
@@ -52,6 +53,7 @@
5253
"jest-environment-jsdom": "29.7.0",
5354
"jest-junit": "^16.0.0",
5455
"jest-mock-extended": "3.0.5",
56+
"jsonschema": "^1.4.0",
5557
"prettier": "3.4.1",
5658
"quicktype": "23.0.78",
5759
"rimraf": "^6.0.1",

packages/fdc3-standard/src/app-directory/specification/test/index.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

packages/fdc3-standard/src/app-directory/specification/test/package-lock.json

Lines changed: 0 additions & 250 deletions
This file was deleted.

packages/fdc3-standard/src/app-directory/specification/test/package.json

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import SwaggerParser from '@apidevtools/swagger-parser';
2+
import { Validator } from 'jsonschema';
3+
import { readFileSync } from 'fs';
4+
import { join } from 'path';
5+
6+
// Get the directory path for loading schema and example files
7+
const specificationDir = join(__dirname, '..', 'src', 'app-directory', 'specification');
8+
9+
describe('App Directory Schema Validation', () => {
10+
let api: unknown;
11+
let applicationSchema: unknown;
12+
let validator: Validator;
13+
14+
beforeAll(async () => {
15+
// Parse and validate the OpenAPI schema
16+
api = await SwaggerParser.validate(join(specificationDir, 'appd.schema.json'));
17+
applicationSchema = (api as { components: { schemas: { Application: unknown } } }).components.schemas.Application;
18+
validator = new Validator();
19+
});
20+
21+
it('should have valid API name and version', () => {
22+
const apiInfo = (api as { info: { title: string; version: string } }).info;
23+
expect(apiInfo.title).toBeDefined();
24+
expect(apiInfo.version).toBeDefined();
25+
});
26+
27+
it('should validate myApplication.json example against the Application schema', () => {
28+
const examplePath = join(specificationDir, 'examples', 'application', 'myApplication.json');
29+
const exampleApplication = JSON.parse(readFileSync(examplePath, 'utf-8'));
30+
31+
const result = validator.validate(exampleApplication, applicationSchema);
32+
33+
expect(result.valid).toBe(true);
34+
if (!result.valid) {
35+
console.error('Validation errors:', result.errors);
36+
}
37+
});
38+
39+
it('should validate fdc3-workbench.json example against the Application schema', () => {
40+
const examplePath = join(specificationDir, 'examples', 'application', 'fdc3-workbench.json');
41+
const exampleApplication = JSON.parse(readFileSync(examplePath, 'utf-8'));
42+
43+
const result = validator.validate(exampleApplication, applicationSchema);
44+
45+
expect(result.valid).toBe(true);
46+
if (!result.valid) {
47+
console.error('Validation errors:', result.errors);
48+
}
49+
});
50+
});

0 commit comments

Comments
 (0)