Skip to content

Commit

Permalink
feat(tests): automatically download openapi specs on preinstall (#218)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt authored May 6, 2024
1 parent 7822f78 commit 7f71485
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2,635 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"main": "dist/src/index.js",
"typings": "dist/src/index.d.ts",
"scripts": {
"postinstall": "node postinstall/edc-openapi.js",
"transpile": "tsc",
"test": "jest --forceExit"
},
Expand Down
26 changes: 26 additions & 0 deletions postinstall/edc-openapi.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const fs = require('fs/promises');

const folder = "node_modules";

fs.readFile("connector/gradle/libs.versions.toml")
.then(versions => {
const edcRow = versions.toString().split('\n').filter(row => row.startsWith("edc = "))[0];
return edcRow.substring(7, edcRow.length - 1)
})
.then(edcVersion => {
const context = "management-api";
const resourceUrl = `https://eclipse-edc.github.io/Connector/openapi/${context}/${edcVersion}/${context}.yaml`;

return fetch(resourceUrl)
.then(response => {
if (!response.ok) {
throw new Error(`Failed to download ${context} openapi spec`);
}
return response.text()
})
.then(text => text.replaceAll("example: null", ""))
.then(text => fs.writeFile(`${folder}/${context}.yml`, text));
})
.catch(error => {
console.error('Error downloading openapi specs:', error);
})
2 changes: 1 addition & 1 deletion tests/controllers/management-tests/edrs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe("edrs", () => {

beforeAll(async () => {
startedContainer = await new GenericContainer("stoplight/prism:5.8.1")
.withCopyFilesToContainer([{ source: "tests/management-api.yaml", target: "/management-api.yml" }])
.withCopyFilesToContainer([{ source: "node_modules/management-api.yml", target: "/management-api.yml" }])
.withCommand(["mock", "-h", "0.0.0.0", "/management-api.yml"])
.withExposedPorts(4010)
.start();
Expand Down
Loading

0 comments on commit 7f71485

Please sign in to comment.