@e22m4u/js-repository 0.0.32 → 0.0.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/adapter/adapter-loader.js +1 -1
- package/src/adapter/adapter-loader.spec.js +1 -1
- package/src/adapter/adapter.d.ts +11 -7
- package/src/adapter/builtin/memory-adapter.d.ts +11 -7
- package/src/adapter/decorator/data-sanitizing-decorator.js +1 -1
- package/src/adapter/decorator/data-validation-decorator.js +1 -1
- package/src/adapter/decorator/default-values-decorator.js +1 -1
- package/src/adapter/decorator/fields-filtering-decorator.js +1 -1
- package/src/adapter/decorator/inclusion-decorator.js +1 -1
- package/src/definition/model/model-data-sanitizer.js +2 -2
- package/src/definition/model/model-data-validator.js +1 -1
- package/src/definition/model/model-data-validator.spec.js +1 -1
- package/src/definition/model/model-definition-utils.js +1 -1
- package/src/definition/model/model-definition-utils.spec.js +1 -1
- package/src/filter/fields-clause-tool.d.ts +4 -4
- package/src/filter/fields-clause-tool.js +32 -21
- package/src/filter/fields-clause-tool.spec.js +479 -100
- package/src/filter/{filter.d.ts → filter-clause.d.ts} +10 -10
- package/src/filter/include-clause-tool.d.ts +7 -5
- package/src/filter/index.d.ts +1 -1
- package/src/filter/operator-clause-tool.js +1 -1
- package/src/filter/operator-clause-tool.spec.js +1 -1
- package/src/filter/order-clause-tool.d.ts +1 -1
- package/src/filter/order-clause-tool.js +20 -17
- package/src/filter/order-clause-tool.spec.js +621 -362
- package/src/filter/slice-clause-tool.js +1 -1
- package/src/filter/where-clause-tool.d.ts +1 -1
- package/src/relations/belongs-to-resolver.d.ts +3 -3
- package/src/relations/has-many-resolver.d.ts +4 -4
- package/src/relations/has-one-resolver.d.ts +4 -4
- package/src/relations/references-many-resolver.d.ts +2 -2
- package/src/repository/repository.d.ts +9 -9
|
@@ -6,10 +6,10 @@ const S = new OrderClauseTool();
|
|
|
6
6
|
|
|
7
7
|
describe('OrderClauseTool', function () {
|
|
8
8
|
describe('sort', function () {
|
|
9
|
-
describe('
|
|
10
|
-
it('
|
|
11
|
-
const objects = [{foo:
|
|
12
|
-
S.sort(objects, '
|
|
9
|
+
describe('single field', function () {
|
|
10
|
+
it('does not throw an error if the given field is not exist', function () {
|
|
11
|
+
const objects = [{foo: 1}, {foo: 2}, {foo: 3}, {foo: 4}];
|
|
12
|
+
S.sort(objects, 'bar');
|
|
13
13
|
expect(objects).to.have.length(4);
|
|
14
14
|
expect(objects[0].foo).to.be.eq(1);
|
|
15
15
|
expect(objects[1].foo).to.be.eq(2);
|
|
@@ -17,19 +17,75 @@ describe('OrderClauseTool', function () {
|
|
|
17
17
|
expect(objects[3].foo).to.be.eq(4);
|
|
18
18
|
});
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
describe('with number values', function () {
|
|
21
|
+
it('orders in ascending by default', function () {
|
|
22
|
+
const objects = [{foo: 2}, {foo: 3}, {foo: 1}, {foo: 4}];
|
|
23
|
+
S.sort(objects, 'foo');
|
|
24
|
+
expect(objects).to.have.length(4);
|
|
25
|
+
expect(objects[0].foo).to.be.eq(1);
|
|
26
|
+
expect(objects[1].foo).to.be.eq(2);
|
|
27
|
+
expect(objects[2].foo).to.be.eq(3);
|
|
28
|
+
expect(objects[3].foo).to.be.eq(4);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('orders in descending', function () {
|
|
32
|
+
const objects = [{foo: 2}, {foo: 3}, {foo: 1}, {foo: 4}];
|
|
33
|
+
S.sort(objects, 'foo DESC');
|
|
34
|
+
expect(objects).to.have.length(4);
|
|
35
|
+
expect(objects[0].foo).to.be.eq(4);
|
|
36
|
+
expect(objects[1].foo).to.be.eq(3);
|
|
37
|
+
expect(objects[2].foo).to.be.eq(2);
|
|
38
|
+
expect(objects[3].foo).to.be.eq(1);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('orders in ascending', function () {
|
|
42
|
+
const objects = [{foo: 2}, {foo: 3}, {foo: 1}, {foo: 4}];
|
|
43
|
+
S.sort(objects, 'foo ASC');
|
|
44
|
+
expect(objects).to.have.length(4);
|
|
45
|
+
expect(objects[0].foo).to.be.eq(1);
|
|
46
|
+
expect(objects[1].foo).to.be.eq(2);
|
|
47
|
+
expect(objects[2].foo).to.be.eq(3);
|
|
48
|
+
expect(objects[3].foo).to.be.eq(4);
|
|
49
|
+
});
|
|
28
50
|
});
|
|
29
51
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
52
|
+
describe('with string values', function () {
|
|
53
|
+
it('orders in ascending by default', function () {
|
|
54
|
+
const objects = [{foo: 'b'}, {foo: 'c'}, {foo: 'a'}, {foo: 'd'}];
|
|
55
|
+
S.sort(objects, 'foo');
|
|
56
|
+
expect(objects).to.have.length(4);
|
|
57
|
+
expect(objects[0].foo).to.be.eq('a');
|
|
58
|
+
expect(objects[1].foo).to.be.eq('b');
|
|
59
|
+
expect(objects[2].foo).to.be.eq('c');
|
|
60
|
+
expect(objects[3].foo).to.be.eq('d');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('orders in descending', function () {
|
|
64
|
+
const objects = [{foo: 'b'}, {foo: 'c'}, {foo: 'a'}, {foo: 'd'}];
|
|
65
|
+
S.sort(objects, 'foo DESC');
|
|
66
|
+
expect(objects).to.have.length(4);
|
|
67
|
+
expect(objects[0].foo).to.be.eq('d');
|
|
68
|
+
expect(objects[1].foo).to.be.eq('c');
|
|
69
|
+
expect(objects[2].foo).to.be.eq('b');
|
|
70
|
+
expect(objects[3].foo).to.be.eq('a');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('orders in ascending', function () {
|
|
74
|
+
const objects = [{foo: 'b'}, {foo: 'c'}, {foo: 'a'}, {foo: 'd'}];
|
|
75
|
+
S.sort(objects, 'foo ASC');
|
|
76
|
+
expect(objects).to.have.length(4);
|
|
77
|
+
expect(objects[0].foo).to.be.eq('a');
|
|
78
|
+
expect(objects[1].foo).to.be.eq('b');
|
|
79
|
+
expect(objects[2].foo).to.be.eq('c');
|
|
80
|
+
expect(objects[3].foo).to.be.eq('d');
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('multiple fields', function () {
|
|
86
|
+
it('does not throw an error if multiple fields are not exist', function () {
|
|
87
|
+
const objects = [{foo: 1}, {foo: 2}, {foo: 3}, {foo: 4}];
|
|
88
|
+
S.sort(objects, ['bar', 'baz']);
|
|
33
89
|
expect(objects).to.have.length(4);
|
|
34
90
|
expect(objects[0].foo).to.be.eq(1);
|
|
35
91
|
expect(objects[1].foo).to.be.eq(2);
|
|
@@ -37,402 +93,605 @@ describe('OrderClauseTool', function () {
|
|
|
37
93
|
expect(objects[3].foo).to.be.eq(4);
|
|
38
94
|
});
|
|
39
95
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
96
|
+
describe('with number values', function () {
|
|
97
|
+
it('orders in ascending by default', function () {
|
|
98
|
+
const objects = [
|
|
99
|
+
{foo: 2, bar: 2},
|
|
100
|
+
{foo: 2, bar: 3},
|
|
101
|
+
{foo: 2, bar: 1},
|
|
102
|
+
{foo: 1, bar: 4},
|
|
103
|
+
];
|
|
104
|
+
S.sort(objects, ['foo', 'bar']);
|
|
105
|
+
expect(objects).to.have.length(4);
|
|
106
|
+
expect(objects[0].bar).to.be.eq(4);
|
|
107
|
+
expect(objects[1].bar).to.be.eq(1);
|
|
108
|
+
expect(objects[2].bar).to.be.eq(2);
|
|
109
|
+
expect(objects[3].bar).to.be.eq(3);
|
|
110
|
+
});
|
|
54
111
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
112
|
+
it('orders in descending', function () {
|
|
113
|
+
const objects = [
|
|
114
|
+
{foo: 2, bar: 2},
|
|
115
|
+
{foo: 2, bar: 3},
|
|
116
|
+
{foo: 2, bar: 1},
|
|
117
|
+
{foo: 1, bar: 4},
|
|
118
|
+
];
|
|
119
|
+
S.sort(objects, ['foo DESC', 'bar DESC']);
|
|
120
|
+
expect(objects).to.have.length(4);
|
|
121
|
+
expect(objects[0].bar).to.be.eq(3);
|
|
122
|
+
expect(objects[1].bar).to.be.eq(2);
|
|
123
|
+
expect(objects[2].bar).to.be.eq(1);
|
|
124
|
+
expect(objects[3].bar).to.be.eq(4);
|
|
125
|
+
});
|
|
69
126
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
127
|
+
it('orders in ascending', function () {
|
|
128
|
+
const objects = [
|
|
129
|
+
{foo: 2, bar: 2},
|
|
130
|
+
{foo: 2, bar: 3},
|
|
131
|
+
{foo: 2, bar: 1},
|
|
132
|
+
{foo: 1, bar: 4},
|
|
133
|
+
];
|
|
134
|
+
S.sort(objects, ['foo ASC', 'bar ASC']);
|
|
135
|
+
expect(objects).to.have.length(4);
|
|
136
|
+
expect(objects[0].bar).to.be.eq(4);
|
|
137
|
+
expect(objects[1].bar).to.be.eq(1);
|
|
138
|
+
expect(objects[2].bar).to.be.eq(2);
|
|
139
|
+
expect(objects[3].bar).to.be.eq(3);
|
|
140
|
+
});
|
|
84
141
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
142
|
+
it('orders with mixed directions', function () {
|
|
143
|
+
const objects = [
|
|
144
|
+
{foo: 2, bar: 2},
|
|
145
|
+
{foo: 2, bar: 4},
|
|
146
|
+
{foo: 2, bar: 1},
|
|
147
|
+
{foo: 1, bar: 3},
|
|
148
|
+
];
|
|
149
|
+
S.sort(objects, ['foo DESC', 'bar ASC']);
|
|
150
|
+
expect(objects).to.have.length(4);
|
|
151
|
+
expect(objects[0].bar).to.be.eq(1);
|
|
152
|
+
expect(objects[1].bar).to.be.eq(2);
|
|
153
|
+
expect(objects[2].bar).to.be.eq(4);
|
|
154
|
+
expect(objects[3].bar).to.be.eq(3);
|
|
155
|
+
});
|
|
98
156
|
});
|
|
99
157
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
158
|
+
describe('with string values', function () {
|
|
159
|
+
it('orders in ascending by default', function () {
|
|
160
|
+
const objects = [
|
|
161
|
+
{foo: 'b', bar: 'b'},
|
|
162
|
+
{foo: 'b', bar: 'c'},
|
|
163
|
+
{foo: 'b', bar: 'a'},
|
|
164
|
+
{foo: 'a', bar: 'd'},
|
|
165
|
+
];
|
|
166
|
+
S.sort(objects, ['foo', 'bar']);
|
|
167
|
+
expect(objects).to.have.length(4);
|
|
168
|
+
expect(objects[0].bar).to.be.eq('d');
|
|
169
|
+
expect(objects[1].bar).to.be.eq('a');
|
|
170
|
+
expect(objects[2].bar).to.be.eq('b');
|
|
171
|
+
expect(objects[3].bar).to.be.eq('c');
|
|
172
|
+
});
|
|
114
173
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
174
|
+
it('orders in descending', function () {
|
|
175
|
+
const objects = [
|
|
176
|
+
{foo: 'b', bar: 'b'},
|
|
177
|
+
{foo: 'b', bar: 'c'},
|
|
178
|
+
{foo: 'b', bar: 'a'},
|
|
179
|
+
{foo: 'a', bar: 'd'},
|
|
180
|
+
];
|
|
181
|
+
S.sort(objects, ['foo DESC', 'bar DESC']);
|
|
182
|
+
expect(objects).to.have.length(4);
|
|
183
|
+
expect(objects[0].bar).to.be.eq('c');
|
|
184
|
+
expect(objects[1].bar).to.be.eq('b');
|
|
185
|
+
expect(objects[2].bar).to.be.eq('a');
|
|
186
|
+
expect(objects[3].bar).to.be.eq('d');
|
|
187
|
+
});
|
|
129
188
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
});
|
|
189
|
+
it('orders in ascending', function () {
|
|
190
|
+
const objects = [
|
|
191
|
+
{foo: 'b', bar: 'b'},
|
|
192
|
+
{foo: 'b', bar: 'c'},
|
|
193
|
+
{foo: 'b', bar: 'a'},
|
|
194
|
+
{foo: 'a', bar: 'd'},
|
|
195
|
+
];
|
|
196
|
+
S.sort(objects, ['foo ASC', 'bar ASC']);
|
|
197
|
+
expect(objects).to.have.length(4);
|
|
198
|
+
expect(objects[0].bar).to.be.eq('d');
|
|
199
|
+
expect(objects[1].bar).to.be.eq('a');
|
|
200
|
+
expect(objects[2].bar).to.be.eq('b');
|
|
201
|
+
expect(objects[3].bar).to.be.eq('c');
|
|
202
|
+
});
|
|
145
203
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
204
|
+
it('orders with mixed directions', function () {
|
|
205
|
+
const objects = [
|
|
206
|
+
{foo: 'b', bar: 'b'},
|
|
207
|
+
{foo: 'b', bar: 'd'},
|
|
208
|
+
{foo: 'b', bar: 'a'},
|
|
209
|
+
{foo: 'a', bar: 'c'},
|
|
210
|
+
];
|
|
211
|
+
S.sort(objects, ['foo DESC', 'bar ASC']);
|
|
212
|
+
expect(objects).to.have.length(4);
|
|
213
|
+
expect(objects[0].bar).to.be.eq('a');
|
|
214
|
+
expect(objects[1].bar).to.be.eq('b');
|
|
215
|
+
expect(objects[2].bar).to.be.eq('d');
|
|
216
|
+
expect(objects[3].bar).to.be.eq('c');
|
|
217
|
+
});
|
|
155
218
|
});
|
|
156
219
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
220
|
+
describe('with number and string values', function () {
|
|
221
|
+
it('orders in ascending by default', function () {
|
|
222
|
+
const objects = [
|
|
223
|
+
{foo: 2, bar: 'd'},
|
|
224
|
+
{foo: 2, bar: 'b'},
|
|
225
|
+
{foo: 2, bar: 'a'},
|
|
226
|
+
{foo: 1, bar: 'c'},
|
|
227
|
+
];
|
|
228
|
+
S.sort(objects, ['foo', 'bar']);
|
|
229
|
+
expect(objects).to.have.length(4);
|
|
230
|
+
expect(objects[0].bar).to.be.eq('c');
|
|
231
|
+
expect(objects[1].bar).to.be.eq('a');
|
|
232
|
+
expect(objects[2].bar).to.be.eq('b');
|
|
233
|
+
expect(objects[3].bar).to.be.eq('d');
|
|
234
|
+
});
|
|
166
235
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
236
|
+
it('orders in descending', function () {
|
|
237
|
+
const objects = [
|
|
238
|
+
{foo: 2, bar: 'd'},
|
|
239
|
+
{foo: 2, bar: 'b'},
|
|
240
|
+
{foo: 2, bar: 'a'},
|
|
241
|
+
{foo: 1, bar: 'c'},
|
|
242
|
+
];
|
|
243
|
+
S.sort(objects, ['foo DESC', 'bar DESC']);
|
|
244
|
+
expect(objects).to.have.length(4);
|
|
245
|
+
expect(objects[0].bar).to.be.eq('d');
|
|
246
|
+
expect(objects[1].bar).to.be.eq('b');
|
|
247
|
+
expect(objects[2].bar).to.be.eq('a');
|
|
248
|
+
expect(objects[3].bar).to.be.eq('c');
|
|
249
|
+
});
|
|
176
250
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
251
|
+
it('orders in ascending', function () {
|
|
252
|
+
const objects = [
|
|
253
|
+
{foo: 2, bar: 'd'},
|
|
254
|
+
{foo: 2, bar: 'b'},
|
|
255
|
+
{foo: 2, bar: 'a'},
|
|
256
|
+
{foo: 1, bar: 'c'},
|
|
257
|
+
];
|
|
258
|
+
S.sort(objects, ['foo ASC', 'bar ASC']);
|
|
259
|
+
expect(objects).to.have.length(4);
|
|
260
|
+
expect(objects[0].bar).to.be.eq('c');
|
|
261
|
+
expect(objects[1].bar).to.be.eq('a');
|
|
262
|
+
expect(objects[2].bar).to.be.eq('b');
|
|
263
|
+
expect(objects[3].bar).to.be.eq('d');
|
|
264
|
+
});
|
|
191
265
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
266
|
+
it('orders in mixed directions', function () {
|
|
267
|
+
const objects = [
|
|
268
|
+
{foo: 2, bar: 'd'},
|
|
269
|
+
{foo: 2, bar: 'b'},
|
|
270
|
+
{foo: 2, bar: 'a'},
|
|
271
|
+
{foo: 1, bar: 'c'},
|
|
272
|
+
];
|
|
273
|
+
S.sort(objects, ['foo DESC', 'bar ASC']);
|
|
274
|
+
expect(objects).to.have.length(4);
|
|
275
|
+
expect(objects[0].bar).to.be.eq('a');
|
|
276
|
+
expect(objects[1].bar).to.be.eq('b');
|
|
277
|
+
expect(objects[2].bar).to.be.eq('d');
|
|
278
|
+
expect(objects[3].bar).to.be.eq('c');
|
|
279
|
+
});
|
|
205
280
|
});
|
|
281
|
+
});
|
|
206
282
|
|
|
207
|
-
|
|
283
|
+
describe('nested single field', function () {
|
|
284
|
+
it('does not throw an error if the nested field is not exist', function () {
|
|
208
285
|
const objects = [
|
|
209
|
-
{foo:
|
|
210
|
-
{foo:
|
|
211
|
-
{foo:
|
|
212
|
-
{foo:
|
|
286
|
+
{foo: 1},
|
|
287
|
+
{foo: 2, bar: undefined},
|
|
288
|
+
{foo: 3, bar: {baz: undefined}},
|
|
289
|
+
{foo: 4, bar: {baz: 1}},
|
|
213
290
|
];
|
|
214
|
-
S.sort(objects,
|
|
291
|
+
S.sort(objects, 'bar.baz');
|
|
215
292
|
expect(objects).to.have.length(4);
|
|
216
|
-
expect(objects[0].
|
|
217
|
-
expect(objects[1].
|
|
218
|
-
expect(objects[2].
|
|
219
|
-
expect(objects[3].
|
|
293
|
+
expect(objects[0].foo).to.be.eq(1);
|
|
294
|
+
expect(objects[1].foo).to.be.eq(2);
|
|
295
|
+
expect(objects[2].foo).to.be.eq(3);
|
|
296
|
+
expect(objects[3].foo).to.be.eq(4);
|
|
220
297
|
});
|
|
221
298
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
299
|
+
describe('with number values', function () {
|
|
300
|
+
it('orders in ascending by default', function () {
|
|
301
|
+
const objects = [
|
|
302
|
+
{foo: {bar: 3}},
|
|
303
|
+
{foo: {bar: 4}},
|
|
304
|
+
{foo: {bar: 2}},
|
|
305
|
+
{foo: {bar: 1}},
|
|
306
|
+
];
|
|
307
|
+
S.sort(objects, 'foo.bar');
|
|
308
|
+
expect(objects).to.have.length(4);
|
|
309
|
+
expect(objects[0].foo.bar).to.be.eq(1);
|
|
310
|
+
expect(objects[1].foo.bar).to.be.eq(2);
|
|
311
|
+
expect(objects[2].foo.bar).to.be.eq(3);
|
|
312
|
+
expect(objects[3].foo.bar).to.be.eq(4);
|
|
313
|
+
});
|
|
236
314
|
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
315
|
+
it('orders in descending', function () {
|
|
316
|
+
const objects = [
|
|
317
|
+
{foo: {bar: 3}},
|
|
318
|
+
{foo: {bar: 4}},
|
|
319
|
+
{foo: {bar: 2}},
|
|
320
|
+
{foo: {bar: 1}},
|
|
321
|
+
];
|
|
322
|
+
S.sort(objects, 'foo.bar DESC');
|
|
323
|
+
expect(objects).to.have.length(4);
|
|
324
|
+
expect(objects[0].foo.bar).to.be.eq(4);
|
|
325
|
+
expect(objects[1].foo.bar).to.be.eq(3);
|
|
326
|
+
expect(objects[2].foo.bar).to.be.eq(2);
|
|
327
|
+
expect(objects[3].foo.bar).to.be.eq(1);
|
|
328
|
+
});
|
|
251
329
|
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
330
|
+
it('orders in ascending', function () {
|
|
331
|
+
const objects = [
|
|
332
|
+
{foo: {bar: 3}},
|
|
333
|
+
{foo: {bar: 4}},
|
|
334
|
+
{foo: {bar: 2}},
|
|
335
|
+
{foo: {bar: 1}},
|
|
336
|
+
];
|
|
337
|
+
S.sort(objects, 'foo.bar ASC');
|
|
338
|
+
expect(objects).to.have.length(4);
|
|
339
|
+
expect(objects[0].foo.bar).to.be.eq(1);
|
|
340
|
+
expect(objects[1].foo.bar).to.be.eq(2);
|
|
341
|
+
expect(objects[2].foo.bar).to.be.eq(3);
|
|
342
|
+
expect(objects[3].foo.bar).to.be.eq(4);
|
|
343
|
+
});
|
|
265
344
|
});
|
|
266
345
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
346
|
+
describe('with string values', function () {
|
|
347
|
+
it('orders in ascending by default', function () {
|
|
348
|
+
const objects = [
|
|
349
|
+
{foo: {bar: 'c'}},
|
|
350
|
+
{foo: {bar: 'd'}},
|
|
351
|
+
{foo: {bar: 'b'}},
|
|
352
|
+
{foo: {bar: 'a'}},
|
|
353
|
+
];
|
|
354
|
+
S.sort(objects, 'foo.bar');
|
|
355
|
+
expect(objects).to.have.length(4);
|
|
356
|
+
expect(objects[0].foo.bar).to.be.eq('a');
|
|
357
|
+
expect(objects[1].foo.bar).to.be.eq('b');
|
|
358
|
+
expect(objects[2].foo.bar).to.be.eq('c');
|
|
359
|
+
expect(objects[3].foo.bar).to.be.eq('d');
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
it('orders in descending', function () {
|
|
363
|
+
const objects = [
|
|
364
|
+
{foo: {bar: 'c'}},
|
|
365
|
+
{foo: {bar: 'd'}},
|
|
366
|
+
{foo: {bar: 'b'}},
|
|
367
|
+
{foo: {bar: 'a'}},
|
|
368
|
+
];
|
|
369
|
+
S.sort(objects, 'foo.bar DESC');
|
|
370
|
+
expect(objects).to.have.length(4);
|
|
371
|
+
expect(objects[0].foo.bar).to.be.eq('d');
|
|
372
|
+
expect(objects[1].foo.bar).to.be.eq('c');
|
|
373
|
+
expect(objects[2].foo.bar).to.be.eq('b');
|
|
374
|
+
expect(objects[3].foo.bar).to.be.eq('a');
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('orders in ascending', function () {
|
|
378
|
+
const objects = [
|
|
379
|
+
{foo: {bar: 'c'}},
|
|
380
|
+
{foo: {bar: 'd'}},
|
|
381
|
+
{foo: {bar: 'b'}},
|
|
382
|
+
{foo: {bar: 'a'}},
|
|
383
|
+
];
|
|
384
|
+
S.sort(objects, 'foo.bar ASC');
|
|
385
|
+
expect(objects).to.have.length(4);
|
|
386
|
+
expect(objects[0].foo.bar).to.be.eq('a');
|
|
387
|
+
expect(objects[1].foo.bar).to.be.eq('b');
|
|
388
|
+
expect(objects[2].foo.bar).to.be.eq('c');
|
|
389
|
+
expect(objects[3].foo.bar).to.be.eq('d');
|
|
390
|
+
});
|
|
280
391
|
});
|
|
281
392
|
});
|
|
282
393
|
|
|
283
|
-
describe('
|
|
284
|
-
it('
|
|
394
|
+
describe('nested multiple fields', function () {
|
|
395
|
+
it('does not throw an error if nested multiple fields are not exist', function () {
|
|
285
396
|
const objects = [
|
|
286
|
-
{foo:
|
|
287
|
-
{foo: 2, bar:
|
|
288
|
-
{foo:
|
|
289
|
-
{foo:
|
|
397
|
+
{foo: 1},
|
|
398
|
+
{foo: 2, bar: undefined},
|
|
399
|
+
{foo: 3, bar: {baz: undefined}},
|
|
400
|
+
{foo: 4, bar: {baz: 1}},
|
|
290
401
|
];
|
|
291
|
-
S.sort(objects, ['
|
|
402
|
+
S.sort(objects, ['bar.baz', 'qux']);
|
|
292
403
|
expect(objects).to.have.length(4);
|
|
293
|
-
expect(objects[0].
|
|
294
|
-
expect(objects[1].
|
|
295
|
-
expect(objects[2].
|
|
296
|
-
expect(objects[3].
|
|
404
|
+
expect(objects[0].foo).to.be.eq(1);
|
|
405
|
+
expect(objects[1].foo).to.be.eq(2);
|
|
406
|
+
expect(objects[2].foo).to.be.eq(3);
|
|
407
|
+
expect(objects[3].foo).to.be.eq(4);
|
|
297
408
|
});
|
|
298
409
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
410
|
+
describe('with number values', function () {
|
|
411
|
+
it('orders in ascending by default', function () {
|
|
412
|
+
const objects = [
|
|
413
|
+
{foo: {bar: 2}, baz: 2},
|
|
414
|
+
{foo: {bar: 2}, baz: 1},
|
|
415
|
+
{foo: {bar: 2}, baz: 4},
|
|
416
|
+
{foo: {bar: 1}, baz: 3},
|
|
417
|
+
];
|
|
418
|
+
S.sort(objects, ['foo.bar', 'baz']);
|
|
419
|
+
expect(objects).to.have.length(4);
|
|
420
|
+
expect(objects[0].baz).to.be.eq(3);
|
|
421
|
+
expect(objects[1].baz).to.be.eq(1);
|
|
422
|
+
expect(objects[2].baz).to.be.eq(2);
|
|
423
|
+
expect(objects[3].baz).to.be.eq(4);
|
|
424
|
+
});
|
|
313
425
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
426
|
+
it('orders in descending', function () {
|
|
427
|
+
const objects = [
|
|
428
|
+
{foo: {bar: 2}, baz: 2},
|
|
429
|
+
{foo: {bar: 2}, baz: 1},
|
|
430
|
+
{foo: {bar: 2}, baz: 4},
|
|
431
|
+
{foo: {bar: 1}, baz: 3},
|
|
432
|
+
];
|
|
433
|
+
S.sort(objects, ['foo.bar DESC', 'baz DESC']);
|
|
434
|
+
expect(objects).to.have.length(4);
|
|
435
|
+
expect(objects[0].baz).to.be.eq(4);
|
|
436
|
+
expect(objects[1].baz).to.be.eq(2);
|
|
437
|
+
expect(objects[2].baz).to.be.eq(1);
|
|
438
|
+
expect(objects[3].baz).to.be.eq(3);
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
it('orders in ascending', function () {
|
|
442
|
+
const objects = [
|
|
443
|
+
{foo: {bar: 2}, baz: 2},
|
|
444
|
+
{foo: {bar: 2}, baz: 1},
|
|
445
|
+
{foo: {bar: 2}, baz: 4},
|
|
446
|
+
{foo: {bar: 1}, baz: 3},
|
|
447
|
+
];
|
|
448
|
+
S.sort(objects, ['foo.bar ASC', 'baz ASC']);
|
|
449
|
+
expect(objects).to.have.length(4);
|
|
450
|
+
expect(objects[0].baz).to.be.eq(3);
|
|
451
|
+
expect(objects[1].baz).to.be.eq(1);
|
|
452
|
+
expect(objects[2].baz).to.be.eq(2);
|
|
453
|
+
expect(objects[3].baz).to.be.eq(4);
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
it('orders with mixed directions', function () {
|
|
457
|
+
const objects = [
|
|
458
|
+
{foo: {bar: 2}, baz: 2},
|
|
459
|
+
{foo: {bar: 2}, baz: 1},
|
|
460
|
+
{foo: {bar: 2}, baz: 4},
|
|
461
|
+
{foo: {bar: 1}, baz: 3},
|
|
462
|
+
];
|
|
463
|
+
S.sort(objects, ['foo.bar DESC', 'baz']);
|
|
464
|
+
expect(objects).to.have.length(4);
|
|
465
|
+
expect(objects[0].baz).to.be.eq(1);
|
|
466
|
+
expect(objects[1].baz).to.be.eq(2);
|
|
467
|
+
expect(objects[2].baz).to.be.eq(4);
|
|
468
|
+
expect(objects[3].baz).to.be.eq(3);
|
|
469
|
+
});
|
|
327
470
|
});
|
|
328
471
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
472
|
+
describe('with string values', function () {
|
|
473
|
+
it('orders in ascending by default', function () {
|
|
474
|
+
const objects = [
|
|
475
|
+
{foo: {bar: 'b'}, baz: 'b'},
|
|
476
|
+
{foo: {bar: 'b'}, baz: 'a'},
|
|
477
|
+
{foo: {bar: 'b'}, baz: 'd'},
|
|
478
|
+
{foo: {bar: 'a'}, baz: 'c'},
|
|
479
|
+
];
|
|
480
|
+
S.sort(objects, ['foo.bar', 'baz']);
|
|
481
|
+
expect(objects).to.have.length(4);
|
|
482
|
+
expect(objects[0].baz).to.be.eq('c');
|
|
483
|
+
expect(objects[1].baz).to.be.eq('a');
|
|
484
|
+
expect(objects[2].baz).to.be.eq('b');
|
|
485
|
+
expect(objects[3].baz).to.be.eq('d');
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
it('orders in descending', function () {
|
|
489
|
+
const objects = [
|
|
490
|
+
{foo: {bar: 'b'}, baz: 'b'},
|
|
491
|
+
{foo: {bar: 'b'}, baz: 'a'},
|
|
492
|
+
{foo: {bar: 'b'}, baz: 'd'},
|
|
493
|
+
{foo: {bar: 'a'}, baz: 'c'},
|
|
494
|
+
];
|
|
495
|
+
S.sort(objects, ['foo.bar DESC', 'baz DESC']);
|
|
496
|
+
expect(objects).to.have.length(4);
|
|
497
|
+
expect(objects[0].baz).to.be.eq('d');
|
|
498
|
+
expect(objects[1].baz).to.be.eq('b');
|
|
499
|
+
expect(objects[2].baz).to.be.eq('a');
|
|
500
|
+
expect(objects[3].baz).to.be.eq('c');
|
|
501
|
+
});
|
|
502
|
+
|
|
503
|
+
it('orders in ascending', function () {
|
|
504
|
+
const objects = [
|
|
505
|
+
{foo: {bar: 'b'}, baz: 'b'},
|
|
506
|
+
{foo: {bar: 'b'}, baz: 'a'},
|
|
507
|
+
{foo: {bar: 'b'}, baz: 'd'},
|
|
508
|
+
{foo: {bar: 'a'}, baz: 'c'},
|
|
509
|
+
];
|
|
510
|
+
S.sort(objects, ['foo.bar ASC', 'baz ASC']);
|
|
511
|
+
expect(objects).to.have.length(4);
|
|
512
|
+
expect(objects[0].baz).to.be.eq('c');
|
|
513
|
+
expect(objects[1].baz).to.be.eq('a');
|
|
514
|
+
expect(objects[2].baz).to.be.eq('b');
|
|
515
|
+
expect(objects[3].baz).to.be.eq('d');
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
it('orders with mixed directions', function () {
|
|
519
|
+
const objects = [
|
|
520
|
+
{foo: {bar: 'b'}, baz: 'b'},
|
|
521
|
+
{foo: {bar: 'b'}, baz: 'a'},
|
|
522
|
+
{foo: {bar: 'b'}, baz: 'd'},
|
|
523
|
+
{foo: {bar: 'a'}, baz: 'c'},
|
|
524
|
+
];
|
|
525
|
+
S.sort(objects, ['foo.bar DESC', 'baz']);
|
|
526
|
+
expect(objects).to.have.length(4);
|
|
527
|
+
expect(objects[0].baz).to.be.eq('a');
|
|
528
|
+
expect(objects[1].baz).to.be.eq('b');
|
|
529
|
+
expect(objects[2].baz).to.be.eq('d');
|
|
530
|
+
expect(objects[3].baz).to.be.eq('c');
|
|
531
|
+
});
|
|
342
532
|
});
|
|
343
|
-
});
|
|
344
533
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
534
|
+
describe('with number and string values', function () {
|
|
535
|
+
it('orders in ascending by default', function () {
|
|
536
|
+
const objects = [
|
|
537
|
+
{foo: {bar: 'b'}, baz: 2},
|
|
538
|
+
{foo: {bar: 'b'}, baz: 1},
|
|
539
|
+
{foo: {bar: 'b'}, baz: 4},
|
|
540
|
+
{foo: {bar: 'a'}, baz: 3},
|
|
541
|
+
];
|
|
542
|
+
S.sort(objects, ['foo.bar', 'baz']);
|
|
543
|
+
expect(objects).to.have.length(4);
|
|
544
|
+
expect(objects[0].baz).to.be.eq(3);
|
|
545
|
+
expect(objects[1].baz).to.be.eq(1);
|
|
546
|
+
expect(objects[2].baz).to.be.eq(2);
|
|
547
|
+
expect(objects[3].baz).to.be.eq(4);
|
|
548
|
+
});
|
|
354
549
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
550
|
+
it('orders in descending', function () {
|
|
551
|
+
const objects = [
|
|
552
|
+
{foo: {bar: 'b'}, baz: 2},
|
|
553
|
+
{foo: {bar: 'b'}, baz: 1},
|
|
554
|
+
{foo: {bar: 'b'}, baz: 4},
|
|
555
|
+
{foo: {bar: 'a'}, baz: 3},
|
|
556
|
+
];
|
|
557
|
+
S.sort(objects, ['foo.bar DESC', 'baz DESC']);
|
|
558
|
+
expect(objects).to.have.length(4);
|
|
559
|
+
expect(objects[0].baz).to.be.eq(4);
|
|
560
|
+
expect(objects[1].baz).to.be.eq(2);
|
|
561
|
+
expect(objects[2].baz).to.be.eq(1);
|
|
562
|
+
expect(objects[3].baz).to.be.eq(3);
|
|
563
|
+
});
|
|
369
564
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
565
|
+
it('orders in ascending', function () {
|
|
566
|
+
const objects = [
|
|
567
|
+
{foo: {bar: 'b'}, baz: 2},
|
|
568
|
+
{foo: {bar: 'b'}, baz: 1},
|
|
569
|
+
{foo: {bar: 'b'}, baz: 4},
|
|
570
|
+
{foo: {bar: 'a'}, baz: 3},
|
|
571
|
+
];
|
|
572
|
+
S.sort(objects, ['foo.bar ASC', 'baz ASC']);
|
|
573
|
+
expect(objects).to.have.length(4);
|
|
574
|
+
expect(objects[0].baz).to.be.eq(3);
|
|
575
|
+
expect(objects[1].baz).to.be.eq(1);
|
|
576
|
+
expect(objects[2].baz).to.be.eq(2);
|
|
577
|
+
expect(objects[3].baz).to.be.eq(4);
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
it('orders with mixed directions', function () {
|
|
581
|
+
const objects = [
|
|
582
|
+
{foo: {bar: 'b'}, baz: 2},
|
|
583
|
+
{foo: {bar: 'b'}, baz: 1},
|
|
584
|
+
{foo: {bar: 'b'}, baz: 4},
|
|
585
|
+
{foo: {bar: 'a'}, baz: 3},
|
|
586
|
+
];
|
|
587
|
+
S.sort(objects, ['foo.bar DESC', 'baz']);
|
|
588
|
+
expect(objects).to.have.length(4);
|
|
589
|
+
expect(objects[0].baz).to.be.eq(1);
|
|
590
|
+
expect(objects[1].baz).to.be.eq(2);
|
|
591
|
+
expect(objects[2].baz).to.be.eq(4);
|
|
592
|
+
expect(objects[3].baz).to.be.eq(3);
|
|
593
|
+
});
|
|
594
|
+
});
|
|
376
595
|
});
|
|
377
596
|
});
|
|
378
597
|
|
|
379
598
|
describe('validateOrderClause', function () {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
'
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
599
|
+
describe('single field', function () {
|
|
600
|
+
it('requires the first argument as a non-empty string', function () {
|
|
601
|
+
const throwable = v => () => OrderClauseTool.validateOrderClause(v);
|
|
602
|
+
const error = v =>
|
|
603
|
+
format(
|
|
604
|
+
'The provided option "order" should be a non-empty String ' +
|
|
605
|
+
'or an Array of non-empty String, but %s given.',
|
|
606
|
+
v,
|
|
607
|
+
);
|
|
608
|
+
expect(throwable('')).to.throw(error('""'));
|
|
609
|
+
expect(throwable(10)).to.throw(error('10'));
|
|
610
|
+
expect(throwable(0)).to.throw(error('0'));
|
|
611
|
+
expect(throwable(true)).to.throw(error('true'));
|
|
612
|
+
expect(throwable(false)).to.throw(error('false'));
|
|
613
|
+
expect(throwable({})).to.throw(error('Object'));
|
|
614
|
+
throwable('field')();
|
|
615
|
+
throwable(undefined)();
|
|
616
|
+
throwable(null)();
|
|
617
|
+
});
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
describe('multiple fields', function () {
|
|
621
|
+
it('requires the first argument as a non-empty string', function () {
|
|
622
|
+
const throwable = v => () => OrderClauseTool.validateOrderClause(v);
|
|
623
|
+
const error = v =>
|
|
624
|
+
format(
|
|
625
|
+
'The provided option "order" should be a non-empty String ' +
|
|
626
|
+
'or an Array of non-empty String, but %s given.',
|
|
627
|
+
v,
|
|
628
|
+
);
|
|
629
|
+
expect(throwable([''])).to.throw(error('""'));
|
|
630
|
+
expect(throwable([10])).to.throw(error('10'));
|
|
631
|
+
expect(throwable([0])).to.throw(error('0'));
|
|
632
|
+
expect(throwable([true])).to.throw(error('true'));
|
|
633
|
+
expect(throwable([false])).to.throw(error('false'));
|
|
634
|
+
expect(throwable([{}])).to.throw(error('Object'));
|
|
635
|
+
expect(throwable([undefined])).to.throw(error('undefined'));
|
|
636
|
+
expect(throwable([null])).to.throw(error('null'));
|
|
637
|
+
throwable(['field'])();
|
|
638
|
+
throwable([])();
|
|
639
|
+
});
|
|
403
640
|
});
|
|
404
641
|
});
|
|
405
642
|
|
|
406
643
|
describe('normalizeOrderClause', function () {
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
644
|
+
describe('single field', function () {
|
|
645
|
+
it('requires the first argument as a non-empty string', function () {
|
|
646
|
+
const throwable = v => () => OrderClauseTool.normalizeOrderClause(v);
|
|
647
|
+
const error = v =>
|
|
648
|
+
format(
|
|
649
|
+
'The provided option "order" should be a non-empty String ' +
|
|
650
|
+
'or an Array of non-empty String, but %s given.',
|
|
651
|
+
v,
|
|
652
|
+
);
|
|
653
|
+
expect(throwable('')).to.throw(error('""'));
|
|
654
|
+
expect(throwable(10)).to.throw(error('10'));
|
|
655
|
+
expect(throwable(0)).to.throw(error('0'));
|
|
656
|
+
expect(throwable(true)).to.throw(error('true'));
|
|
657
|
+
expect(throwable(false)).to.throw(error('false'));
|
|
658
|
+
expect(throwable({})).to.throw(error('Object'));
|
|
659
|
+
expect(throwable('field')()).to.be.eql(['field']);
|
|
660
|
+
expect(throwable(undefined)()).to.be.undefined;
|
|
661
|
+
expect(throwable(null)()).to.be.undefined;
|
|
662
|
+
});
|
|
663
|
+
|
|
664
|
+
it('returns an array of string', function () {
|
|
665
|
+
const fn = OrderClauseTool.normalizeOrderClause;
|
|
666
|
+
expect(fn('foo')).to.be.eql(['foo']);
|
|
667
|
+
});
|
|
411
668
|
});
|
|
412
669
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
'
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
670
|
+
describe('multiple fields', function () {
|
|
671
|
+
it('requires the first argument as a non-empty string', function () {
|
|
672
|
+
const throwable = v => () => OrderClauseTool.normalizeOrderClause(v);
|
|
673
|
+
const error = v =>
|
|
674
|
+
format(
|
|
675
|
+
'The provided option "order" should be a non-empty String ' +
|
|
676
|
+
'or an Array of non-empty String, but %s given.',
|
|
677
|
+
v,
|
|
678
|
+
);
|
|
679
|
+
expect(throwable([''])).to.throw(error('""'));
|
|
680
|
+
expect(throwable([10])).to.throw(error('10'));
|
|
681
|
+
expect(throwable([0])).to.throw(error('0'));
|
|
682
|
+
expect(throwable([true])).to.throw(error('true'));
|
|
683
|
+
expect(throwable([false])).to.throw(error('false'));
|
|
684
|
+
expect(throwable([{}])).to.throw(error('Object'));
|
|
685
|
+
expect(throwable([undefined])).to.throw(error('undefined'));
|
|
686
|
+
expect(throwable([null])).to.throw(error('null'));
|
|
687
|
+
expect(throwable(['field'])()).to.be.eql(['field']);
|
|
688
|
+
expect(throwable([])()).to.be.undefined;
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
it('returns an array of strings', function () {
|
|
692
|
+
const fn = OrderClauseTool.normalizeOrderClause;
|
|
693
|
+
expect(fn(['foo', 'bar'])).to.be.eql(['foo', 'bar']);
|
|
694
|
+
});
|
|
436
695
|
});
|
|
437
696
|
});
|
|
438
697
|
});
|