1
- import { MainModel } from '../test/fixtures/TestModel.js' ;
1
+ import { MainModel } from '../test/fixtures/Models.js' ;
2
+ import { Models } from '../test/fixtures/ModelCollection.js' ;
2
3
import Query from './Query.js' ;
3
- import { TestIndex } from '../test/fixtures/TestIndex.js' ;
4
4
import test from 'ava' ;
5
5
6
6
test ( 'new Query(query) stores the query' , t => {
@@ -9,122 +9,117 @@ test('new Query(query) stores the query', t => {
9
9
t . deepEqual ( query . query , { string : 'test' } ) ;
10
10
} ) ;
11
11
12
- test ( 'Query.execute(index) finds exact matches with primitive types' , t => {
12
+ test ( 'Query.execute(index) finds exact string matches with primitive type' , t => {
13
+ const models = new Models ( ) ;
14
+ const model = models . createFullTestModel ( ) ;
15
+
13
16
const query = new Query ( { string : 'test' } ) ;
14
- const results = query . execute ( MainModel , TestIndex ) ;
15
-
16
- t . deepEqual ( results , [
17
- MainModel . fromData ( {
18
- id : 'MainModel/000000000000' ,
19
- string : 'test' ,
20
- arrayOfString : [ 'test' ] ,
21
- linkedMany : [ {
22
- id : 'LinkedManyModel/000000000000000' ,
23
- string : 'test' ,
24
- } ] ,
25
- } ) ,
26
- ] ) ;
17
+
18
+ const results = query . execute ( MainModel , models . getIndex ( MainModel ) ) ;
19
+
20
+ t . like ( results , [ model . toIndexData ( ) ] ) ;
27
21
} ) ;
28
22
29
- test ( 'Query.execute(index) finds exact matches with $is' , t => {
23
+ test ( 'Query.execute(index) finds exact string matches with $is' , t => {
24
+ const models = new Models ( ) ;
25
+ const model = models . createFullTestModel ( ) ;
26
+ models . createFullTestModel ( { string : 'another test' } ) ;
27
+
30
28
const query = new Query ( { string : { $is : 'test' } } ) ;
31
- const results = query . execute ( MainModel , TestIndex ) ;
32
-
33
- t . deepEqual ( results , [
34
- MainModel . fromData ( {
35
- id : 'MainModel/000000000000' ,
36
- string : 'test' ,
37
- arrayOfString : [ 'test' ] ,
38
- linkedMany : [ {
39
- id : 'LinkedManyModel/000000000000000' ,
40
- string : 'test' ,
41
- } ] ,
42
- } ) ,
43
- ] ) ;
29
+ const results = query . execute ( MainModel , models . getIndex ( MainModel ) ) ;
30
+
31
+ t . like ( results , [ model . toIndexData ( ) ] ) ;
32
+ } ) ;
33
+
34
+ test ( 'Query.execute(index) finds exact boolean matches with primitive type' , t => {
35
+ const models = new Models ( ) ;
36
+ const model = models . createFullTestModel ( ) ;
37
+
38
+ const query = new Query ( { boolean : false } ) ;
39
+ const results = query . execute ( MainModel , models . getIndex ( MainModel ) ) ;
40
+
41
+ t . like ( results , [ model . toIndexData ( ) ] ) ;
42
+ } ) ;
43
+
44
+ test ( 'Query.execute(index) finds exact boolean matches with $is' , t => {
45
+ const models = new Models ( ) ;
46
+ const model = models . createFullTestModel ( ) ;
47
+
48
+ const query = new Query ( { boolean : { $is : false } } ) ;
49
+ const results = query . execute ( MainModel , models . getIndex ( MainModel ) ) ;
50
+
51
+ t . like ( results , [ model . toIndexData ( ) ] ) ;
52
+ } ) ;
53
+
54
+ test ( 'Query.execute(index) finds exact number matches with $is' , t => {
55
+ const models = new Models ( ) ;
56
+ const model = models . createFullTestModel ( ) ;
57
+
58
+ const query = new Query ( { number : { $is : 24.3 } } ) ;
59
+ const results = query . execute ( MainModel , models . getIndex ( MainModel ) ) ;
60
+
61
+ t . like ( results , [ model . toIndexData ( ) ] ) ;
62
+ } ) ;
63
+
64
+ test ( 'Query.execute(index) finds exact number matches with primitive type' , t => {
65
+ const models = new Models ( ) ;
66
+ const model = models . createFullTestModel ( ) ;
67
+
68
+ const query = new Query ( { number : 24.3 } ) ;
69
+ const results = query . execute ( MainModel , models . getIndex ( MainModel ) ) ;
70
+
71
+ t . like ( results , [ model . toIndexData ( ) ] ) ;
44
72
} ) ;
45
73
46
74
test ( 'Query.execute(index) finds matches containing for strings' , t => {
75
+ const models = new Models ( ) ;
76
+ const model1 = models . createFullTestModel ( ) ;
77
+ const model2 = models . createFullTestModel ( ) ;
78
+ models . createFullTestModel ( { string : 'not matching' } ) ;
79
+
80
+ model2 . string = 'testing' ;
81
+
47
82
const query = new Query ( { string : { $contains : 'test' } } ) ;
48
- const results = query . execute ( MainModel , TestIndex ) ;
49
-
50
- t . deepEqual ( results , [
51
- MainModel . fromData ( {
52
- id : 'MainModel/000000000000' ,
53
- string : 'test' ,
54
- arrayOfString : [ 'test' ] ,
55
- linkedMany : [ {
56
- id : 'LinkedManyModel/000000000000000' ,
57
- string : 'test' ,
58
- } ] ,
59
- } ) ,
60
- MainModel . fromData ( {
61
- id : 'MainModel/111111111111' ,
62
- string : 'testing' ,
63
- arrayOfString : [ 'testing' ] ,
64
- linkedMany : [ {
65
- id : 'LinkedManyModel/111111111111' ,
66
- string : 'testing' ,
67
- } ] ,
68
- } ) ,
83
+ const results = query . execute ( MainModel , models . getIndex ( MainModel ) ) ;
84
+
85
+ t . like ( results , [
86
+ model1 . toIndexData ( ) ,
87
+ model2 . toIndexData ( ) ,
69
88
] ) ;
70
89
} ) ;
71
90
72
91
test ( 'Query.execute(index) finds matches containing for arrays' , t => {
92
+ const models = new Models ( ) ;
93
+ const model = models . createFullTestModel ( ) ;
94
+
73
95
const query = new Query ( { arrayOfString : { $contains : 'test' } } ) ;
74
- const results = query . execute ( MainModel , TestIndex ) ;
75
-
76
- t . deepEqual ( results , [
77
- MainModel . fromData ( {
78
- id : 'MainModel/000000000000' ,
79
- string : 'test' ,
80
- arrayOfString : [ 'test' ] ,
81
- linkedMany : [ {
82
- id : 'LinkedManyModel/000000000000000' ,
83
- string : 'test' ,
84
- } ] ,
85
- } ) ,
86
- ] ) ;
96
+ const results = query . execute ( MainModel , models . getIndex ( MainModel ) ) ;
97
+
98
+ t . like ( results , [ model . toIndexData ( ) ] ) ;
87
99
} ) ;
88
100
89
101
test ( 'Query.execute(index) finds exact matches for elements in arrays' , t => {
90
- const query = new Query ( { linkedMany : { $contains : { string : 'test' } } } ) ;
91
- const results = query . execute ( MainModel , TestIndex ) ;
92
-
93
- t . deepEqual ( results , [
94
- MainModel . fromData ( {
95
- id : 'MainModel/000000000000' ,
96
- string : 'test' ,
97
- arrayOfString : [ 'test' ] ,
98
- linkedMany : [ {
99
- id : 'LinkedManyModel/000000000000000' ,
100
- string : 'test' ,
101
- } ] ,
102
- } ) ,
103
- ] ) ;
102
+ const models = new Models ( ) ;
103
+ const model = models . createFullTestModel ( ) ;
104
+
105
+ const query = new Query ( { linkedMany : { $contains : { string : 'many' } } } ) ;
106
+ const results = query . execute ( MainModel , models . getIndex ( MainModel ) ) ;
107
+
108
+ t . like ( results , [ model . toIndexData ( ) ] ) ;
104
109
} ) ;
105
110
106
111
test ( 'Query.execute(index) finds partial matches for elements in arrays' , t => {
107
- const query = new Query ( { linkedMany : { $contains : { string : { $contains : 'test' } } } } ) ;
108
- const results = query . execute ( MainModel , TestIndex ) ;
109
-
110
- t . deepEqual ( results , [
111
- MainModel . fromData ( {
112
- id : 'MainModel/000000000000' ,
113
- string : 'test' ,
114
- arrayOfString : [ 'test' ] ,
115
- linkedMany : [ {
116
- id : 'LinkedManyModel/000000000000000' ,
117
- string : 'test' ,
118
- } ] ,
119
- } ) ,
120
- MainModel . fromData ( {
121
- id : 'MainModel/111111111111' ,
122
- string : 'testing' ,
123
- arrayOfString : [ 'testing' ] ,
124
- linkedMany : [ {
125
- id : 'LinkedManyModel/111111111111' ,
126
- string : 'testing' ,
127
- } ] ,
128
- } ) ,
112
+ const models = new Models ( ) ;
113
+ const model1 = models . createFullTestModel ( ) ;
114
+ const model2 = models . createFullTestModel ( ) ;
115
+
116
+ model2 . linkedMany [ 0 ] . string = 'many tests' ;
117
+
118
+ const query = new Query ( { linkedMany : { $contains : { string : { $contains : 'many' } } } } ) ;
119
+ const results = query . execute ( MainModel , models . getIndex ( MainModel ) ) ;
120
+
121
+ t . like ( results , [
122
+ model1 . toIndexData ( ) ,
123
+ model2 . toIndexData ( ) ,
129
124
] ) ;
130
125
} ) ;
0 commit comments