@feathersjs/adapter-tests 4.5.16 → 4.5.20
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/CHANGELOG.md +20 -0
- package/lib/basic.d.ts +2 -1
- package/lib/basic.js.map +1 -1
- package/lib/declarations.d.ts +8 -0
- package/lib/declarations.js +3 -0
- package/lib/declarations.js.map +1 -0
- package/lib/index.d.ts +3 -1
- package/lib/index.js +21 -5
- package/lib/index.js.map +1 -1
- package/lib/methods.d.ts +2 -1
- package/lib/methods.js +293 -141
- package/lib/methods.js.map +1 -1
- package/lib/syntax.d.ts +2 -1
- package/lib/syntax.js +149 -91
- package/lib/syntax.js.map +1 -1
- package/package.json +7 -7
package/lib/methods.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -17,37 +8,37 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
17
8
|
describe(' Methods', () => {
|
|
18
9
|
let doug;
|
|
19
10
|
let service;
|
|
20
|
-
beforeEach(() =>
|
|
11
|
+
beforeEach(async () => {
|
|
21
12
|
service = app.service(serviceName);
|
|
22
|
-
doug =
|
|
13
|
+
doug = await app.service(serviceName).create({
|
|
23
14
|
name: 'Doug',
|
|
24
15
|
age: 32
|
|
25
16
|
});
|
|
26
|
-
})
|
|
27
|
-
afterEach(() =>
|
|
17
|
+
});
|
|
18
|
+
afterEach(async () => {
|
|
28
19
|
try {
|
|
29
|
-
|
|
20
|
+
await app.service(serviceName).remove(doug[idProp]);
|
|
30
21
|
}
|
|
31
22
|
catch (error) { }
|
|
32
|
-
})
|
|
23
|
+
});
|
|
33
24
|
describe('get', () => {
|
|
34
|
-
test('.get', () =>
|
|
35
|
-
const data =
|
|
25
|
+
test('.get', async () => {
|
|
26
|
+
const data = await service.get(doug[idProp]);
|
|
36
27
|
assert_1.default.strictEqual(data[idProp].toString(), doug[idProp].toString(), `${idProp} id matches`);
|
|
37
28
|
assert_1.default.strictEqual(data.name, 'Doug', 'data.name matches');
|
|
38
29
|
assert_1.default.strictEqual(data.age, 32, 'data.age matches');
|
|
39
|
-
})
|
|
40
|
-
test('.get + $select', () =>
|
|
41
|
-
const data =
|
|
30
|
+
});
|
|
31
|
+
test('.get + $select', async () => {
|
|
32
|
+
const data = await service.get(doug[idProp], {
|
|
42
33
|
query: { $select: ['name'] }
|
|
43
34
|
});
|
|
44
35
|
assert_1.default.strictEqual(data[idProp].toString(), doug[idProp].toString(), `${idProp} id property matches`);
|
|
45
36
|
assert_1.default.strictEqual(data.name, 'Doug', 'data.name matches');
|
|
46
37
|
assert_1.default.ok(!data.age, 'data.age is falsy');
|
|
47
|
-
})
|
|
48
|
-
test('.get + id + query', () =>
|
|
38
|
+
});
|
|
39
|
+
test('.get + id + query', async () => {
|
|
49
40
|
try {
|
|
50
|
-
|
|
41
|
+
await service.get(doug[idProp], {
|
|
51
42
|
query: { name: 'Tester' }
|
|
52
43
|
});
|
|
53
44
|
throw new Error('Should never get here');
|
|
@@ -55,23 +46,32 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
55
46
|
catch (error) {
|
|
56
47
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
57
48
|
}
|
|
58
|
-
})
|
|
59
|
-
test('.get + NotFound', () =>
|
|
49
|
+
});
|
|
50
|
+
test('.get + NotFound', async () => {
|
|
60
51
|
try {
|
|
61
|
-
|
|
52
|
+
await service.get('568225fbfe21222432e836ff');
|
|
62
53
|
throw new Error('Should never get here');
|
|
63
54
|
}
|
|
64
55
|
catch (error) {
|
|
65
56
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
66
57
|
}
|
|
67
|
-
})
|
|
68
|
-
test('.get +
|
|
69
|
-
|
|
58
|
+
});
|
|
59
|
+
test('.get + NotFound (integer)', async () => {
|
|
60
|
+
try {
|
|
61
|
+
await service.get(123456789);
|
|
62
|
+
throw new Error('Should never get here');
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
test('.get + id + query id', async () => {
|
|
69
|
+
const alice = await service.create({
|
|
70
70
|
name: 'Alice',
|
|
71
71
|
age: 12
|
|
72
72
|
});
|
|
73
73
|
try {
|
|
74
|
-
|
|
74
|
+
await service.get(doug[idProp], {
|
|
75
75
|
query: { [idProp]: alice[idProp] }
|
|
76
76
|
});
|
|
77
77
|
throw new Error('Should never get here');
|
|
@@ -79,31 +79,32 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
79
79
|
catch (error) {
|
|
80
80
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
81
81
|
}
|
|
82
|
-
|
|
83
|
-
})
|
|
82
|
+
await service.remove(alice[idProp]);
|
|
83
|
+
});
|
|
84
84
|
});
|
|
85
85
|
describe('find', () => {
|
|
86
|
-
test('.find', () =>
|
|
87
|
-
const data =
|
|
86
|
+
test('.find', async () => {
|
|
87
|
+
const data = await service.find();
|
|
88
88
|
assert_1.default.ok(Array.isArray(data), 'Data is an array');
|
|
89
89
|
assert_1.default.strictEqual(data.length, 1, 'Got one entry');
|
|
90
|
-
})
|
|
90
|
+
});
|
|
91
91
|
});
|
|
92
92
|
describe('remove', () => {
|
|
93
|
-
test('.remove', () =>
|
|
94
|
-
const data =
|
|
93
|
+
test('.remove', async () => {
|
|
94
|
+
const data = await service.remove(doug[idProp]);
|
|
95
95
|
assert_1.default.strictEqual(data.name, 'Doug', 'data.name matches');
|
|
96
|
-
})
|
|
97
|
-
test('.remove + $select', () =>
|
|
98
|
-
const data =
|
|
96
|
+
});
|
|
97
|
+
test('.remove + $select', async () => {
|
|
98
|
+
const data = await service.remove(doug[idProp], {
|
|
99
99
|
query: { $select: ['name'] }
|
|
100
100
|
});
|
|
101
|
+
assert_1.default.strictEqual(data[idProp].toString(), doug[idProp].toString(), `${idProp} id property matches`);
|
|
101
102
|
assert_1.default.strictEqual(data.name, 'Doug', 'data.name matches');
|
|
102
103
|
assert_1.default.ok(!data.age, 'data.age is falsy');
|
|
103
|
-
})
|
|
104
|
-
test('.remove + id + query', () =>
|
|
104
|
+
});
|
|
105
|
+
test('.remove + id + query', async () => {
|
|
105
106
|
try {
|
|
106
|
-
|
|
107
|
+
await service.remove(doug[idProp], {
|
|
107
108
|
query: { name: 'Tester' }
|
|
108
109
|
});
|
|
109
110
|
throw new Error('Should never get here');
|
|
@@ -111,37 +112,97 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
111
112
|
catch (error) {
|
|
112
113
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
113
114
|
}
|
|
114
|
-
})
|
|
115
|
-
test('.remove +
|
|
115
|
+
});
|
|
116
|
+
test('.remove + NotFound', async () => {
|
|
117
|
+
try {
|
|
118
|
+
await service.remove('568225fbfe21222432e836ff');
|
|
119
|
+
throw new Error('Should never get here');
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
test('.remove + NotFound (integer)', async () => {
|
|
126
|
+
try {
|
|
127
|
+
await service.remove(123456789);
|
|
128
|
+
throw new Error('Should never get here');
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
test('.remove + multi', async () => {
|
|
116
135
|
try {
|
|
117
|
-
|
|
136
|
+
await service.remove(null);
|
|
118
137
|
throw new Error('Should never get here');
|
|
119
138
|
}
|
|
120
139
|
catch (error) {
|
|
121
140
|
assert_1.default.strictEqual(error.name, 'MethodNotAllowed', 'Removing multiple without option set throws MethodNotAllowed');
|
|
122
141
|
}
|
|
123
142
|
service.options.multi = ['remove'];
|
|
124
|
-
|
|
125
|
-
|
|
143
|
+
await service.create({ name: 'Dave', age: 29, created: true });
|
|
144
|
+
await service.create({
|
|
126
145
|
name: 'David',
|
|
127
146
|
age: 3,
|
|
128
147
|
created: true
|
|
129
148
|
});
|
|
130
|
-
const data =
|
|
149
|
+
const data = await service.remove(null, {
|
|
131
150
|
query: { created: true }
|
|
132
151
|
});
|
|
133
152
|
assert_1.default.strictEqual(data.length, 2);
|
|
134
153
|
const names = data.map((person) => person.name);
|
|
135
154
|
assert_1.default.ok(names.includes('Dave'), 'Dave removed');
|
|
136
155
|
assert_1.default.ok(names.includes('David'), 'David removed');
|
|
137
|
-
})
|
|
138
|
-
test('.remove +
|
|
139
|
-
|
|
156
|
+
});
|
|
157
|
+
test('.remove + multi no pagination', async () => {
|
|
158
|
+
try {
|
|
159
|
+
await service.remove(doug[idProp]);
|
|
160
|
+
}
|
|
161
|
+
catch (error) { }
|
|
162
|
+
const count = 14;
|
|
163
|
+
const defaultPaginate = 10;
|
|
164
|
+
assert_1.default.ok(count > defaultPaginate, 'count is bigger than default pagination');
|
|
165
|
+
const multiBefore = service.options.multi;
|
|
166
|
+
const paginateBefore = service.options.paginate;
|
|
167
|
+
try {
|
|
168
|
+
service.options.multi = true;
|
|
169
|
+
service.options.paginate = {
|
|
170
|
+
default: defaultPaginate,
|
|
171
|
+
max: 100
|
|
172
|
+
};
|
|
173
|
+
const emptyItems = await service.find({ paginate: false });
|
|
174
|
+
assert_1.default.strictEqual(emptyItems.length, 0, 'no items before');
|
|
175
|
+
const createdItems = await service.create(Array.from(Array(count)).map((_, i) => ({
|
|
176
|
+
name: `name-${i}`,
|
|
177
|
+
age: 3,
|
|
178
|
+
created: true
|
|
179
|
+
})));
|
|
180
|
+
assert_1.default.strictEqual(createdItems.length, count, `created ${count} items`);
|
|
181
|
+
const foundItems = await service.find({ paginate: false });
|
|
182
|
+
assert_1.default.strictEqual(foundItems.length, count, `created ${count} items`);
|
|
183
|
+
const foundPaginatedItems = await service.find({});
|
|
184
|
+
assert_1.default.strictEqual(foundPaginatedItems.data.length, defaultPaginate, 'found paginated items');
|
|
185
|
+
const allItems = await service.remove(null, {
|
|
186
|
+
query: { created: true }
|
|
187
|
+
});
|
|
188
|
+
assert_1.default.strictEqual(allItems.length, count, `removed all ${count} items`);
|
|
189
|
+
}
|
|
190
|
+
finally {
|
|
191
|
+
await service.remove(null, {
|
|
192
|
+
query: { created: true },
|
|
193
|
+
paginate: false
|
|
194
|
+
});
|
|
195
|
+
service.options.multi = multiBefore;
|
|
196
|
+
service.options.paginate = paginateBefore;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
test('.remove + id + query id', async () => {
|
|
200
|
+
const alice = await service.create({
|
|
140
201
|
name: 'Alice',
|
|
141
202
|
age: 12
|
|
142
203
|
});
|
|
143
204
|
try {
|
|
144
|
-
|
|
205
|
+
await service.remove(doug[idProp], {
|
|
145
206
|
query: { [idProp]: alice[idProp] }
|
|
146
207
|
});
|
|
147
208
|
throw new Error('Should never get here');
|
|
@@ -149,34 +210,35 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
149
210
|
catch (error) {
|
|
150
211
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
151
212
|
}
|
|
152
|
-
|
|
153
|
-
})
|
|
213
|
+
await service.remove(alice[idProp]);
|
|
214
|
+
});
|
|
154
215
|
});
|
|
155
216
|
describe('update', () => {
|
|
156
|
-
test('.update', () =>
|
|
217
|
+
test('.update', async () => {
|
|
157
218
|
const originalData = { [idProp]: doug[idProp], name: 'Dougler' };
|
|
158
219
|
const originalCopy = Object.assign({}, originalData);
|
|
159
|
-
const data =
|
|
220
|
+
const data = await service.update(doug[idProp], originalData);
|
|
160
221
|
assert_1.default.deepStrictEqual(originalData, originalCopy, 'data was not modified');
|
|
161
222
|
assert_1.default.strictEqual(data[idProp].toString(), doug[idProp].toString(), `${idProp} id matches`);
|
|
162
223
|
assert_1.default.strictEqual(data.name, 'Dougler', 'data.name matches');
|
|
163
224
|
assert_1.default.ok(!data.age, 'data.age is falsy');
|
|
164
|
-
})
|
|
165
|
-
test('.update + $select', () =>
|
|
225
|
+
});
|
|
226
|
+
test('.update + $select', async () => {
|
|
166
227
|
const originalData = {
|
|
167
228
|
[idProp]: doug[idProp],
|
|
168
229
|
name: 'Dougler',
|
|
169
230
|
age: 10
|
|
170
231
|
};
|
|
171
|
-
const data =
|
|
232
|
+
const data = await service.update(doug[idProp], originalData, {
|
|
172
233
|
query: { $select: ['name'] }
|
|
173
234
|
});
|
|
235
|
+
assert_1.default.strictEqual(data[idProp].toString(), doug[idProp].toString(), `${idProp} id property matches`);
|
|
174
236
|
assert_1.default.strictEqual(data.name, 'Dougler', 'data.name matches');
|
|
175
237
|
assert_1.default.ok(!data.age, 'data.age is falsy');
|
|
176
|
-
})
|
|
177
|
-
test('.update + id + query', () =>
|
|
238
|
+
});
|
|
239
|
+
test('.update + id + query', async () => {
|
|
178
240
|
try {
|
|
179
|
-
|
|
241
|
+
await service.update(doug[idProp], {
|
|
180
242
|
name: 'Dougler'
|
|
181
243
|
}, {
|
|
182
244
|
query: { name: 'Tester' }
|
|
@@ -186,34 +248,49 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
186
248
|
catch (error) {
|
|
187
249
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
188
250
|
}
|
|
189
|
-
|
|
190
|
-
|
|
251
|
+
const updatedDoug = await service.get(doug[idProp]);
|
|
252
|
+
assert_1.default.strictEqual(updatedDoug.name, 'Doug', 'Doug was not updated');
|
|
253
|
+
});
|
|
254
|
+
test('.update + NotFound', async () => {
|
|
191
255
|
try {
|
|
192
|
-
|
|
256
|
+
await service.update('568225fbfe21222432e836ff', {
|
|
257
|
+
name: 'NotFound'
|
|
258
|
+
});
|
|
193
259
|
throw new Error('Should never get here');
|
|
194
260
|
}
|
|
195
261
|
catch (error) {
|
|
196
262
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
197
263
|
}
|
|
198
|
-
})
|
|
199
|
-
test('.update +
|
|
200
|
-
const dave = yield service.create({ name: 'Dave' });
|
|
264
|
+
});
|
|
265
|
+
test('.update + NotFound (integer)', async () => {
|
|
201
266
|
try {
|
|
202
|
-
|
|
267
|
+
await service.update(123456789, {
|
|
268
|
+
name: 'NotFound'
|
|
269
|
+
});
|
|
203
270
|
throw new Error('Should never get here');
|
|
204
271
|
}
|
|
205
272
|
catch (error) {
|
|
206
273
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
207
274
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
275
|
+
});
|
|
276
|
+
test('.update + query + NotFound', async () => {
|
|
277
|
+
const dave = await service.create({ name: 'Dave' });
|
|
278
|
+
try {
|
|
279
|
+
await service.update(dave[idProp], { name: 'UpdatedDave' }, { query: { name: 'NotDave' } });
|
|
280
|
+
throw new Error('Should never get here');
|
|
281
|
+
}
|
|
282
|
+
catch (error) {
|
|
283
|
+
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
284
|
+
}
|
|
285
|
+
await service.remove(dave[idProp]);
|
|
286
|
+
});
|
|
287
|
+
test('.update + id + query id', async () => {
|
|
288
|
+
const alice = await service.create({
|
|
212
289
|
name: 'Alice',
|
|
213
290
|
age: 12
|
|
214
291
|
});
|
|
215
292
|
try {
|
|
216
|
-
|
|
293
|
+
await service.update(doug[idProp], {
|
|
217
294
|
name: 'Dougler',
|
|
218
295
|
age: 33
|
|
219
296
|
}, {
|
|
@@ -224,30 +301,31 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
224
301
|
catch (error) {
|
|
225
302
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
226
303
|
}
|
|
227
|
-
|
|
228
|
-
})
|
|
304
|
+
await service.remove(alice[idProp]);
|
|
305
|
+
});
|
|
229
306
|
});
|
|
230
307
|
describe('patch', () => {
|
|
231
|
-
test('.patch', () =>
|
|
308
|
+
test('.patch', async () => {
|
|
232
309
|
const originalData = { [idProp]: doug[idProp], name: 'PatchDoug' };
|
|
233
310
|
const originalCopy = Object.assign({}, originalData);
|
|
234
|
-
const data =
|
|
311
|
+
const data = await service.patch(doug[idProp], originalData);
|
|
235
312
|
assert_1.default.deepStrictEqual(originalData, originalCopy, 'original data was not modified');
|
|
236
313
|
assert_1.default.strictEqual(data[idProp].toString(), doug[idProp].toString(), `${idProp} id matches`);
|
|
237
314
|
assert_1.default.strictEqual(data.name, 'PatchDoug', 'data.name matches');
|
|
238
315
|
assert_1.default.strictEqual(data.age, 32, 'data.age matches');
|
|
239
|
-
})
|
|
240
|
-
test('.patch + $select', () =>
|
|
316
|
+
});
|
|
317
|
+
test('.patch + $select', async () => {
|
|
241
318
|
const originalData = { [idProp]: doug[idProp], name: 'PatchDoug' };
|
|
242
|
-
const data =
|
|
319
|
+
const data = await service.patch(doug[idProp], originalData, {
|
|
243
320
|
query: { $select: ['name'] }
|
|
244
321
|
});
|
|
322
|
+
assert_1.default.strictEqual(data[idProp].toString(), doug[idProp].toString(), `${idProp} id property matches`);
|
|
245
323
|
assert_1.default.strictEqual(data.name, 'PatchDoug', 'data.name matches');
|
|
246
324
|
assert_1.default.ok(!data.age, 'data.age is falsy');
|
|
247
|
-
})
|
|
248
|
-
test('.patch + id + query', () =>
|
|
325
|
+
});
|
|
326
|
+
test('.patch + id + query', async () => {
|
|
249
327
|
try {
|
|
250
|
-
|
|
328
|
+
await service.patch(doug[idProp], {
|
|
251
329
|
name: 'id patched doug'
|
|
252
330
|
}, {
|
|
253
331
|
query: { name: 'Tester' }
|
|
@@ -257,10 +335,10 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
257
335
|
catch (error) {
|
|
258
336
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
259
337
|
}
|
|
260
|
-
})
|
|
261
|
-
test('.patch multiple', () =>
|
|
338
|
+
});
|
|
339
|
+
test('.patch multiple', async () => {
|
|
262
340
|
try {
|
|
263
|
-
|
|
341
|
+
await service.patch(null, {});
|
|
264
342
|
throw new Error('Should never get here');
|
|
265
343
|
}
|
|
266
344
|
catch (error) {
|
|
@@ -269,101 +347,161 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
269
347
|
const params = {
|
|
270
348
|
query: { created: true }
|
|
271
349
|
};
|
|
272
|
-
const dave =
|
|
350
|
+
const dave = await service.create({
|
|
273
351
|
name: 'Dave',
|
|
274
352
|
age: 29,
|
|
275
353
|
created: true
|
|
276
354
|
});
|
|
277
|
-
const david =
|
|
355
|
+
const david = await service.create({
|
|
278
356
|
name: 'David',
|
|
279
357
|
age: 3,
|
|
280
358
|
created: true
|
|
281
359
|
});
|
|
282
360
|
service.options.multi = ['patch'];
|
|
283
|
-
const data =
|
|
361
|
+
const data = await service.patch(null, {
|
|
284
362
|
age: 2
|
|
285
363
|
}, params);
|
|
286
364
|
assert_1.default.strictEqual(data.length, 2, 'returned two entries');
|
|
287
365
|
assert_1.default.strictEqual(data[0].age, 2, 'First entry age was updated');
|
|
288
366
|
assert_1.default.strictEqual(data[1].age, 2, 'Second entry age was updated');
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
})
|
|
292
|
-
test('.patch
|
|
367
|
+
await service.remove(dave[idProp]);
|
|
368
|
+
await service.remove(david[idProp]);
|
|
369
|
+
});
|
|
370
|
+
test('.patch multiple no pagination', async () => {
|
|
371
|
+
try {
|
|
372
|
+
await service.remove(doug[idProp]);
|
|
373
|
+
}
|
|
374
|
+
catch (error) { }
|
|
375
|
+
const count = 14;
|
|
376
|
+
const defaultPaginate = 10;
|
|
377
|
+
assert_1.default.ok(count > defaultPaginate, 'count is bigger than default pagination');
|
|
378
|
+
const multiBefore = service.options.multi;
|
|
379
|
+
const paginateBefore = service.options.paginate;
|
|
380
|
+
let ids;
|
|
381
|
+
try {
|
|
382
|
+
service.options.multi = true;
|
|
383
|
+
service.options.paginate = {
|
|
384
|
+
default: defaultPaginate,
|
|
385
|
+
max: 100
|
|
386
|
+
};
|
|
387
|
+
const emptyItems = await service.find({ paginate: false });
|
|
388
|
+
assert_1.default.strictEqual(emptyItems.length, 0, 'no items before');
|
|
389
|
+
const createdItems = await service.create(Array.from(Array(count)).map((_, i) => ({
|
|
390
|
+
name: `name-${i}`,
|
|
391
|
+
age: 3,
|
|
392
|
+
created: true
|
|
393
|
+
})));
|
|
394
|
+
assert_1.default.strictEqual(createdItems.length, count, `created ${count} items`);
|
|
395
|
+
ids = createdItems.map((item) => item[idProp]);
|
|
396
|
+
const foundItems = await service.find({ paginate: false });
|
|
397
|
+
assert_1.default.strictEqual(foundItems.length, count, `created ${count} items`);
|
|
398
|
+
const foundPaginatedItems = await service.find({});
|
|
399
|
+
assert_1.default.strictEqual(foundPaginatedItems.data.length, defaultPaginate, 'found paginated data');
|
|
400
|
+
const allItems = await service.patch(null, { age: 4 }, { query: { created: true } });
|
|
401
|
+
assert_1.default.strictEqual(allItems.length, count, `patched all ${count} items`);
|
|
402
|
+
}
|
|
403
|
+
finally {
|
|
404
|
+
service.options.multi = multiBefore;
|
|
405
|
+
service.options.paginate = paginateBefore;
|
|
406
|
+
if (ids) {
|
|
407
|
+
await Promise.all(ids.map((id) => service.remove(id)));
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
test('.patch multi query same', async () => {
|
|
293
412
|
const service = app.service(serviceName);
|
|
413
|
+
const multiBefore = service.options.multi;
|
|
414
|
+
service.options.multi = true;
|
|
294
415
|
const params = {
|
|
295
416
|
query: { age: { $lt: 10 } }
|
|
296
417
|
};
|
|
297
|
-
const dave =
|
|
418
|
+
const dave = await service.create({
|
|
298
419
|
name: 'Dave',
|
|
299
420
|
age: 8,
|
|
300
421
|
created: true
|
|
301
422
|
});
|
|
302
|
-
const david =
|
|
423
|
+
const david = await service.create({
|
|
303
424
|
name: 'David',
|
|
304
425
|
age: 4,
|
|
305
426
|
created: true
|
|
306
427
|
});
|
|
307
|
-
const data =
|
|
428
|
+
const data = await service.patch(null, {
|
|
308
429
|
age: 2
|
|
309
430
|
}, params);
|
|
310
431
|
assert_1.default.strictEqual(data.length, 2, 'returned two entries');
|
|
311
432
|
assert_1.default.strictEqual(data[0].age, 2, 'First entry age was updated');
|
|
312
433
|
assert_1.default.strictEqual(data[1].age, 2, 'Second entry age was updated');
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
434
|
+
await service.remove(dave[idProp]);
|
|
435
|
+
await service.remove(david[idProp]);
|
|
436
|
+
service.options.multi = multiBefore;
|
|
437
|
+
});
|
|
438
|
+
test('.patch multi query changed', async () => {
|
|
317
439
|
const service = app.service(serviceName);
|
|
440
|
+
const multiBefore = service.options.multi;
|
|
441
|
+
service.options.multi = true;
|
|
318
442
|
const params = {
|
|
319
443
|
query: { age: 10 }
|
|
320
444
|
};
|
|
321
|
-
const dave =
|
|
445
|
+
const dave = await service.create({
|
|
322
446
|
name: 'Dave',
|
|
323
447
|
age: 10,
|
|
324
448
|
created: true
|
|
325
449
|
});
|
|
326
|
-
const david =
|
|
450
|
+
const david = await service.create({
|
|
327
451
|
name: 'David',
|
|
328
452
|
age: 10,
|
|
329
453
|
created: true
|
|
330
454
|
});
|
|
331
|
-
const data =
|
|
455
|
+
const data = await service.patch(null, {
|
|
332
456
|
age: 2
|
|
333
457
|
}, params);
|
|
334
458
|
assert_1.default.strictEqual(data.length, 2, 'returned two entries');
|
|
335
459
|
assert_1.default.strictEqual(data[0].age, 2, 'First entry age was updated');
|
|
336
460
|
assert_1.default.strictEqual(data[1].age, 2, 'Second entry age was updated');
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
461
|
+
await service.remove(dave[idProp]);
|
|
462
|
+
await service.remove(david[idProp]);
|
|
463
|
+
service.options.multi = multiBefore;
|
|
464
|
+
});
|
|
465
|
+
test('.patch + NotFound', async () => {
|
|
341
466
|
try {
|
|
342
|
-
|
|
467
|
+
await service.patch('568225fbfe21222432e836ff', {
|
|
468
|
+
name: 'PatchDoug'
|
|
469
|
+
});
|
|
343
470
|
throw new Error('Should never get here');
|
|
344
471
|
}
|
|
345
472
|
catch (error) {
|
|
346
473
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
347
474
|
}
|
|
348
|
-
})
|
|
349
|
-
test('.patch +
|
|
350
|
-
const dave = yield service.create({ name: 'Dave' });
|
|
475
|
+
});
|
|
476
|
+
test('.patch + NotFound (integer)', async () => {
|
|
351
477
|
try {
|
|
352
|
-
|
|
478
|
+
await service.patch(123456789, {
|
|
479
|
+
name: 'PatchDoug'
|
|
480
|
+
});
|
|
353
481
|
throw new Error('Should never get here');
|
|
354
482
|
}
|
|
355
483
|
catch (error) {
|
|
356
484
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
357
485
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
486
|
+
});
|
|
487
|
+
test('.patch + query + NotFound', async () => {
|
|
488
|
+
const dave = await service.create({ name: 'Dave' });
|
|
489
|
+
try {
|
|
490
|
+
await service.patch(dave[idProp], { name: 'PatchedDave' }, { query: { name: 'NotDave' } });
|
|
491
|
+
throw new Error('Should never get here');
|
|
492
|
+
}
|
|
493
|
+
catch (error) {
|
|
494
|
+
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
495
|
+
}
|
|
496
|
+
await service.remove(dave[idProp]);
|
|
497
|
+
});
|
|
498
|
+
test('.patch + id + query id', async () => {
|
|
499
|
+
const alice = await service.create({
|
|
362
500
|
name: 'Alice',
|
|
363
501
|
age: 12
|
|
364
502
|
});
|
|
365
503
|
try {
|
|
366
|
-
|
|
504
|
+
await service.patch(doug[idProp], {
|
|
367
505
|
age: 33
|
|
368
506
|
}, {
|
|
369
507
|
query: { [idProp]: alice[idProp] }
|
|
@@ -373,37 +511,51 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
373
511
|
catch (error) {
|
|
374
512
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
375
513
|
}
|
|
376
|
-
|
|
377
|
-
})
|
|
514
|
+
await service.remove(alice[idProp]);
|
|
515
|
+
});
|
|
378
516
|
});
|
|
379
517
|
describe('create', () => {
|
|
380
|
-
test('.create', () =>
|
|
518
|
+
test('.create', async () => {
|
|
381
519
|
const originalData = {
|
|
382
520
|
name: 'Bill',
|
|
383
521
|
age: 40
|
|
384
522
|
};
|
|
385
523
|
const originalCopy = Object.assign({}, originalData);
|
|
386
|
-
const data =
|
|
524
|
+
const data = await service.create(originalData);
|
|
387
525
|
assert_1.default.deepStrictEqual(originalData, originalCopy, 'original data was not modified');
|
|
388
526
|
assert_1.default.ok(data instanceof Object, 'data is an object');
|
|
389
527
|
assert_1.default.strictEqual(data.name, 'Bill', 'data.name matches');
|
|
390
|
-
|
|
391
|
-
})
|
|
392
|
-
test('.create
|
|
528
|
+
await service.remove(data[idProp]);
|
|
529
|
+
});
|
|
530
|
+
test('.create ignores query', async () => {
|
|
531
|
+
const originalData = {
|
|
532
|
+
name: 'Billy',
|
|
533
|
+
age: 42
|
|
534
|
+
};
|
|
535
|
+
const data = await service.create(originalData, {
|
|
536
|
+
query: {
|
|
537
|
+
name: 'Dave'
|
|
538
|
+
}
|
|
539
|
+
});
|
|
540
|
+
assert_1.default.strictEqual(data.name, 'Billy', 'data.name matches');
|
|
541
|
+
await service.remove(data[idProp]);
|
|
542
|
+
});
|
|
543
|
+
test('.create + $select', async () => {
|
|
393
544
|
const originalData = {
|
|
394
545
|
name: 'William',
|
|
395
546
|
age: 23
|
|
396
547
|
};
|
|
397
|
-
const data =
|
|
548
|
+
const data = await service.create(originalData, {
|
|
398
549
|
query: { $select: ['name'] }
|
|
399
550
|
});
|
|
551
|
+
assert_1.default.ok(idProp in data, 'data has id');
|
|
400
552
|
assert_1.default.strictEqual(data.name, 'William', 'data.name matches');
|
|
401
553
|
assert_1.default.ok(!data.age, 'data.age is falsy');
|
|
402
|
-
|
|
403
|
-
})
|
|
404
|
-
test('.create multi', () =>
|
|
554
|
+
await service.remove(data[idProp]);
|
|
555
|
+
});
|
|
556
|
+
test('.create multi', async () => {
|
|
405
557
|
try {
|
|
406
|
-
|
|
558
|
+
await service.create([], {});
|
|
407
559
|
throw new Error('Should never get here');
|
|
408
560
|
}
|
|
409
561
|
catch (error) {
|
|
@@ -420,20 +572,20 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
420
572
|
}
|
|
421
573
|
];
|
|
422
574
|
service.options.multi = ['create', 'patch'];
|
|
423
|
-
const data =
|
|
575
|
+
const data = await service.create(items);
|
|
424
576
|
assert_1.default.ok(Array.isArray(data), 'data is an array');
|
|
425
577
|
assert_1.default.ok(typeof data[0][idProp] !== 'undefined', 'id is set');
|
|
426
578
|
assert_1.default.strictEqual(data[0].name, 'Gerald', 'first name matches');
|
|
427
579
|
assert_1.default.ok(typeof data[1][idProp] !== 'undefined', 'id is set');
|
|
428
580
|
assert_1.default.strictEqual(data[1].name, 'Herald', 'second name macthes');
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
})
|
|
581
|
+
await service.remove(data[0][idProp]);
|
|
582
|
+
await service.remove(data[1][idProp]);
|
|
583
|
+
});
|
|
432
584
|
});
|
|
433
|
-
describe(
|
|
585
|
+
describe("doesn't call public methods internally", () => {
|
|
434
586
|
let throwing;
|
|
435
587
|
before(() => {
|
|
436
|
-
throwing = app.service(serviceName)
|
|
588
|
+
throwing = Object.assign(Object.create(app.service(serviceName)), {
|
|
437
589
|
get store() {
|
|
438
590
|
return app.service(serviceName).store;
|
|
439
591
|
},
|
|
@@ -459,13 +611,13 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
459
611
|
});
|
|
460
612
|
test('internal .find', () => app.service(serviceName).find.call(throwing));
|
|
461
613
|
test('internal .get', () => service.get.call(throwing, doug[idProp]));
|
|
462
|
-
test('internal .create', () =>
|
|
463
|
-
const bob =
|
|
614
|
+
test('internal .create', async () => {
|
|
615
|
+
const bob = await service.create.call(throwing, {
|
|
464
616
|
name: 'Bob',
|
|
465
617
|
age: 25
|
|
466
618
|
});
|
|
467
|
-
|
|
468
|
-
})
|
|
619
|
+
await service.remove(bob[idProp]);
|
|
620
|
+
});
|
|
469
621
|
test('internal .update', () => service.update.call(throwing, doug[idProp], {
|
|
470
622
|
name: 'Dougler'
|
|
471
623
|
}));
|