Skip to content

Commit

Permalink
feat(doorkeeper): ✨ add new check method to doorkeeper (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
cjimenezsaiz authored Jun 6, 2023
1 parent 7b97c9b commit 972f636
Show file tree
Hide file tree
Showing 3 changed files with 264 additions and 163 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"service-config",
"openc2",
"app-wrapper",
"ci"
"ci",
"doorkeeper"
],

}
68 changes: 68 additions & 0 deletions packages/api/doorkeeper/src/Doorkeeper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,77 @@ describe('#DoorKeeper #package', () => {
});
it(`Should resolve a correct JSON object when try to validate a schema that is in the scope and is CORRECT`, async () => {
await expect(dk.validate('Config.Artifact', artifact, v4())).resolves.toBe(artifact);
await expect(dk.validate('Config.Artifact', artifact)).resolves.toBe(artifact);
});
it(`Should invoke the callback a correct JSON object when try to validate a schema that is in the scope and is CORRECT`, done => {
dk.validate('Config.Artifact', artifact, (error, result) => {
expect(error).toBeUndefined();
expect(result).toEqual(artifact);
done();
});
});
it(`Should invoke the callback a correct JSON object when try to validate a schema that is in the scope and is CORRECT using external uuid`, done => {
dk.validate('Config.Artifact', artifact, v4(), (error, result) => {
expect(error).toBeUndefined();
expect(result).toEqual(artifact);
done();
});
});
it(`Should invoke the callback with an error when try to validate a schema that is in the scope and is INCORRECT`, done => {
dk.validate('Config.Artifact', {}, (error, result) => {
expect(error).toBeInstanceOf(Multi);
expect((error as Multi).message).toEqual('Errors during the schema validation process');
expect((error as Multi).name).toEqual('ValidationError');
expect((error as Multi).causes).toBeDefined();
const causes = (error as Multi).causes as Crash[];
for (const cause of causes) {
expect(cause).toBeInstanceOf(Crash);
expect(cause.name).toEqual('ValidationError');
}
const trace = (error as Multi).trace();
expect(trace).toEqual([
"ValidationError: must have required property 'id'",
"ValidationError: must have required property 'processId'",
"ValidationError: must have required property 'release'",
"ValidationError: must have required property 'version'",
]);
expect(result).toEqual({});
done();
});
});
it(`Should invoke the callback with an error when try to validate a schema that is in the scope and is INCORRECT using external uuid`, done => {
dk.validate('Config.Artifact', {}, v4(), (error, result) => {
expect(error).toBeInstanceOf(Multi);
expect((error as Multi).message).toEqual('Errors during the schema validation process');
expect((error as Multi).name).toEqual('ValidationError');
expect((error as Multi).causes).toBeDefined();
const causes = (error as Multi).causes as Crash[];
for (const cause of causes) {
expect(cause).toBeInstanceOf(Crash);
expect(cause.name).toEqual('ValidationError');
}
const trace = (error as Multi).trace();
expect(trace).toEqual([
"ValidationError: must have required property 'id'",
"ValidationError: must have required property 'processId'",
"ValidationError: must have required property 'release'",
"ValidationError: must have required property 'version'",
]);
expect(result).toEqual({});
done();
});
});
it(`Should resolve a correct JSON object when attempt to validate a schema that is in the scope and is CORRECT`, () => {
expect(dk.attempt('Config.Artifact', artifact, v4())).toBe(artifact);
expect(dk.attempt('Config.Artifact', artifact)).toBe(artifact);
});
it(`Should return a TRUE value when try to check a schema that is in the scope and is CORRECT`, () => {
expect(dk.check('Config.Artifact', artifact)).toBeTruthy();
expect(dk.check('Config.Artifact', artifact, v4())).toBeTruthy();
});
it(`Should return a FALSE value when try to check a schema that is in the scope and is INCORRECT`, () => {
expect(dk.check('Config.Artifact', {})).toBeFalsy();
expect(dk.check('Config.Artifact', {}, v4())).toBeFalsy();
});
});
describe('#Sad path', () => {
Expand Down
Loading

0 comments on commit 972f636

Please sign in to comment.