11const expect = require ( 'chai' ) . expect
22const SchemaValidator = require ( '../../src/schema-validator' )
3+ const clone = require ( 'ramda/src/clone' )
34
45describe ( 'validation-error-converter test' , ( ) => {
56
7+ const baseSchema = {
8+ $id : 'http://example.com/schemas/schema.json' ,
9+ type : 'object' ,
10+ additionalProperties : false
11+ }
12+
613 it ( 'type' , ( ) => {
7- const schema = {
8- $id : 'http://example.com/schemas/schema.json' ,
9- type : 'object' ,
10- properties : {
11- typeError : {
12- type : 'object'
13- }
14+ const schema = clone ( baseSchema )
15+ schema . properties = {
16+ typeError : {
17+ type : 'object'
1418 }
1519 }
20+
1621 const schemaValidator = new SchemaValidator ( schema . $id , [ schema ] )
1722
1823 const result = schemaValidator . validate . bind ( schemaValidator , { typeError : 'invalid-type' } )
@@ -24,14 +29,10 @@ describe('validation-error-converter test', () => {
2429 } )
2530
2631 it ( 'additionalProperties' , ( ) => {
27- const schema = {
28- $id : 'http://example.com/schemas/schema.json' ,
29- type : 'object' ,
30- additionalProperties : false ,
31- properties : {
32- valid : {
33- type : 'string'
34- }
32+ const schema = clone ( baseSchema )
33+ schema . properties = {
34+ valid : {
35+ type : 'string'
3536 }
3637 }
3738 const schemaValidator = new SchemaValidator ( schema . $id , [ schema ] )
@@ -44,18 +45,14 @@ describe('validation-error-converter test', () => {
4445 } )
4546
4647 it ( 'required' , ( ) => {
47- const schema = {
48- $id : 'http://example.com/schemas/schema.json' ,
49- type : 'object' ,
50- additionalProperties : false ,
51- properties : {
52- requiredError : {
53- type : 'object' ,
54- required : [ 'requiredProperty' ] ,
55- properties : {
56- requiredProperty : {
57- type : 'string'
58- }
48+ const schema = clone ( baseSchema )
49+ schema . properties = {
50+ requiredError : {
51+ type : 'object' ,
52+ required : [ 'requiredProperty' ] ,
53+ properties : {
54+ requiredProperty : {
55+ type : 'string'
5956 }
6057 }
6158 }
@@ -70,14 +67,11 @@ describe('validation-error-converter test', () => {
7067 } )
7168
7269 it ( 'const' , ( ) => {
73- const schema = {
74- $id : 'http://example.com/schemas/schema.json' ,
75- type : 'object' ,
76- properties : {
77- constError : {
78- type : 'string' ,
79- const : 'valid_value'
80- }
70+ const schema = clone ( baseSchema )
71+ schema . properties = {
72+ constError : {
73+ type : 'string' ,
74+ const : 'valid_value'
8175 }
8276 }
8377 const schemaValidator = new SchemaValidator ( schema . $id , [ schema ] )
@@ -91,18 +85,15 @@ describe('validation-error-converter test', () => {
9185 } )
9286
9387 it ( 'enum - values' , ( ) => {
94- const schema = {
95- $id : 'http://example.com/schemas/schema.json' ,
96- type : 'object' ,
97- properties : {
98- enumError : {
99- type : 'string' ,
100- enum : [
101- 'valid-1' ,
102- 'valid-2' ,
103- 'valid-3'
104- ]
105- }
88+ const schema = clone ( baseSchema )
89+ schema . properties = {
90+ enumError : {
91+ type : 'string' ,
92+ enum : [
93+ 'valid-1' ,
94+ 'valid-2' ,
95+ 'valid-3'
96+ ]
10697 }
10798 }
10899 const schemaValidator = new SchemaValidator ( schema . $id , [ schema ] )
@@ -116,17 +107,13 @@ describe('validation-error-converter test', () => {
116107 } )
117108
118109 it ( 'enum - properties' , ( ) => {
119- const schema = {
120- $id : 'http://example.com/schemas/schema.json' ,
121- type : 'object' ,
122- additionalProperties : false ,
123- propertyNames : {
124- enum : [
125- 'valid-prop-1' ,
126- 'valid-prop-2' ,
127- 'valid-prop-3'
128- ]
129- }
110+ const schema = clone ( baseSchema )
111+ schema . propertyNames = {
112+ enum : [
113+ 'valid-prop-1' ,
114+ 'valid-prop-2' ,
115+ 'valid-prop-3'
116+ ]
130117 }
131118 const schemaValidator = new SchemaValidator ( schema . $id , [ schema ] )
132119
@@ -138,14 +125,11 @@ describe('validation-error-converter test', () => {
138125 } )
139126
140127 it ( 'format URL' , ( ) => {
141- const schema = {
142- $id : 'http://example.com/schemas/schema.json' ,
143- type : 'object' ,
144- properties : {
145- formatError : {
146- type : 'string' ,
147- format : 'httpUrl'
148- }
128+ const schema = clone ( baseSchema )
129+ schema . properties = {
130+ formatError : {
131+ type : 'string' ,
132+ format : 'httpUrl'
149133 }
150134 }
151135 const schemaValidator = new SchemaValidator ( schema . $id , [ schema ] )
@@ -159,14 +143,11 @@ describe('validation-error-converter test', () => {
159143 } )
160144
161145 it ( 'format other' , ( ) => {
162- const schema = {
163- $id : 'http://example.com/schemas/schema.json' ,
164- type : 'object' ,
165- properties : {
166- formatError : {
167- type : 'string' ,
168- format : 'email'
169- }
146+ const schema = clone ( baseSchema )
147+ schema . properties = {
148+ formatError : {
149+ type : 'string' ,
150+ format : 'email'
170151 }
171152 }
172153 const schemaValidator = new SchemaValidator ( schema . $id , [ schema ] )
0 commit comments