This repository has been archived by the owner on Mar 28, 2023. It is now read-only.
/
schema_spec.js
108 lines (79 loc) · 4.6 KB
/
schema_spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/**
* Copyright 2016 aixigo AG
* Released under the MIT license.
* http://laxarjs.org/license
*/
define( [
'../schema',
'../../utilities/object',
'./spec_data'
], function( schema, object, data ) {
'use strict';
describe( 'schema.transformV3ToV4( schema )', function() {
var v4Schema;
beforeEach( function() {
v4Schema = schema.transformV3ToV4( data.v3Schema );
} );
//////////////////////////////////////////////////////////////////////////////////////////////////
it( 'moves boolean required to required array property of parent schema', function() {
expect( v4Schema.properties.resource.required ).not.toBeDefined();
expect( v4Schema.required ).toContain( 'resource' );
} );
//////////////////////////////////////////////////////////////////////////////////////////////////
it( 'simply removes required combined with a default value', function() {
expect( v4Schema.properties.action.required ).not.toBeDefined();
expect( v4Schema.required ).not.toContain( 'action' );
expect( v4Schema.properties.action.type ).toEqual( 'string' );
} );
//////////////////////////////////////////////////////////////////////////////////////////////////
it( 'adds "null" to the allowed types for non-required fields (LaxarJS interpretation of non-required)', function() {
expect( v4Schema.properties.attribute.type ).toContain( 'string' );
expect( v4Schema.properties.attribute.type ).toContain( 'null' );
} );
//////////////////////////////////////////////////////////////////////////////////////////////////
it( 'treats falsy required attribute as if not set at all (#46)', function() {
expect( v4Schema.properties.reallyNotRequired.required ).not.toBeDefined();
expect( v4Schema.required ).not.toContain( 'reallyNotRequired' );
expect( v4Schema.properties.reallyNotRequired.type ).toContain( 'string' );
expect( v4Schema.properties.reallyNotRequired.type ).toContain( 'null' );
} );
} );
///////////////////////////////////////////////////////////////////////////////////////////////////////////
describe( 'schema.prohibitAdditionalProperties( schema )', function() {
var strictSchema;
var strictNestedSchema;
beforeEach( function() {
// prohibitAdditionalProperties modifies the schema. Hence, to isolate tests, we need to clone.
strictSchema = object.deepClone( data.v4SchemaWithDifferentProperties );
strictNestedSchema = object.deepClone( data.v4SchemaWithNestedProperties );
schema.prohibitAdditionalProperties( strictSchema );
schema.prohibitAdditionalProperties( strictNestedSchema );
} );
////////////////////////////////////////////////////////////////////////////////////////////////////////
it( 'adds additionProperties false where applicable', function() {
expect( strictSchema.additionalProperties ).toBe( false );
expect( strictSchema.properties.simpleProps.additionalProperties ).toBe( false );
expect( strictSchema.properties.patternProps.additionalProperties ).toBe( false );
expect( strictSchema.properties.patternAndSimpleProps.additionalProperties ).toBe( false );
} );
////////////////////////////////////////////////////////////////////////////////////////////////////////
it( 'leaves existing additionalProperties untouched', function() {
expect( strictSchema.properties.propsWithAdditional )
.toEqual( data.v4SchemaWithDifferentProperties.properties.propsWithAdditional );
expect( strictSchema.properties.allTypeOfProps )
.toEqual( data.v4SchemaWithDifferentProperties.properties.allTypeOfProps );
} );
////////////////////////////////////////////////////////////////////////////////////////////////////////
it( 'descends into nested pattern properties', function() {
expect( strictNestedSchema.patternProperties['^y'].additionalProperties ).toBe( false );
} );
////////////////////////////////////////////////////////////////////////////////////////////////////////
it( 'descends into nested additional properties', function() {
expect( strictNestedSchema.additionalProperties.additionalProperties ).toBe( false );
} );
////////////////////////////////////////////////////////////////////////////////////////////////////////
it( 'descends into nested array item specifications', function() {
expect( strictNestedSchema.items.additionalProperties ).toBe( false );
} );
} );
} );