1
1
import { assert , property } from 'fast-check' ;
2
2
import { $refArbitrary } from '../../../../../utils/__tests__/ref.spec' ;
3
3
import {
4
+ getSerializedIntersectionType ,
4
5
getSerializedObjectType ,
5
6
getSerializedPropertyType ,
6
7
getSerializedRecursiveType ,
7
8
getSerializedRefType ,
9
+ SERIALIZED_STRING_TYPE ,
8
10
} from '../../../common/data/serialized-type' ;
9
11
import { pipe } from 'fp-ts/lib/pipeable' ;
10
12
import { serializeSchemaObject } from '../schema-object' ;
@@ -15,69 +17,153 @@ import { reportIfFailed } from '../../../../../utils/io-ts';
15
17
16
18
describe ( 'SchemaObject serializer' , ( ) => {
17
19
describe ( 'recursive' , ( ) => {
18
- it ( 'level 1' , ( ) => {
19
- assert (
20
- property ( $refArbitrary , ref => {
21
- const schema = SchemaObjectCodec . decode ( {
22
- type : 'object' ,
23
- required : [ 'recursive' ] ,
24
- properties : {
25
- recursive : {
26
- $ref : ref . $ref ,
20
+ describe ( 'properties' , ( ) => {
21
+ it ( 'level 1' , ( ) => {
22
+ assert (
23
+ property ( $refArbitrary , ref => {
24
+ const schema = SchemaObjectCodec . decode ( {
25
+ type : 'object' ,
26
+ required : [ 'recursive' ] ,
27
+ properties : {
28
+ recursive : {
29
+ $ref : ref . $ref ,
30
+ } ,
27
31
} ,
28
- } ,
29
- } ) ;
30
- const expected = pipe (
31
- ref ,
32
- getSerializedRefType ( ref ) ,
33
- getSerializedPropertyType ( 'recursive' , true ) ,
34
- getSerializedObjectType ( ) ,
35
- getSerializedRecursiveType ( ref , true ) ,
36
- ) ;
37
- const serialized = pipe (
38
- schema ,
39
- reportIfFailed ,
40
- either . chain ( schema => serializeSchemaObject ( ref , schema ) ) ,
41
- ) ;
42
- expect ( serialized ) . toEqual ( right ( expected ) ) ;
43
- } ) ,
44
- ) ;
45
- } ) ;
46
- it ( 'level 2' , ( ) => {
47
- assert (
48
- property ( $refArbitrary , ref => {
49
- const schema = SchemaObjectCodec . decode ( {
50
- type : 'object' ,
51
- required : [ 'children' ] ,
52
- properties : {
53
- children : {
54
- type : 'object' ,
55
- required : [ 'recursive' ] ,
56
- properties : {
57
- recursive : {
58
- $ref : ref . $ref ,
32
+ } ) ;
33
+ const expected = pipe (
34
+ ref ,
35
+ getSerializedRefType ( ref ) ,
36
+ getSerializedPropertyType ( 'recursive' , true ) ,
37
+ getSerializedObjectType ( ) ,
38
+ getSerializedRecursiveType ( ref , true ) ,
39
+ ) ;
40
+ const serialized = pipe (
41
+ schema ,
42
+ reportIfFailed ,
43
+ either . chain ( schema => serializeSchemaObject ( ref , schema ) ) ,
44
+ ) ;
45
+ expect ( serialized ) . toEqual ( right ( expected ) ) ;
46
+ } ) ,
47
+ ) ;
48
+ } ) ;
49
+ it ( 'level 2' , ( ) => {
50
+ assert (
51
+ property ( $refArbitrary , ref => {
52
+ const schema = SchemaObjectCodec . decode ( {
53
+ type : 'object' ,
54
+ required : [ 'children' ] ,
55
+ properties : {
56
+ children : {
57
+ type : 'object' ,
58
+ required : [ 'recursive' ] ,
59
+ properties : {
60
+ recursive : {
61
+ $ref : ref . $ref ,
62
+ } ,
59
63
} ,
60
64
} ,
61
65
} ,
62
- } ,
63
- } ) ;
64
- const expected = pipe (
65
- ref ,
66
- getSerializedRefType ( ref ) ,
67
- getSerializedPropertyType ( 'recursive' , true ) ,
68
- getSerializedObjectType ( ) ,
69
- getSerializedPropertyType ( 'children' , true ) ,
70
- getSerializedObjectType ( ) ,
71
- getSerializedRecursiveType ( ref , true ) ,
72
- ) ;
73
- const serialized = pipe (
74
- schema ,
75
- reportIfFailed ,
76
- either . chain ( schema => serializeSchemaObject ( ref , schema ) ) ,
77
- ) ;
78
- expect ( serialized ) . toEqual ( right ( expected ) ) ;
79
- } ) ,
80
- ) ;
66
+ } ) ;
67
+ const expected = pipe (
68
+ ref ,
69
+ getSerializedRefType ( ref ) ,
70
+ getSerializedPropertyType ( 'recursive' , true ) ,
71
+ getSerializedObjectType ( ) ,
72
+ getSerializedPropertyType ( 'children' , true ) ,
73
+ getSerializedObjectType ( ) ,
74
+ getSerializedRecursiveType ( ref , true ) ,
75
+ ) ;
76
+ const serialized = pipe (
77
+ schema ,
78
+ reportIfFailed ,
79
+ either . chain ( schema => serializeSchemaObject ( ref , schema ) ) ,
80
+ ) ;
81
+ expect ( serialized ) . toEqual ( right ( expected ) ) ;
82
+ } ) ,
83
+ ) ;
84
+ } ) ;
85
+ } ) ;
86
+ describe ( 'allOf' , ( ) => {
87
+ it ( 'level 1' , ( ) => {
88
+ assert (
89
+ property ( $refArbitrary , ref => {
90
+ const schema = SchemaObjectCodec . decode ( {
91
+ allOf : [
92
+ {
93
+ type : 'string' ,
94
+ } ,
95
+ {
96
+ type : 'object' ,
97
+ required : [ 'self' ] ,
98
+ properties : {
99
+ self : {
100
+ $ref : ref . $ref ,
101
+ } ,
102
+ } ,
103
+ } ,
104
+ ] ,
105
+ } ) ;
106
+ const serialized = pipe (
107
+ schema ,
108
+ reportIfFailed ,
109
+ either . chain ( schema => serializeSchemaObject ( ref , schema ) ) ,
110
+ ) ;
111
+ const expected = pipe (
112
+ ref ,
113
+ getSerializedRefType ( ref ) ,
114
+ getSerializedPropertyType ( 'self' , true ) ,
115
+ getSerializedObjectType ( ) ,
116
+ serialized => getSerializedIntersectionType ( [ SERIALIZED_STRING_TYPE , serialized ] ) ,
117
+ getSerializedRecursiveType ( ref , true ) ,
118
+ ) ;
119
+ expect ( serialized ) . toEqual ( right ( expected ) ) ;
120
+ } ) ,
121
+ ) ;
122
+ } ) ;
123
+ it ( 'level 2' , ( ) => {
124
+ assert (
125
+ property ( $refArbitrary , ref => {
126
+ const schema = SchemaObjectCodec . decode ( {
127
+ allOf : [
128
+ {
129
+ type : 'string' ,
130
+ } ,
131
+ {
132
+ type : 'object' ,
133
+ required : [ 'nested' ] ,
134
+ properties : {
135
+ nested : {
136
+ type : 'object' ,
137
+ required : [ 'self' ] ,
138
+ properties : {
139
+ self : {
140
+ $ref : ref . $ref ,
141
+ } ,
142
+ } ,
143
+ } ,
144
+ } ,
145
+ } ,
146
+ ] ,
147
+ } ) ;
148
+ const serialized = pipe (
149
+ schema ,
150
+ reportIfFailed ,
151
+ either . chain ( schema => serializeSchemaObject ( ref , schema ) ) ,
152
+ ) ;
153
+ const expected = pipe (
154
+ ref ,
155
+ getSerializedRefType ( ref ) ,
156
+ getSerializedPropertyType ( 'self' , true ) ,
157
+ getSerializedObjectType ( ) ,
158
+ getSerializedPropertyType ( 'nested' , true ) ,
159
+ getSerializedObjectType ( ) ,
160
+ serialized => getSerializedIntersectionType ( [ SERIALIZED_STRING_TYPE , serialized ] ) ,
161
+ getSerializedRecursiveType ( ref , true ) ,
162
+ ) ;
163
+ expect ( serialized ) . toEqual ( right ( expected ) ) ;
164
+ } ) ,
165
+ ) ;
166
+ } ) ;
81
167
} ) ;
82
168
} ) ;
83
169
} ) ;
0 commit comments