1
1
const { entity, field, id } = require ( '@herbsjs/gotu' )
2
2
const Repository = require ( '../../../src/repository' )
3
- const assert = require ( 'assert' )
4
- const { RequestTokenHandler } = require ( 'tedious/lib/token/handler' )
3
+ const assert = require ( 'assert' ) . strict
5
4
6
5
describe ( 'Query Find' , ( ) => {
7
6
@@ -75,7 +74,7 @@ describe('Query Find', () => {
75
74
const ret = await itemRepo . find ( )
76
75
77
76
//then
78
- assert . strictEqual ( ret . length , 2 )
77
+ assert . equal ( ret . length , 2 )
79
78
} )
80
79
81
80
it ( 'should return entities with collumn order by' , async ( ) => {
@@ -97,9 +96,9 @@ describe('Query Find', () => {
97
96
const ret = await itemRepo . find ( { orderBy : 'stringTest' } )
98
97
99
98
//then
100
- assert . strictEqual ( ret . length , 2 )
101
- assert . deepStrictEqual ( spy . select , [ 'id' , 'string_test' , 'boolean_test' ] )
102
- assert . deepStrictEqual ( spy . orderBy , 'stringTest' )
99
+ assert . equal ( ret . length , 2 )
100
+ assert . deepEqual ( spy . select , [ 'id' , 'string_test' , 'boolean_test' ] )
101
+ assert . deepEqual ( spy . orderBy , 'stringTest' )
103
102
} )
104
103
105
104
it ( 'should return entities with limit' , async ( ) => {
@@ -121,9 +120,9 @@ describe('Query Find', () => {
121
120
const ret = await itemRepo . find ( { limit : 1 } )
122
121
123
122
//then
124
- assert . strictEqual ( ret . length , 1 )
125
- assert . deepStrictEqual ( spy . select , [ 'id' , 'string_test' , 'boolean_test' ] )
126
- assert . deepStrictEqual ( spy . limit , 1 )
123
+ assert . equal ( ret . length , 1 )
124
+ assert . deepEqual ( spy . select , [ 'id' , 'string_test' , 'boolean_test' ] )
125
+ assert . deepEqual ( spy . limit , 1 )
127
126
} )
128
127
129
128
it ( 'should return all entities when limit is 0' , async ( ) => {
@@ -145,8 +144,8 @@ describe('Query Find', () => {
145
144
const ret = await itemRepo . find ( { limit : 0 } )
146
145
147
146
//then
148
- assert . strictEqual ( ret . length , 2 )
149
- assert . deepStrictEqual ( spy . select , [ 'id' , 'string_test' , 'boolean_test' ] )
147
+ assert . equal ( ret . length , 2 )
148
+ assert . deepEqual ( spy . select , [ 'id' , 'string_test' , 'boolean_test' ] )
150
149
} )
151
150
152
151
it ( 'should return data with offset' , async ( ) => {
@@ -168,9 +167,9 @@ describe('Query Find', () => {
168
167
const ret = await itemRepo . find ( { offset : 10 } )
169
168
170
169
//then
171
- assert . strictEqual ( ret . length , 2 )
172
- assert . deepStrictEqual ( spy . select , [ 'id' , 'string_test' , 'boolean_test' ] )
173
- assert . deepStrictEqual ( spy . offset , 10 )
170
+ assert . equal ( ret . length , 2 )
171
+ assert . deepEqual ( spy . select , [ 'id' , 'string_test' , 'boolean_test' ] )
172
+ assert . deepEqual ( spy . offset , 10 )
174
173
} )
175
174
176
175
it ( 'should return entities with complex order by' , async ( ) => {
@@ -192,9 +191,9 @@ describe('Query Find', () => {
192
191
const ret = await itemRepo . find ( { orderBy : [ { column : 'nome' , order : 'desc' } , 'email' ] } )
193
192
194
193
//then
195
- assert . strictEqual ( ret . length , 2 )
196
- assert . deepStrictEqual ( spy . select , [ 'id' , 'string_test' , 'boolean_test' ] )
197
- assert . deepStrictEqual ( spy . orderBy , [ { column : 'nome' , order : 'desc' } , 'email' ] )
194
+ assert . equal ( ret . length , 2 )
195
+ assert . deepEqual ( spy . select , [ 'id' , 'string_test' , 'boolean_test' ] )
196
+ assert . deepEqual ( spy . orderBy , [ { column : 'nome' , order : 'desc' } , 'email' ] )
198
197
} )
199
198
200
199
it ( 'should return error when order by is a empty object' , async ( ) => {
@@ -217,14 +216,17 @@ describe('Query Find', () => {
217
216
const ret = await itemRepo . find ( { orderBy : { } } )
218
217
} catch ( error ) {
219
218
//then
220
- assert . deepStrictEqual ( error , 'order by is invalid' )
219
+ assert . deepEqual ( error , 'order by is invalid' )
221
220
}
222
221
} )
223
222
} )
224
223
225
224
context ( 'Find with conditions' , ( ) => {
226
225
const givenAnEntity = ( ) => {
227
- const ParentEntity = entity ( 'A Parent Entity' , { } )
226
+ const ParentEntity = entity ( 'A Parent Entity' , {
227
+ id : id ( Number ) ,
228
+ stringTest : field ( String ) ,
229
+ } )
228
230
229
231
return entity ( 'A entity' , {
230
232
id : id ( Number ) ,
@@ -277,13 +279,13 @@ describe('Query Find', () => {
277
279
const ret = await itemRepo . find ( { where : { stringTest : [ "john" ] } } )
278
280
279
281
//then
280
- assert . deepStrictEqual ( ret [ 0 ] . toJSON ( ) , { id : 1 , stringTest : 'john' , booleanTest : true , entityTest : undefined , entitiesTest : undefined } )
281
- assert . deepStrictEqual ( ret [ 1 ] . toJSON ( ) , { id : 2 , stringTest : 'clare' , booleanTest : false , entityTest : undefined , entitiesTest : undefined } )
282
- assert . deepStrictEqual ( spy . select , [ 'id' , 'string_test' , 'boolean_test' ] )
283
- assert . deepStrictEqual ( spy . value , [ "john" ] )
282
+ assert . deepEqual ( ret [ 0 ] . toJSON ( ) , { id : 1 , stringTest : 'john' , booleanTest : true , entityTest : undefined , entitiesTest : undefined } )
283
+ assert . deepEqual ( ret [ 1 ] . toJSON ( ) , { id : 2 , stringTest : 'clare' , booleanTest : false , entityTest : undefined , entitiesTest : undefined } )
284
+ assert . deepEqual ( spy . select , [ 'id' , 'string_test' , 'boolean_test' ] )
285
+ assert . deepEqual ( spy . value , [ "john" ] )
284
286
} )
285
287
286
- it ( 'should return entities using foreing key ' , async ( ) => {
288
+ it ( 'should return entities using foreign keys ' , async ( ) => {
287
289
//given
288
290
let spy = { }
289
291
const retFromDeb = [
@@ -303,11 +305,11 @@ describe('Query Find', () => {
303
305
const ret = await itemRepo . find ( { where : { fkField : 1 } } )
304
306
305
307
//then
306
- assert . deepStrictEqual ( ret [ 0 ] . toJSON ( { allowExtraKeys : true } ) , { id : 1 , stringTest : 'john' , booleanTest : true , entityTest : undefined , entitiesTest : undefined , fkField : "21" } )
307
- assert . deepStrictEqual ( ret [ 1 ] . toJSON ( { allowExtraKeys : true } ) , { id : 2 , stringTest : 'clare' , booleanTest : false , entityTest : undefined , entitiesTest : undefined , fkField : null } )
308
- assert . deepStrictEqual ( spy . select , [ 'id' , 'string_test' , 'boolean_test' , 'fk_field' ] )
309
- assert . deepStrictEqual ( spy . where , 'fk_field' )
310
- assert . deepStrictEqual ( spy . value , [ 1 ] )
308
+ assert . deepEqual ( ret [ 0 ] . toJSON ( { allowExtraKeys : true } ) , { id : 1 , stringTest : 'john' , booleanTest : true , entityTest : undefined , entitiesTest : undefined , fkField : "21" } )
309
+ assert . deepEqual ( ret [ 1 ] . toJSON ( { allowExtraKeys : true } ) , { id : 2 , stringTest : 'clare' , booleanTest : false , entityTest : undefined , entitiesTest : undefined , fkField : null } )
310
+ assert . deepEqual ( spy . select , [ 'id' , 'string_test' , 'boolean_test' , 'fk_field' ] )
311
+ assert . deepEqual ( spy . where , 'fk_field' )
312
+ assert . deepEqual ( spy . value , [ 1 ] )
311
313
} )
312
314
313
315
@@ -331,7 +333,7 @@ describe('Query Find', () => {
331
333
const ret = await itemRepo . find ( { where : "wrong" } )
332
334
} catch ( error ) {
333
335
//then
334
- assert . deepStrictEqual ( error , "condition term is invalid" )
336
+ assert . deepEqual ( error , "condition term is invalid" )
335
337
}
336
338
} )
337
339
@@ -356,7 +358,7 @@ describe('Query Find', () => {
356
358
const ret = await itemRepo . find ( { where : { wrong : { wrong : "wrong" } } } )
357
359
} catch ( error ) {
358
360
//then
359
- assert . deepStrictEqual ( error , "condition value is invalid" )
361
+ assert . deepEqual ( error , "condition value is invalid" )
360
362
}
361
363
} )
362
364
} )
0 commit comments