-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: schema json fix: readme typos fix: schema fix chore: add node_modules and dist in .gitignore chore: ignore lint on generated files chore: update package lock file fix: pr edits for date type fix: include lodash dev-dep fix: tests and include oa schema feat: separate file to handle oa and geekout * fix: gitignore squash issue * feat: update postinstall for new combined schema * fix: lint issue * fix: remove extra oa type generation * fix: edit publish script * fix: shift axios to dev dep * fix: readme Co-authored-by: Matthea Loo <[email protected]>
- Loading branch information
Showing
7 changed files
with
223 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/sg/gov/tech/geekout/1.0/geekout-open-attestation-document.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
{ | ||
"recipient": { | ||
"name": "Matthea Loo" | ||
}, | ||
"programme": { | ||
"name": "GeekOut 2020", | ||
"startDate": "2020-10-12", | ||
"endDate": "2020-10-14" | ||
}, | ||
"signatory": { | ||
"name": "Alice", | ||
"position": "Boss", | ||
"organisation": "ABC", | ||
"signature": "signature" | ||
}, | ||
"issuers": [ | ||
{ | ||
"name": "GovTech", | ||
"documentStore": "0x8Fc57204c35fb9317D91285eF52D6b892EC08cD3", | ||
"identityProof": { | ||
"type": "DNS-TXT", | ||
"location": "example.openattestation.com" | ||
} | ||
} | ||
], | ||
"$template": { | ||
"name": "GEEK_OUT_2020", | ||
"type": "EMBEDDED_RENDERER", | ||
"url": "https://stoic-lumiere-531096.netlify.app" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"$id": "https://schemata.openattestation.com/sg/gov/tech/geekout/1.0/geekout-open-attestation", | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"allOf": [ | ||
{ | ||
"$ref": "https://schema.openattestation.com/2.0/schema.json" | ||
}, | ||
{ | ||
"$ref": "https://schemata.openattestation.com/sg/gov/tech/geekout/1.0/schema.json" | ||
} | ||
] | ||
} |
116 changes: 116 additions & 0 deletions
116
src/sg/gov/tech/geekout/1.0/geekout-open-attestation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
import Ajv from "ajv"; | ||
import { cloneDeep, omit } from "lodash"; | ||
import schema from "./geekout-open-attestation.json"; | ||
import sampleDocJson from "./geekout-open-attestation-document.json"; | ||
import axios from "axios"; | ||
|
||
function loadSchema(uri: string) { | ||
return axios.get(uri).then(res => { | ||
return res.data; | ||
}); | ||
} | ||
const ajv = new Ajv({ allErrors: true, loadSchema: loadSchema }); | ||
let validator: Ajv.ValidateFunction; | ||
|
||
describe("schema", () => { | ||
beforeAll(async () => { | ||
validator = await ajv.compileAsync(schema); | ||
}); | ||
it("should work with valid json", () => { | ||
expect(validator(sampleDocJson)).toBe(true); | ||
}); | ||
|
||
//To test if geekout schema is correctly merged | ||
it("should return array of errors without recipient name", () => { | ||
const badDoc = omit(cloneDeep(sampleDocJson), "recipient.name"); | ||
expect(validator(badDoc)).toBe(false); | ||
expect(validator.errors).toStrictEqual([ | ||
{ | ||
keyword: "required", | ||
dataPath: ".recipient", | ||
schemaPath: | ||
"https://schemata.openattestation.com/sg/gov/tech/geekout/1.0/schema.json/properties/recipient/required", | ||
params: { missingProperty: "name" }, | ||
message: "should have required property 'name'" | ||
} | ||
]); | ||
}); | ||
|
||
//To test if oa schema is correctly merged | ||
it("should return array of errors without issuer name", () => { | ||
const badDoc = omit(cloneDeep(sampleDocJson), "issuers[0].name"); | ||
expect(validator(badDoc)).toBe(false); | ||
expect(validator.errors).toStrictEqual([ | ||
{ | ||
keyword: "required", | ||
dataPath: ".issuers[0]", | ||
schemaPath: "#/required", | ||
params: { missingProperty: "name" }, | ||
message: "should have required property 'name'" | ||
}, | ||
{ | ||
keyword: "required", | ||
dataPath: ".issuers[0]", | ||
schemaPath: "#/allOf/1/required", | ||
params: { missingProperty: "tokenRegistry" }, | ||
message: "should have required property 'tokenRegistry'" | ||
}, | ||
{ | ||
keyword: "required", | ||
dataPath: ".issuers[0]", | ||
schemaPath: "#/required", | ||
params: { missingProperty: "name" }, | ||
message: "should have required property 'name'" | ||
}, | ||
{ | ||
keyword: "required", | ||
dataPath: ".issuers[0]", | ||
schemaPath: "#/definitions/certificateStore/required", | ||
params: { missingProperty: "name" }, | ||
message: "should have required property 'name'" | ||
}, | ||
{ | ||
keyword: "required", | ||
dataPath: ".issuers[0]", | ||
schemaPath: "#/definitions/certificateStore/required", | ||
params: { missingProperty: "certificateStore" }, | ||
message: "should have required property 'certificateStore'" | ||
}, | ||
{ | ||
keyword: "required", | ||
dataPath: ".issuers[0]", | ||
schemaPath: "#/required", | ||
params: { missingProperty: "name" }, | ||
message: "should have required property 'name'" | ||
}, | ||
{ | ||
keyword: "required", | ||
dataPath: ".issuers[0]", | ||
schemaPath: "#/allOf/1/required", | ||
params: { missingProperty: "revocationStore" }, | ||
message: "should have required property 'revocationStore'" | ||
}, | ||
{ | ||
keyword: "required", | ||
dataPath: ".issuers[0]", | ||
schemaPath: "#/required", | ||
params: { missingProperty: "name" }, | ||
message: "should have required property 'name'" | ||
}, | ||
{ | ||
keyword: "not", | ||
dataPath: ".issuers[0]", | ||
schemaPath: "#/properties/issuers/items/oneOf/4/allOf/1/not", | ||
params: {}, | ||
message: "should NOT be valid" | ||
}, | ||
{ | ||
keyword: "oneOf", | ||
dataPath: ".issuers[0]", | ||
schemaPath: "#/properties/issuers/items/oneOf", | ||
params: { passingSchemas: null }, | ||
message: "should match exactly one schema in oneOf" | ||
} | ||
]); | ||
}); | ||
}); |