Skip to content

Commit

Permalink
fix: fetch v4 fixtures from open-attestation (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
HJunyuan authored Aug 1, 2024
1 parent 4e1feae commit 9b4d2c8
Show file tree
Hide file tree
Showing 16 changed files with 878 additions and 104 deletions.
150 changes: 150 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"lint:fix": "npm run lint -- --fix",
"snyk-protect": "snyk-protect",
"prepare": "npm run snyk-protect",
"generate:v3": "DEBUG=oa-verify* ts-node scripts/generate.v3.ts"
"generate:v3": "DEBUG=oa-verify* ts-node scripts/generate.v3.ts",
"fixtures:v4": "ts-node scripts/fetchFixtures.v4.ts"
},
"author": "",
"license": "Apache-2.0",
Expand Down Expand Up @@ -66,6 +67,7 @@
"prettier": "^2.2.1",
"semantic-release": "^22.0.8",
"ts-jest": "^27.1.5",
"ts-node": "^10.9.2",
"typescript": "^4.9.5"
},
"publishConfig": {
Expand Down
23 changes: 23 additions & 0 deletions scripts/fetchFixtures.v4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import fs from "fs";
import path from "path";

const GITHUB_CONTENTS_PATH = (ref = "beta") =>
`https://api.github.com/repos/Open-Attestation/open-attestation/contents/test/fixtures/v4/__generated__?ref=${ref}`;

const OUTPUT_DIR = path.resolve("./test/fixtures/v4/__generated__");

// make sure the output directory exists
if (fs.existsSync(OUTPUT_DIR)) {
fs.rmSync(OUTPUT_DIR, { recursive: true });
}
fs.mkdirSync(OUTPUT_DIR, { recursive: true });

(async () => {
// GitHub Repository Contents API: https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28#get-repository-content
const fixtures = (await (await fetch(GITHUB_CONTENTS_PATH())).json()) as { name: string; download_url: string }[];

for (const f of fixtures) {
const content = await (await fetch(f.download_url)).json();
fs.writeFileSync(path.join(OUTPUT_DIR, f.name), JSON.stringify(content, null, 2));
}
})();
91 changes: 91 additions & 0 deletions test/fixtures/v4/__generated__/batched-raw-documents-did.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 9b4d2c8

Please sign in to comment.