Skip to content

Commit c1b028e

Browse files
committed
simple pet example/test added
1 parent df3b6c3 commit c1b028e

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

Diff for: test/specs/definitions/pets.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"definitions": {
3+
"pet": {
4+
"type": "object",
5+
"properties": {
6+
"name": { "type": "string" },
7+
"breed": { "type": "string" },
8+
"age": { "type": "string" }
9+
},
10+
"required": ["name", "breed", "age"]
11+
}
12+
},
13+
"type": "object",
14+
"properties": {
15+
"cat": { "$ref": "#/definitions/pet" },
16+
"dog": { "$ref": "#/definitions/pet" }
17+
}
18+
}

Diff for: test/specs/pets.spec.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"use strict";
2+
3+
const {expect} = require("chai");
4+
const {LazyJson} = require("../../dist");
5+
const {FileCache} = require("../../dist/resolver/external");
6+
7+
describe("Pets", () => {
8+
describe("parse", () => {
9+
it("should parse a simple reference", async () => {
10+
FileCache.GLOBAL.reset();
11+
12+
let json = LazyJson.create(__dirname + "/definitions/pets.json");
13+
14+
expect(json.properties.cat).to.deep.equal(json.definitions.pet);
15+
expect(json.properties.dog).to.deep.equal(json.definitions.pet);
16+
expect(json.properties.cat).to.deep.equal(json.properties.dog)
17+
});
18+
19+
});
20+
21+
describe("change", () => {
22+
it("should change all references", async () => {
23+
FileCache.GLOBAL.reset();
24+
25+
let json = LazyJson.create(__dirname + "/definitions/pets.json");
26+
27+
json.definitions.pet.type = "Animal";
28+
29+
expect(json.properties.cat.type).to.equal("Animal");
30+
expect(json.properties.dog.type).to.equal("Animal");
31+
});
32+
33+
it("reference change should change source", async () => {
34+
FileCache.GLOBAL.reset();
35+
36+
let json = LazyJson.create(__dirname + "/definitions/pets.json");
37+
38+
json.properties.cat.required = ["category"];
39+
40+
expect(json.definitions.pet.required).to.deep.equal(["category"]);
41+
expect(json.properties.dog.required).to.deep.equal(["category"]);
42+
});
43+
});
44+
});

0 commit comments

Comments
 (0)