@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.
Files changed (33) hide show
  1. package/package.json +1 -1
  2. package/src/adapter/adapter-loader.js +1 -1
  3. package/src/adapter/adapter-loader.spec.js +1 -1
  4. package/src/adapter/adapter.d.ts +11 -7
  5. package/src/adapter/builtin/memory-adapter.d.ts +11 -7
  6. package/src/adapter/decorator/data-sanitizing-decorator.js +1 -1
  7. package/src/adapter/decorator/data-validation-decorator.js +1 -1
  8. package/src/adapter/decorator/default-values-decorator.js +1 -1
  9. package/src/adapter/decorator/fields-filtering-decorator.js +1 -1
  10. package/src/adapter/decorator/inclusion-decorator.js +1 -1
  11. package/src/definition/model/model-data-sanitizer.js +2 -2
  12. package/src/definition/model/model-data-validator.js +1 -1
  13. package/src/definition/model/model-data-validator.spec.js +1 -1
  14. package/src/definition/model/model-definition-utils.js +1 -1
  15. package/src/definition/model/model-definition-utils.spec.js +1 -1
  16. package/src/filter/fields-clause-tool.d.ts +4 -4
  17. package/src/filter/fields-clause-tool.js +32 -21
  18. package/src/filter/fields-clause-tool.spec.js +479 -100
  19. package/src/filter/{filter.d.ts → filter-clause.d.ts} +10 -10
  20. package/src/filter/include-clause-tool.d.ts +7 -5
  21. package/src/filter/index.d.ts +1 -1
  22. package/src/filter/operator-clause-tool.js +1 -1
  23. package/src/filter/operator-clause-tool.spec.js +1 -1
  24. package/src/filter/order-clause-tool.d.ts +1 -1
  25. package/src/filter/order-clause-tool.js +20 -17
  26. package/src/filter/order-clause-tool.spec.js +621 -362
  27. package/src/filter/slice-clause-tool.js +1 -1
  28. package/src/filter/where-clause-tool.d.ts +1 -1
  29. package/src/relations/belongs-to-resolver.d.ts +3 -3
  30. package/src/relations/has-many-resolver.d.ts +4 -4
  31. package/src/relations/has-one-resolver.d.ts +4 -4
  32. package/src/relations/references-many-resolver.d.ts +2 -2
  33. 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('with number values', function () {
10
- it('orders by a single field in ascending by default', function () {
11
- const objects = [{foo: 2}, {foo: 3}, {foo: 1}, {foo: 4}];
12
- S.sort(objects, 'foo');
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
- it('orders by a single field in descending', function () {
21
- const objects = [{foo: 2}, {foo: 3}, {foo: 1}, {foo: 4}];
22
- S.sort(objects, 'foo DESC');
23
- expect(objects).to.have.length(4);
24
- expect(objects[0].foo).to.be.eq(4);
25
- expect(objects[1].foo).to.be.eq(3);
26
- expect(objects[2].foo).to.be.eq(2);
27
- expect(objects[3].foo).to.be.eq(1);
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
- it('orders by a single field in ascending', function () {
31
- const objects = [{foo: 2}, {foo: 3}, {foo: 1}, {foo: 4}];
32
- S.sort(objects, 'foo ASC');
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
- it('orders by multiple fields in ascending by default', function () {
41
- const objects = [
42
- {foo: 2, bar: 2},
43
- {foo: 2, bar: 3},
44
- {foo: 2, bar: 1},
45
- {foo: 1, bar: 4},
46
- ];
47
- S.sort(objects, ['foo', 'bar']);
48
- expect(objects).to.have.length(4);
49
- expect(objects[0].bar).to.be.eq(4);
50
- expect(objects[1].bar).to.be.eq(1);
51
- expect(objects[2].bar).to.be.eq(2);
52
- expect(objects[3].bar).to.be.eq(3);
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
- it('orders by multiple fields in descending', function () {
56
- const objects = [
57
- {foo: 2, bar: 2},
58
- {foo: 2, bar: 3},
59
- {foo: 2, bar: 1},
60
- {foo: 1, bar: 4},
61
- ];
62
- S.sort(objects, ['foo DESC', 'bar DESC']);
63
- expect(objects).to.have.length(4);
64
- expect(objects[0].bar).to.be.eq(3);
65
- expect(objects[1].bar).to.be.eq(2);
66
- expect(objects[2].bar).to.be.eq(1);
67
- expect(objects[3].bar).to.be.eq(4);
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
- it('orders by multiple fields in ascending', function () {
71
- const objects = [
72
- {foo: 2, bar: 2},
73
- {foo: 2, bar: 3},
74
- {foo: 2, bar: 1},
75
- {foo: 1, bar: 4},
76
- ];
77
- S.sort(objects, ['foo ASC', 'bar ASC']);
78
- expect(objects).to.have.length(4);
79
- expect(objects[0].bar).to.be.eq(4);
80
- expect(objects[1].bar).to.be.eq(1);
81
- expect(objects[2].bar).to.be.eq(2);
82
- expect(objects[3].bar).to.be.eq(3);
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
- it('orders by nested fields in ascending by default', function () {
86
- const objects = [
87
- {foo: {bar: 3}},
88
- {foo: {bar: 4}},
89
- {foo: {bar: 2}},
90
- {foo: {bar: 1}},
91
- ];
92
- S.sort(objects, 'foo.bar');
93
- expect(objects).to.have.length(4);
94
- expect(objects[0].foo.bar).to.be.eq(1);
95
- expect(objects[1].foo.bar).to.be.eq(2);
96
- expect(objects[2].foo.bar).to.be.eq(3);
97
- expect(objects[3].foo.bar).to.be.eq(4);
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
- it('orders by nested fields in descending', function () {
101
- const objects = [
102
- {foo: {bar: 3}},
103
- {foo: {bar: 4}},
104
- {foo: {bar: 2}},
105
- {foo: {bar: 1}},
106
- ];
107
- S.sort(objects, 'foo.bar DESC');
108
- expect(objects).to.have.length(4);
109
- expect(objects[0].foo.bar).to.be.eq(4);
110
- expect(objects[1].foo.bar).to.be.eq(3);
111
- expect(objects[2].foo.bar).to.be.eq(2);
112
- expect(objects[3].foo.bar).to.be.eq(1);
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
- it('orders by nested fields in ascending', function () {
116
- const objects = [
117
- {foo: {bar: 3}},
118
- {foo: {bar: 4}},
119
- {foo: {bar: 2}},
120
- {foo: {bar: 1}},
121
- ];
122
- S.sort(objects, 'foo.bar ASC');
123
- expect(objects).to.have.length(4);
124
- expect(objects[0].foo.bar).to.be.eq(1);
125
- expect(objects[1].foo.bar).to.be.eq(2);
126
- expect(objects[2].foo.bar).to.be.eq(3);
127
- expect(objects[3].foo.bar).to.be.eq(4);
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
- it('orders by multiple fields with nested one', function () {
131
- const objects = [
132
- {foo: {bar: 2}, baz: 2},
133
- {foo: {bar: 2}, baz: 3},
134
- {foo: {bar: 2}, baz: 4},
135
- {foo: {bar: 1}, baz: 1},
136
- ];
137
- S.sort(objects, ['foo.bar ASC', 'baz DESC']);
138
- expect(objects).to.have.length(4);
139
- expect(objects[0].baz).to.be.eq(1);
140
- expect(objects[1].baz).to.be.eq(4);
141
- expect(objects[2].baz).to.be.eq(3);
142
- expect(objects[3].baz).to.be.eq(2);
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
- describe('with string values', function () {
147
- it('orders by a single field in ascending by default', function () {
148
- const objects = [{foo: 'b'}, {foo: 'c'}, {foo: 'a'}, {foo: 'd'}];
149
- S.sort(objects, 'foo');
150
- expect(objects).to.have.length(4);
151
- expect(objects[0].foo).to.be.eq('a');
152
- expect(objects[1].foo).to.be.eq('b');
153
- expect(objects[2].foo).to.be.eq('c');
154
- expect(objects[3].foo).to.be.eq('d');
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
- it('orders by a single field in descending', function () {
158
- const objects = [{foo: 'b'}, {foo: 'c'}, {foo: 'a'}, {foo: 'd'}];
159
- S.sort(objects, 'foo DESC');
160
- expect(objects).to.have.length(4);
161
- expect(objects[0].foo).to.be.eq('d');
162
- expect(objects[1].foo).to.be.eq('c');
163
- expect(objects[2].foo).to.be.eq('b');
164
- expect(objects[3].foo).to.be.eq('a');
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
- it('orders by a single field in ascending', function () {
168
- const objects = [{foo: 'b'}, {foo: 'c'}, {foo: 'a'}, {foo: 'd'}];
169
- S.sort(objects, 'foo ASC');
170
- expect(objects).to.have.length(4);
171
- expect(objects[0].foo).to.be.eq('a');
172
- expect(objects[1].foo).to.be.eq('b');
173
- expect(objects[2].foo).to.be.eq('c');
174
- expect(objects[3].foo).to.be.eq('d');
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
- it('orders by multiple fields in ascending by default', function () {
178
- const objects = [
179
- {foo: 'b', bar: 'b'},
180
- {foo: 'b', bar: 'c'},
181
- {foo: 'b', bar: 'a'},
182
- {foo: 'a', bar: 'd'},
183
- ];
184
- S.sort(objects, ['foo', 'bar']);
185
- expect(objects).to.have.length(4);
186
- expect(objects[0].bar).to.be.eq('d');
187
- expect(objects[1].bar).to.be.eq('a');
188
- expect(objects[2].bar).to.be.eq('b');
189
- expect(objects[3].bar).to.be.eq('c');
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
- it('orders by multiple fields in descending', function () {
193
- const objects = [
194
- {foo: 'b', bar: 'b'},
195
- {foo: 'b', bar: 'c'},
196
- {foo: 'b', bar: 'a'},
197
- {foo: 'a', bar: 'd'},
198
- ];
199
- S.sort(objects, ['foo DESC', 'bar DESC']);
200
- expect(objects).to.have.length(4);
201
- expect(objects[0].bar).to.be.eq('c');
202
- expect(objects[1].bar).to.be.eq('b');
203
- expect(objects[2].bar).to.be.eq('a');
204
- expect(objects[3].bar).to.be.eq('d');
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
- it('orders by multiple fields in ascending', function () {
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: 'b', bar: 'b'},
210
- {foo: 'b', bar: 'c'},
211
- {foo: 'b', bar: 'a'},
212
- {foo: 'a', bar: 'd'},
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, ['foo ASC', 'bar ASC']);
291
+ S.sort(objects, 'bar.baz');
215
292
  expect(objects).to.have.length(4);
216
- expect(objects[0].bar).to.be.eq('d');
217
- expect(objects[1].bar).to.be.eq('a');
218
- expect(objects[2].bar).to.be.eq('b');
219
- expect(objects[3].bar).to.be.eq('c');
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
- it('orders by nested fields in ascending by default', function () {
223
- const objects = [
224
- {foo: {bar: 'c'}},
225
- {foo: {bar: 'd'}},
226
- {foo: {bar: 'b'}},
227
- {foo: {bar: 'a'}},
228
- ];
229
- S.sort(objects, 'foo.bar');
230
- expect(objects).to.have.length(4);
231
- expect(objects[0].foo.bar).to.be.eq('a');
232
- expect(objects[1].foo.bar).to.be.eq('b');
233
- expect(objects[2].foo.bar).to.be.eq('c');
234
- expect(objects[3].foo.bar).to.be.eq('d');
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
- it('orders by nested fields in descending', function () {
238
- const objects = [
239
- {foo: {bar: 'c'}},
240
- {foo: {bar: 'd'}},
241
- {foo: {bar: 'b'}},
242
- {foo: {bar: 'a'}},
243
- ];
244
- S.sort(objects, 'foo.bar DESC');
245
- expect(objects).to.have.length(4);
246
- expect(objects[0].foo.bar).to.be.eq('d');
247
- expect(objects[1].foo.bar).to.be.eq('c');
248
- expect(objects[2].foo.bar).to.be.eq('b');
249
- expect(objects[3].foo.bar).to.be.eq('a');
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
- it('orders by nested fields in ascending', function () {
253
- const objects = [
254
- {foo: {bar: 'c'}},
255
- {foo: {bar: 'd'}},
256
- {foo: {bar: 'b'}},
257
- {foo: {bar: 'a'}},
258
- ];
259
- S.sort(objects, 'foo.bar ASC');
260
- expect(objects).to.have.length(4);
261
- expect(objects[0].foo.bar).to.be.eq('a');
262
- expect(objects[1].foo.bar).to.be.eq('b');
263
- expect(objects[2].foo.bar).to.be.eq('c');
264
- expect(objects[3].foo.bar).to.be.eq('d');
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
- it('orders by multiple fields with nested one', function () {
268
- const objects = [
269
- {foo: {bar: 'b'}, baz: 'b'},
270
- {foo: {bar: 'b'}, baz: 'c'},
271
- {foo: {bar: 'b'}, baz: 'd'},
272
- {foo: {bar: 'a'}, baz: 'a'},
273
- ];
274
- S.sort(objects, ['foo.bar ASC', 'baz DESC']);
275
- expect(objects).to.have.length(4);
276
- expect(objects[0].baz).to.be.eq('a');
277
- expect(objects[1].baz).to.be.eq('d');
278
- expect(objects[2].baz).to.be.eq('c');
279
- expect(objects[3].baz).to.be.eq('b');
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('with number and string values', function () {
284
- it('orders by number and string values in ascending by default', function () {
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: 2, bar: 'd'},
287
- {foo: 2, bar: 'b'},
288
- {foo: 2, bar: 'a'},
289
- {foo: 1, bar: 'c'},
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, ['foo', 'bar']);
402
+ S.sort(objects, ['bar.baz', 'qux']);
292
403
  expect(objects).to.have.length(4);
293
- expect(objects[0].bar).to.be.eq('c');
294
- expect(objects[1].bar).to.be.eq('a');
295
- expect(objects[2].bar).to.be.eq('b');
296
- expect(objects[3].bar).to.be.eq('d');
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
- it('orders by number and string values in descending', function () {
300
- const objects = [
301
- {foo: 2, bar: 'd'},
302
- {foo: 2, bar: 'b'},
303
- {foo: 2, bar: 'a'},
304
- {foo: 1, bar: 'c'},
305
- ];
306
- S.sort(objects, ['foo DESC', 'bar DESC']);
307
- expect(objects).to.have.length(4);
308
- expect(objects[0].bar).to.be.eq('d');
309
- expect(objects[1].bar).to.be.eq('b');
310
- expect(objects[2].bar).to.be.eq('a');
311
- expect(objects[3].bar).to.be.eq('c');
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
- it('orders by number and string values in ascending', function () {
315
- const objects = [
316
- {foo: 2, bar: 'd'},
317
- {foo: 2, bar: 'b'},
318
- {foo: 2, bar: 'a'},
319
- {foo: 1, bar: 'c'},
320
- ];
321
- S.sort(objects, ['foo ASC', 'bar ASC']);
322
- expect(objects).to.have.length(4);
323
- expect(objects[0].bar).to.be.eq('c');
324
- expect(objects[1].bar).to.be.eq('a');
325
- expect(objects[2].bar).to.be.eq('b');
326
- expect(objects[3].bar).to.be.eq('d');
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
- it('orders by number and string values in mixed directions', function () {
330
- const objects = [
331
- {foo: 2, bar: 'd'},
332
- {foo: 2, bar: 'b'},
333
- {foo: 2, bar: 'a'},
334
- {foo: 1, bar: 'c'},
335
- ];
336
- S.sort(objects, ['foo DESC', 'bar ASC']);
337
- expect(objects).to.have.length(4);
338
- expect(objects[0].bar).to.be.eq('a');
339
- expect(objects[1].bar).to.be.eq('b');
340
- expect(objects[2].bar).to.be.eq('d');
341
- expect(objects[3].bar).to.be.eq('c');
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
- it('does not throw an error if a field does not exist', function () {
346
- const objects = [{foo: 1}, {foo: 2}, {foo: 3}, {foo: 4}];
347
- S.sort(objects, 'bar');
348
- expect(objects).to.have.length(4);
349
- expect(objects[0].foo).to.be.eq(1);
350
- expect(objects[1].foo).to.be.eq(2);
351
- expect(objects[2].foo).to.be.eq(3);
352
- expect(objects[3].foo).to.be.eq(4);
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
- it('does not throw an error if a nested field does not exist', function () {
356
- const objects = [
357
- {foo: 1},
358
- {foo: 2, bar: undefined},
359
- {foo: 3, bar: {baz: undefined}},
360
- {foo: 4, bar: {baz: 1}},
361
- ];
362
- S.sort(objects, 'bar.baz');
363
- expect(objects).to.have.length(4);
364
- expect(objects[0].foo).to.be.eq(1);
365
- expect(objects[1].foo).to.be.eq(2);
366
- expect(objects[2].foo).to.be.eq(3);
367
- expect(objects[3].foo).to.be.eq(4);
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
- it('throws an error if a given property is not a string', function () {
371
- const throwable = () => S.sort([], 10);
372
- expect(throwable).to.throw(
373
- 'The provided option "order" should be a String ' +
374
- 'or an Array of String, but 10 given.',
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
- it('requires a non-empty string or an array of non-empty strings', function () {
381
- const validate = v => () => OrderClauseTool.validateOrderClause(v);
382
- const error = v =>
383
- format(
384
- 'The provided option "order" should be a non-empty String ' +
385
- 'or an Array of String, but %s given.',
386
- v,
387
- );
388
- expect(validate(10)).to.throw(error('10'));
389
- expect(validate(true)).to.throw(error('true'));
390
- expect(validate({})).to.throw(error('Object'));
391
- expect(validate([''])).to.throw(error('""'));
392
- expect(validate([10])).to.throw(error('10'));
393
- expect(validate([true])).to.throw(error('true'));
394
- expect(validate([false])).to.throw(error('false'));
395
- expect(validate([undefined])).to.throw(error('undefined'));
396
- expect(validate([null])).to.throw(error('null'));
397
- validate('')();
398
- validate(false)();
399
- validate(undefined)();
400
- validate(null)();
401
- validate('foo')();
402
- validate(['foo'])();
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
- it('returns an array of strings', function () {
408
- const fn = OrderClauseTool.normalizeOrderClause;
409
- expect(fn('foo')).to.be.eql(['foo']);
410
- expect(fn(['foo'])).to.be.eql(['foo']);
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
- it('requires a non-empty string or an array of non-empty strings', function () {
414
- const fn = clause => () => OrderClauseTool.normalizeOrderClause(clause);
415
- const error = v =>
416
- format(
417
- 'The provided option "order" should be a non-empty String ' +
418
- 'or an Array of String, but %s given.',
419
- v,
420
- );
421
- expect(fn(10)).to.throw(error('10'));
422
- expect(fn(true)).to.throw(error('true'));
423
- expect(fn({})).to.throw(error('Object'));
424
- expect(fn([''])).to.throw(error('""'));
425
- expect(fn([10])).to.throw(error('10'));
426
- expect(fn([true])).to.throw(error('true'));
427
- expect(fn([false])).to.throw(error('false'));
428
- expect(fn([undefined])).to.throw(error('undefined'));
429
- expect(fn([null])).to.throw(error('null'));
430
- expect(fn('')()).to.be.undefined;
431
- expect(fn(false)()).to.be.undefined;
432
- expect(fn(undefined)()).to.be.undefined;
433
- expect(fn(null)()).to.be.undefined;
434
- expect(fn('foo')()).to.be.eql(['foo']);
435
- expect(fn(['foo'])()).to.be.eql(['foo']);
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
  });