@@ -97,16 +97,90 @@ describe('Connector', () => {
97
97
} ) ;
98
98
99
99
it ( 'should return undefined for non-existing nested property' , ( ) => {
100
- const definition = connector . getPropertyDefinition ( 'MyModel' ,
101
- 'someProp.innerArray.foo' ) ;
100
+ const definition = connector . getPropertyDefinition (
101
+ 'MyModel' ,
102
+ 'someProp.innerArray.foo' ,
103
+ ) ;
102
104
// eslint-disable-next-line no-unused-expressions
103
105
expect ( definition ) . to . be . undefined ;
104
106
} ) ;
105
107
106
108
it ( 'should preserve backward-compatibility for non-existing property' , ( ) => {
107
- const definition = connector . getPropertyDefinition ( 'MyModel' , 'idontexist' ) ;
109
+ const definition = connector . getPropertyDefinition (
110
+ 'MyModel' ,
111
+ 'idontexist' ,
112
+ ) ;
108
113
// eslint-disable-next-line no-unused-expressions
109
114
expect ( definition ) . to . be . undefined ;
110
115
} ) ;
111
116
} ) ;
117
+
118
+ describe ( 'isNullable()' , ( ) => {
119
+ const nullableOverrideFlags = [ 'required' , 'id' ] ;
120
+
121
+ const nullableFlags = [ 'nullable' , 'null' , 'allowNull' ] ;
122
+
123
+ const nullableValues = [ 1 , 'Y' , 'YES' , true ] ;
124
+
125
+ const notNullableValues = [ 0 , 'N' , 'NO' , false ] ;
126
+
127
+ for ( const nullableOverrideFlag of nullableOverrideFlags ) {
128
+ const propDefNullableOverridePlainSlice = {
129
+ [ nullableOverrideFlag ] : true ,
130
+ } ;
131
+ it ( `returns \`false\` for \`${ JSON . stringify (
132
+ propDefNullableOverridePlainSlice ,
133
+ ) } `, ( ) => {
134
+ const result = Connector . prototype . isNullable (
135
+ propDefNullableOverridePlainSlice ,
136
+ ) ;
137
+ // eslint-disable-next-line no-unused-expressions
138
+ expect ( result ) . to . be . false ;
139
+ } ) ;
140
+
141
+ for ( const nullableFlag of nullableFlags ) {
142
+ for ( const nullableValue of nullableValues ) {
143
+ const propDefNullableOverrideSlice = {
144
+ ...propDefNullableOverridePlainSlice ,
145
+ [ nullableFlag ] : nullableValue ,
146
+ } ;
147
+ it ( `returns \`false\` for \`${ JSON . stringify (
148
+ propDefNullableOverrideSlice ,
149
+ ) } `, ( ) => {
150
+ const result = Connector . prototype . isNullable (
151
+ propDefNullableOverrideSlice ,
152
+ ) ;
153
+ // eslint-disable-next-line no-unused-expressions
154
+ expect ( result ) . to . be . false ;
155
+ } ) ;
156
+ }
157
+ }
158
+ }
159
+
160
+ for ( const nullableFlag of nullableFlags ) {
161
+ for ( const nullableValue of nullableValues ) {
162
+ const propDefNullableSlice = { [ nullableFlag ] : nullableValue } ;
163
+ it ( `returns \`true\` for \`${ JSON . stringify (
164
+ propDefNullableSlice ,
165
+ ) } \``, ( ) => {
166
+ const result = Connector . prototype . isNullable ( propDefNullableSlice ) ;
167
+ // eslint-disable-next-line no-unused-expressions
168
+ expect ( result ) . to . be . true ;
169
+ } ) ;
170
+ }
171
+
172
+ for ( const notNullableValue of notNullableValues ) {
173
+ const propDefNotNullableSlice = { [ nullableFlag ] : notNullableValue } ;
174
+ it ( `returns \`false\` for \`${ JSON . stringify (
175
+ propDefNotNullableSlice ,
176
+ ) } \``, ( ) => {
177
+ const result = Connector . prototype . isNullable (
178
+ propDefNotNullableSlice ,
179
+ ) ;
180
+ // eslint-disable-next-line no-unused-expressions
181
+ expect ( result ) . to . be . false ;
182
+ } ) ;
183
+ }
184
+ }
185
+ } ) ;
112
186
} ) ;
0 commit comments