1
+ import 'dart:convert';
2
+
1
3
import 'package:{{ language .params .packageName }}/{{ language .params .packageName }}.dart';
2
4
{% if ' dart' in language .params .packageName %}
3
5
import 'package:test/test.dart';
4
6
{% else %}
5
7
import 'package:flutter_test/flutter_test.dart';
6
8
{% endif %}
7
9
8
- class BasicFilterQueryTest {
10
+ class BasicFilterQueryTest< T > {
9
11
final String description;
10
- final dynamic value;
11
- final String expectedValues;
12
+ final T value;
13
+ final List< T > expectedValues;
12
14
13
15
BasicFilterQueryTest({
14
16
required this.description,
@@ -23,7 +25,7 @@ void main() {
23
25
BasicFilterQueryTest(
24
26
description: 'with a string',
25
27
value: 's',
26
- expectedValues: ["s" ],
28
+ expectedValues: ['s' ],
27
29
),
28
30
BasicFilterQueryTest(
29
31
description: 'with an integer',
@@ -48,14 +50,14 @@ void main() {
48
50
BasicFilterQueryTest(
49
51
description: 'with a list',
50
52
value: ['a', 'b', 'c'],
51
- expectedValues: ["a","b","c" ],
53
+ expectedValues: ['a', 'b', 'c' ],
52
54
),
53
55
];
54
56
55
57
group('equal()', () {
56
58
for (var t in tests) {
57
59
test(t.description, () {
58
- final query = Query.equal('attr', t.value).toJson( );
60
+ final query = jsonDecode( Query.equal('attr', t.value));
59
61
expect(query['attribute'], 'attr');
60
62
expect(query['values'], t.expectedValues);
61
63
expect(query['method'], 'equal');
@@ -66,7 +68,7 @@ void main() {
66
68
group('notEqual()', () {
67
69
for (var t in tests) {
68
70
test(t.description, () {
69
- final query = Query.notEqual('attr', t.value).toJson( );
71
+ final query = jsonDecode( Query.notEqual('attr', t.value));
70
72
expect(query['attribute'], 'attr');
71
73
expect(query['values'], t.expectedValues);
72
74
expect(query['method'], 'notEqual');
@@ -77,7 +79,7 @@ void main() {
77
79
group('lessThan()', () {
78
80
for (var t in tests) {
79
81
test(t.description, () {
80
- final query = Query.lessThan('attr', t.value).toJson( );
82
+ final query = jsonDecode( Query.lessThan('attr', t.value));
81
83
expect(query['attribute'], 'attr');
82
84
expect(query['values'], t.expectedValues);
83
85
expect(query['method'], 'lessThan');
@@ -88,7 +90,7 @@ void main() {
88
90
group('lessThanEqual()', () {
89
91
for (var t in tests) {
90
92
test(t.description, () {
91
- final query = Query.lessThanEqual('attr', t.value).toJson( );
93
+ final query = jsonDecode( Query.lessThanEqual('attr', t.value));
92
94
expect(query['attribute'], 'attr');
93
95
expect(query['values'], t.expectedValues);
94
96
expect(query['method'], 'lessThanEqual');
@@ -99,7 +101,7 @@ void main() {
99
101
group('greaterThan()', () {
100
102
for (var t in tests) {
101
103
test(t.description, () {
102
- final query = Query.greaterThan('attr', t.value).toJson( );
104
+ final query = jsonDecode( Query.greaterThan('attr', t.value));
103
105
expect(query['attribute'], 'attr');
104
106
expect(query['values'], t.expectedValues);
105
107
expect(query['method'], 'greaterThan');
@@ -110,7 +112,7 @@ void main() {
110
112
group('greaterThanEqual()', () {
111
113
for (var t in tests) {
112
114
test(t.description, () {
113
- final query = Query.greaterThanEqual('attr', t.value).toJson( );
115
+ final query = jsonDecode( Query.greaterThanEqual('attr', t.value));
114
116
expect(query['attribute'], 'attr');
115
117
expect(query['values'], t.expectedValues);
116
118
expect(query['method'], 'greaterThanEqual');
@@ -120,172 +122,172 @@ void main() {
120
122
});
121
123
122
124
test('returns search', () {
123
- final query = Query.search('attr', 'keyword1 keyword2').toJson( );
125
+ final query = jsonDecode( Query.search('attr', 'keyword1 keyword2'));
124
126
expect(query['attribute'], 'attr');
125
127
expect(query['values'], ['keyword1 keyword2']);
126
128
expect(query['method'], 'search');
127
129
});
128
130
129
131
test('returns isNull', () {
130
- final query = Query.isNull('attr').toJson( );
132
+ final query = jsonDecode( Query.isNull('attr'));
131
133
expect(query['attribute'], 'attr');
132
134
expect(query['values'], null);
133
135
expect(query['method'], 'isNull');
134
136
});
135
137
136
138
test('returns isNotNull', () {
137
- final query = Query.isNotNull('attr', 'keyword1 keyword2').toJson( );
139
+ final query = jsonDecode( Query.isNotNull('attr') );
138
140
expect(query['attribute'], 'attr');
139
141
expect(query['values'], null);
140
142
expect(query['method'], 'isNotNull');
141
143
});
142
144
143
145
group('between()', () {
144
146
test('with integers', () {
145
- final query = Query.between('attr', 1, 2).toJson( );
147
+ final query = jsonDecode( Query.between('attr', 1, 2));
146
148
expect(query['attribute'], 'attr');
147
149
expect(query['values'], [1, 2]);
148
150
expect(query['method'], 'between');
149
151
});
150
152
151
153
test('with doubles', () {
152
- final query = Query.between('attr', 1.0, 2.0).toJson( );
154
+ final query = jsonDecode( Query.between('attr', 1.0, 2.0));
153
155
expect(query['attribute'], 'attr');
154
156
expect(query['values'], [1.0, 2.0]);
155
157
expect(query['method'], 'between');
156
158
});
157
159
158
160
test('with strings', () {
159
- final query = Query.between('attr', 'a', 'z').toJson( );
161
+ final query = jsonDecode( Query.between('attr', 'a', 'z'));
160
162
expect(query['attribute'], 'attr');
161
163
expect(query['values'], ['a', 'z']);
162
164
expect(query['method'], 'between');
163
165
});
164
166
});
165
167
166
168
test('returns select', () {
167
- final query = Query.select(['attr1', 'attr2']).toJson( );
169
+ final query = jsonDecode( Query.select(['attr1', 'attr2']));
168
170
expect(query['attribute'], null);
169
171
expect(query['values'], ['attr1', 'attr2']);
170
172
expect(query['method'], 'select');
171
173
});
172
174
173
175
test('returns orderAsc', () {
174
- final query = Query.orderAsc('attr').toJson( );
176
+ final query = jsonDecode( Query.orderAsc('attr'));
175
177
expect(query['attribute'], 'attr');
176
178
expect(query['values'], null);
177
179
expect(query['method'], 'orderAsc');
178
180
});
179
181
180
182
test('returns orderDesc', () {
181
- final query = Query.orderDesc('attr').toJson( );
183
+ final query = jsonDecode( Query.orderDesc('attr'));
182
184
expect(query['attribute'], 'attr');
183
185
expect(query['values'], null);
184
186
expect(query['method'], 'orderDesc');
185
187
});
186
188
187
189
test('returns cursorBefore', () {
188
- final query = Query.cursorBefore('custom').toJson( );
190
+ final query = jsonDecode( Query.cursorBefore('custom'));
189
191
expect(query['attribute'], null);
190
192
expect(query['values'], 'custom');
191
193
expect(query['method'], 'cursorBefore');
192
194
});
193
195
194
196
test('returns cursorAfter', () {
195
- final query = Query.cursorAfter('custom').toJson( );
197
+ final query = jsonDecode( Query.cursorAfter('custom'));
196
198
expect(query['attribute'], null);
197
199
expect(query['values'], 'custom');
198
200
expect(query['method'], 'cursorAfter');
199
201
});
200
202
201
203
test('returns limit', () {
202
- final query = Query.limit(1).toJson( );
204
+ final query = jsonDecode( Query.limit(1));
203
205
expect(query['attribute'], null);
204
206
expect(query['values'], 1);
205
207
expect(query['method'], 'limit');
206
208
});
207
209
208
210
test('returns offset', () {
209
- final query = Query.offset(1).toJson( );
211
+ final query = jsonDecode( Query.offset(1));
210
212
expect(query['attribute'], null);
211
213
expect(query['values'], 1);
212
214
expect(query['method'], 'offset');
213
215
});
214
216
215
217
test('returns notContains', () {
216
- final query = Query.notContains('attr', 'value').toJson( );
218
+ final query = jsonDecode( Query.notContains('attr', 'value'));
217
219
expect(query['attribute'], 'attr');
218
220
expect(query['values'], ['value']);
219
221
expect(query['method'], 'notContains');
220
222
});
221
223
222
224
test('returns notSearch', () {
223
- final query = Query.notSearch('attr', 'keyword1 keyword2').toJson( );
225
+ final query = jsonDecode( Query.notSearch('attr', 'keyword1 keyword2'));
224
226
expect(query['attribute'], 'attr');
225
227
expect(query['values'], ['keyword1 keyword2']);
226
228
expect(query['method'], 'notSearch');
227
229
});
228
230
229
231
group('notBetween()', () {
230
232
test('with integers', () {
231
- final query = Query.notBetween('attr', 1, 2).toJson( );
233
+ final query = jsonDecode( Query.notBetween('attr', 1, 2));
232
234
expect(query['attribute'], 'attr');
233
235
expect(query['values'], [1, 2]);
234
236
expect(query['method'], 'notBetween');
235
237
});
236
238
237
239
test('with doubles', () {
238
- final query = Query.notBetween('attr', 1.0, 2.0).toJson( );
240
+ final query = jsonDecode( Query.notBetween('attr', 1.0, 2.0));
239
241
expect(query['attribute'], 'attr');
240
242
expect(query['values'], [1.0, 2.0]);
241
243
expect(query['method'], 'notBetween');
242
244
});
243
245
244
246
test('with strings', () {
245
- final query = Query.notBetween('attr', 'a', 'z').toJson( );
247
+ final query = jsonDecode( Query.notBetween('attr', 'a', 'z'));
246
248
expect(query['attribute'], 'attr');
247
249
expect(query['values'], ['a', 'z']);
248
250
expect(query['method'], 'notBetween');
249
251
});
250
252
});
251
253
252
254
test('returns notStartsWith', () {
253
- final query = Query.notStartsWith('attr', 'prefix').toJson( );
255
+ final query = jsonDecode( Query.notStartsWith('attr', 'prefix'));
254
256
expect(query['attribute'], 'attr');
255
257
expect(query['values'], ['prefix']);
256
258
expect(query['method'], 'notStartsWith');
257
259
});
258
260
259
261
test('returns notEndsWith', () {
260
- final query = Query.notEndsWith('attr', 'suffix').toJson( );
262
+ final query = jsonDecode( Query.notEndsWith('attr', 'suffix'));
261
263
expect(query['attribute'], 'attr');
262
264
expect(query['values'], ['suffix']);
263
265
expect(query['method'], 'notEndsWith');
264
266
});
265
267
266
268
test('returns createdBefore', () {
267
- final query = Query.createdBefore('2023-01-01').toJson( );
269
+ final query = jsonDecode( Query.createdBefore('2023-01-01'));
268
270
expect(query['attribute'], null);
269
271
expect(query['values'], '2023-01-01');
270
272
expect(query['method'], 'createdBefore');
271
273
});
272
274
273
275
test('returns createdAfter', () {
274
- final query = Query.createdAfter('2023-01-01').toJson( );
276
+ final query = jsonDecode( Query.createdAfter('2023-01-01'));
275
277
expect(query['attribute'], null);
276
278
expect(query['values'], '2023-01-01');
277
279
expect(query['method'], 'createdAfter');
278
280
});
279
281
280
282
test('returns updatedBefore', () {
281
- final query = Query.updatedBefore('2023-01-01').toJson( );
283
+ final query = jsonDecode( Query.updatedBefore('2023-01-01'));
282
284
expect(query['attribute'], null);
283
285
expect(query['values'], '2023-01-01');
284
286
expect(query['method'], 'updatedBefore');
285
287
});
286
288
287
289
test('returns updatedAfter', () {
288
- final query = Query.updatedAfter('2023-01-01').toJson( );
290
+ final query = jsonDecode( Query.updatedAfter('2023-01-01'));
289
291
expect(query['attribute'], null);
290
292
expect(query['values'], '2023-01-01');
291
293
expect(query['method'], 'updatedAfter');
0 commit comments