Debian Codegraph @

test/tests/07 - $ref/01 - normalise.js

raw symbols SCIP
1 describe("$ref 01", function () {
2
3 it("normalise - untouched immediate $ref", function () {
4 var schema = {
5 "items": {"$ref": "#"}
6 };
7 tv4.normSchema(schema);
8 assert.propertyVal(schema.items, '$ref', "#");
9 //return schema.items['$ref'] == "#";
10 });
11
12 it("normalise - id as base", function () {
13 var schema = {
14 "id": "baseUrl",
15 "items": {"$ref": "#"}
16 };
17 tv4.normSchema(schema);
18 assert.propertyVal(schema.items, '$ref', "baseUrl#");
19 //return schema.items['$ref'] == "baseUrl#";
20 });
21
22 it("normalise - id relative to parent", function () {
23 var schema = {
24 "id": "http://example.com/schema",
25 "items": {
26 "id": "otherSchema",
27 "items": {
28 "$ref": "#"
29 }
30 }
31 };
32 tv4.normSchema(schema);
33 assert.strictEqual(schema.items.id, "http://example.com/otherSchema", "schema.items.id");
34 assert.strictEqual(schema.items.items['$ref'], "http://example.com/otherSchema#", "$ref");
35 //this.assert(schema.items.id == "http://example.com/otherSchema", "schema.items.id");
36 //this.assert(schema.items.items['$ref'] == "http://example.com/otherSchema#", "$ref");
37 });
38
39 it("normalise - do not touch contents of \"enum\"", function () {
40 var schema = {
41 "id": "http://example.com/schema",
42 "items": {
43 "id": "otherSchema",
44 "enum": [
45 {
46 "$ref": "#"
47 }
48 ]
49 }
50 };
51 tv4.normSchema(schema);
52 assert.strictEqual(schema.items['enum'][0]['$ref'], "#");
53 //this.assert(schema.items['enum'][0]['$ref'] == "#");
54 });
55
56 it("Only normalise id and $ref if they are strings", function () {
57 var schema = {
58 "properties": {
59 "id": {"type": "integer"},
60 "$ref": {"type": "integer"}
61 }
62 };
63 var data = {"id": "test", "$ref": "test"};
64 tv4.normSchema(schema);
65 var valid = tv4.validate(data, schema);
66 assert.isFalse(valid);
67 });
68 });