Skip to content

Commit d49ee5a

Browse files
committed
Add additional unit tests and fixed bugs
1 parent 3d38bc5 commit d49ee5a

14 files changed

Lines changed: 1362 additions & 55 deletions

codify-schemas/package-lock.json

Lines changed: 1197 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

codify-schemas/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
"name": "codify-schemas",
33
"version": "1.0.0",
44
"description": "",
5-
"main": "index.js",
5+
"main": "dist/index.js",
6+
"typings": "dist/index.d.ts",
67
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
8+
"test": "echo \"Error: no test specified\" && exit 1",
9+
"tsc": "tsc"
810
},
911
"keywords": [],
1012
"author": "",

codify-schemas/src/index.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,11 @@ export { default as ConfigFileSchema } from './config-file-schema.json';
22
export { default as ProjectSchema } from './project-schema.json';
33
export { default as ResourceMetaSchema } from './resource-meta-schema.json';
44
export { default as ResourceSchema } from './resource-schema.json';
5-
export { default as IpcMessageSchema } from './ipc-message-schema.json';
5+
export { default as IpcMessageSchema } from './ipc-message-schema.json';
6+
export { default as ApplyRequestDataSchema } from './messages/apply-request-data-schema.json';
7+
export { default as ErrorResponseDataSchema } from './messages/error-response-data-schema.json';
8+
export { default as PlanRequestDataSchema } from './messages/plan-request-data-schema.json';
9+
export { default as PlanResponseDataSchema } from './messages/plan-response-data-schema.json';
10+
export { default as ValidateRequestDataSchema } from './messages/validate-request-data-schema.json';
11+
export { default as ValidateResponseDataSchema } from './messages/validate-response-data-schema.json';
12+
export * from './types';

codify-schemas/src/ipc-message-schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"title": "IPC Message Schema",
55
"type": "object",
66
"properties": {
7-
"msg": {
7+
"cmd": {
88
"description": "The uri for the message. Like an http url",
99
"type": "string"
1010
},
@@ -17,5 +17,5 @@
1717
"description": "The data of the message."
1818
}
1919
},
20-
"required": ["msg", "data"]
21-
}
20+
"required": ["cmd", "data"]
21+
}

codify-schemas/src/ipc-message-schema.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@ describe("Ipc message schema tests", () => {
1212
ajv.compile(schema);
1313
})
1414

15-
it("requires a msg field to be specified", () => {
15+
it("requires a cmd field to be specified", () => {
1616
const validate = ajv.compile(schema);
17-
assert.equal(validate({ msg: "doSomething", data: "data" }), true)
17+
assert.equal(validate({ cmd: "doSomething", data: "data" }), true)
1818
assert.equal(validate({ data: "data" }), false)
1919
})
2020

2121
it("has an optional status field for responses", () => {
2222
const validate = ajv.compile(schema);
23-
assert.equal(validate({ msg: "doSomething", status: "success", data: "data" }), true)
24-
assert.equal(validate({ msg: "doSomething", status: "error", data: "data" }), true)
25-
assert.equal(validate({ msg: "doSomething", status: "other", data: "data" }), false)
26-
assert.equal(validate({ msg: "doSomething", data: "data" }), true)
23+
assert.equal(validate({ cmd: "doSomething", status: "success", data: "data" }), true)
24+
assert.equal(validate({ cmd: "doSomething", status: "error", data: "data" }), true)
25+
assert.equal(validate({ cmd: "doSomething", status: "other", data: "data" }), false)
26+
assert.equal(validate({ cmd: "doSomething", data: "data" }), true)
2727
})
2828

2929
it ("accepts data or null", () => {
3030
const validate = ajv.compile(schema);
31-
assert.equal(validate({ msg: "doSomething", data: "data" }), true)
32-
assert.equal(validate({ msg: "doSomething", data: null }), true)
33-
assert.equal(validate({ msg: "doSomething" }), false)
34-
assert.equal(validate({ msg: "doSomething", data: {} }), true)
31+
assert.equal(validate({ cmd: "doSomething", data: "data" }), true)
32+
assert.equal(validate({ cmd: "doSomething", data: null }), true)
33+
assert.equal(validate({ cmd: "doSomething" }), false)
34+
assert.equal(validate({ cmd: "doSomething", data: {} }), true)
3535
});
3636

37-
});
37+
});

codify-schemas/src/messages/apply-request-data-schema.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
3-
"$id": "https://www.codify.com/plan-response-data-schema.json",
4-
"title": "Plan Response Schema Data",
3+
"$id": "https://www.codify.com/apply-request-data-schema.json",
4+
"title": "Apply Request Schema Data",
55
"description": "Apply the previously generated plan. The plan must already be generated in order for apply to work.",
66
"type": "object",
77
"properties": {
@@ -13,4 +13,4 @@
1313
},
1414
"required": ["planId"],
1515
"additionalProperties": false
16-
}
16+
}

codify-schemas/src/messages/plan-request-data-schema.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
33
"$id": "https://www.codify.com/plan-request-data-schema.json",
44
"title": "Plan Request Schema Data",
5-
"$ref": "../resource-schema.json"
6-
}
5+
"$ref": "resource-schema.json"
6+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import Ajv2020 from "ajv/dist/2020";
2+
import schema from './plan-request-data-schema.json';
3+
import resourceSchema from '../resource-schema.json'
4+
import {it} from "mocha";
5+
import assert from "node:assert";
6+
7+
const ajv = new Ajv2020({
8+
strict: true,
9+
})
10+
ajv.addSchema(resourceSchema);
11+
12+
describe('Plan request data schema', () => {
13+
it('compiles', () => {
14+
ajv.compile(schema);
15+
})
16+
17+
it("requires a type field to be specified", () => {
18+
const validate = ajv.compile(schema);
19+
assert.equal(validate({ type: "type" }), true)
20+
assert.equal(validate({}), false)
21+
})
22+
23+
it ("name and type are alpha-numeric and follow variable naming conventions", () => {
24+
const validate = ajv.compile(schema);
25+
assert.equal(validate({ type: "a234abcDEF_-"}), true)
26+
assert.equal(validate({ type: "234"}), false);
27+
assert.equal(validate({ type: "ABCDEF$"}), false);
28+
29+
assert.equal(validate({ type: "type", name: "a234abcDEF_-"}), true)
30+
assert.equal(validate({ type: "type", name: "234"}), false);
31+
assert.equal(validate({ type: "type", name: "ABCDEF$"}), false);
32+
});
33+
34+
})

codify-schemas/src/messages/validate-request-data-schema.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,15 @@
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
33
"$id": "https://www.codify.com/validate-request-data-schema.json",
44
"title": "Validate Request Schema Data",
5-
"type": "array",
6-
"items": {
7-
"$ref": "../resource-schema.json"
8-
}
9-
}
5+
"type": "object",
6+
"properties": {
7+
"configs": {
8+
"type": "array",
9+
"items": {
10+
"$ref": "resource-schema.json"
11+
}
12+
}
13+
},
14+
"required": [],
15+
"additionalProperties": false
16+
}

codify-schemas/src/messages/validate-response-data-schema.json

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,5 @@
22
"$schema": "https://json-schema.org/draft/2020-12/schema",
33
"$id": "https://www.codify.com/validate-response-data-schema.json",
44
"title": "Validate Response Schema Data",
5-
"type": "object",
6-
"properties": {
7-
"type": {
8-
"description": "The resource type",
9-
"type": "string",
10-
"pattern": "^[a-zA-Z-_][\\w-]+$"
11-
},
12-
"name": {
13-
"description": "Optional name. Useful for specifying multiple resources of the same type",
14-
"type": "string",
15-
"pattern": "^[a-zA-Z-_][\\w-]+$"
16-
},
17-
"dependsOn": {
18-
"type": "array",
19-
"items": {
20-
"type": "string"
21-
},
22-
"uniqueItems": true
23-
}
24-
},
25-
"required": ["type"]
26-
}
5+
"type": "null"
6+
}

0 commit comments

Comments
 (0)