@feathersjs/adapter-tests 5.0.0-pre.2 → 5.0.0-pre.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 +179 -9
- package/LICENSE +1 -1
- package/README.md +2 -2
- package/lib/basic.d.ts +2 -1
- package/lib/basic.js +18 -0
- 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 +4 -2
- package/lib/index.js +23 -5
- package/lib/index.js.map +1 -1
- package/lib/methods.d.ts +2 -1
- package/lib/methods.js +206 -139
- package/lib/methods.js.map +1 -1
- package/lib/syntax.d.ts +2 -1
- package/lib/syntax.js +116 -90
- package/lib/syntax.js.map +1 -1
- package/package.json +15 -13
- package/src/basic.ts +26 -1
- package/src/declarations.ts +90 -0
- package/src/index.ts +12 -6
- package/src/methods.ts +127 -18
- package/src/syntax.ts +42 -1
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,23 @@ 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 + id + query id', () =>
|
|
69
|
-
const alice =
|
|
58
|
+
});
|
|
59
|
+
test('.get + id + query id', async () => {
|
|
60
|
+
const alice = await service.create({
|
|
70
61
|
name: 'Alice',
|
|
71
62
|
age: 12
|
|
72
63
|
});
|
|
73
64
|
try {
|
|
74
|
-
|
|
65
|
+
await service.get(doug[idProp], {
|
|
75
66
|
query: { [idProp]: alice[idProp] }
|
|
76
67
|
});
|
|
77
68
|
throw new Error('Should never get here');
|
|
@@ -79,31 +70,31 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
79
70
|
catch (error) {
|
|
80
71
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
81
72
|
}
|
|
82
|
-
|
|
83
|
-
})
|
|
73
|
+
await service.remove(alice[idProp]);
|
|
74
|
+
});
|
|
84
75
|
});
|
|
85
76
|
describe('find', () => {
|
|
86
|
-
test('.find', () =>
|
|
87
|
-
const data =
|
|
77
|
+
test('.find', async () => {
|
|
78
|
+
const data = await service.find();
|
|
88
79
|
assert_1.default.ok(Array.isArray(data), 'Data is an array');
|
|
89
80
|
assert_1.default.strictEqual(data.length, 1, 'Got one entry');
|
|
90
|
-
})
|
|
81
|
+
});
|
|
91
82
|
});
|
|
92
83
|
describe('remove', () => {
|
|
93
|
-
test('.remove', () =>
|
|
94
|
-
const data =
|
|
84
|
+
test('.remove', async () => {
|
|
85
|
+
const data = await service.remove(doug[idProp]);
|
|
95
86
|
assert_1.default.strictEqual(data.name, 'Doug', 'data.name matches');
|
|
96
|
-
})
|
|
97
|
-
test('.remove + $select', () =>
|
|
98
|
-
const data =
|
|
87
|
+
});
|
|
88
|
+
test('.remove + $select', async () => {
|
|
89
|
+
const data = await service.remove(doug[idProp], {
|
|
99
90
|
query: { $select: ['name'] }
|
|
100
91
|
});
|
|
101
92
|
assert_1.default.strictEqual(data.name, 'Doug', 'data.name matches');
|
|
102
93
|
assert_1.default.ok(!data.age, 'data.age is falsy');
|
|
103
|
-
})
|
|
104
|
-
test('.remove + id + query', () =>
|
|
94
|
+
});
|
|
95
|
+
test('.remove + id + query', async () => {
|
|
105
96
|
try {
|
|
106
|
-
|
|
97
|
+
await service.remove(doug[idProp], {
|
|
107
98
|
query: { name: 'Tester' }
|
|
108
99
|
});
|
|
109
100
|
throw new Error('Should never get here');
|
|
@@ -111,37 +102,70 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
111
102
|
catch (error) {
|
|
112
103
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
113
104
|
}
|
|
114
|
-
})
|
|
115
|
-
test('.remove + multi', () =>
|
|
105
|
+
});
|
|
106
|
+
test('.remove + multi', async () => {
|
|
116
107
|
try {
|
|
117
|
-
|
|
108
|
+
await service.remove(null);
|
|
118
109
|
throw new Error('Should never get here');
|
|
119
110
|
}
|
|
120
111
|
catch (error) {
|
|
121
112
|
assert_1.default.strictEqual(error.name, 'MethodNotAllowed', 'Removing multiple without option set throws MethodNotAllowed');
|
|
122
113
|
}
|
|
123
114
|
service.options.multi = ['remove'];
|
|
124
|
-
|
|
125
|
-
|
|
115
|
+
await service.create({ name: 'Dave', age: 29, created: true });
|
|
116
|
+
await service.create({
|
|
126
117
|
name: 'David',
|
|
127
118
|
age: 3,
|
|
128
119
|
created: true
|
|
129
120
|
});
|
|
130
|
-
const data =
|
|
121
|
+
const data = await service.remove(null, {
|
|
131
122
|
query: { created: true }
|
|
132
123
|
});
|
|
133
124
|
assert_1.default.strictEqual(data.length, 2);
|
|
134
125
|
const names = data.map((person) => person.name);
|
|
135
126
|
assert_1.default.ok(names.includes('Dave'), 'Dave removed');
|
|
136
127
|
assert_1.default.ok(names.includes('David'), 'David removed');
|
|
137
|
-
})
|
|
138
|
-
test('.remove +
|
|
139
|
-
|
|
128
|
+
});
|
|
129
|
+
test('.remove + multi no pagination', async () => {
|
|
130
|
+
try {
|
|
131
|
+
await service.remove(doug[idProp]);
|
|
132
|
+
}
|
|
133
|
+
catch (error) { }
|
|
134
|
+
const count = 14;
|
|
135
|
+
const defaultPaginate = 10;
|
|
136
|
+
assert_1.default.ok(count > defaultPaginate, 'count is bigger than default pagination');
|
|
137
|
+
const multiBefore = service.options.multi;
|
|
138
|
+
const paginateBefore = service.options.paginate;
|
|
139
|
+
try {
|
|
140
|
+
service.options.multi = true;
|
|
141
|
+
service.options.paginate = {
|
|
142
|
+
'default': defaultPaginate,
|
|
143
|
+
'max': 100
|
|
144
|
+
};
|
|
145
|
+
const emptyItems = await service.find({ paginate: false });
|
|
146
|
+
assert_1.default.strictEqual(emptyItems.length, 0, 'no items before');
|
|
147
|
+
const createdItems = await service.create(Array.from(Array(count)).map((_, i) => ({ name: `name-${i}`, age: 3, created: true })));
|
|
148
|
+
assert_1.default.strictEqual(createdItems.length, count, `created ${count} items`);
|
|
149
|
+
const foundItems = await service.find({ paginate: false });
|
|
150
|
+
assert_1.default.strictEqual(foundItems.length, count, `created ${count} items`);
|
|
151
|
+
const foundPaginatedItems = await service.find({});
|
|
152
|
+
assert_1.default.strictEqual(foundPaginatedItems.data.length, defaultPaginate, 'found paginated items');
|
|
153
|
+
const allItems = await service.remove(null, { query: { created: true } });
|
|
154
|
+
assert_1.default.strictEqual(allItems.length, count, `removed all ${count} items`);
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
await service.remove(null, { query: { created: true }, paginate: false });
|
|
158
|
+
service.options.multi = multiBefore;
|
|
159
|
+
service.options.paginate = paginateBefore;
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
test('.remove + id + query id', async () => {
|
|
163
|
+
const alice = await service.create({
|
|
140
164
|
name: 'Alice',
|
|
141
165
|
age: 12
|
|
142
166
|
});
|
|
143
167
|
try {
|
|
144
|
-
|
|
168
|
+
await service.remove(doug[idProp], {
|
|
145
169
|
query: { [idProp]: alice[idProp] }
|
|
146
170
|
});
|
|
147
171
|
throw new Error('Should never get here');
|
|
@@ -149,34 +173,34 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
149
173
|
catch (error) {
|
|
150
174
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
151
175
|
}
|
|
152
|
-
|
|
153
|
-
})
|
|
176
|
+
await service.remove(alice[idProp]);
|
|
177
|
+
});
|
|
154
178
|
});
|
|
155
179
|
describe('update', () => {
|
|
156
|
-
test('.update', () =>
|
|
180
|
+
test('.update', async () => {
|
|
157
181
|
const originalData = { [idProp]: doug[idProp], name: 'Dougler' };
|
|
158
182
|
const originalCopy = Object.assign({}, originalData);
|
|
159
|
-
const data =
|
|
183
|
+
const data = await service.update(doug[idProp], originalData);
|
|
160
184
|
assert_1.default.deepStrictEqual(originalData, originalCopy, 'data was not modified');
|
|
161
185
|
assert_1.default.strictEqual(data[idProp].toString(), doug[idProp].toString(), `${idProp} id matches`);
|
|
162
186
|
assert_1.default.strictEqual(data.name, 'Dougler', 'data.name matches');
|
|
163
187
|
assert_1.default.ok(!data.age, 'data.age is falsy');
|
|
164
|
-
})
|
|
165
|
-
test('.update + $select', () =>
|
|
188
|
+
});
|
|
189
|
+
test('.update + $select', async () => {
|
|
166
190
|
const originalData = {
|
|
167
191
|
[idProp]: doug[idProp],
|
|
168
192
|
name: 'Dougler',
|
|
169
193
|
age: 10
|
|
170
194
|
};
|
|
171
|
-
const data =
|
|
195
|
+
const data = await service.update(doug[idProp], originalData, {
|
|
172
196
|
query: { $select: ['name'] }
|
|
173
197
|
});
|
|
174
198
|
assert_1.default.strictEqual(data.name, 'Dougler', 'data.name matches');
|
|
175
199
|
assert_1.default.ok(!data.age, 'data.age is falsy');
|
|
176
|
-
})
|
|
177
|
-
test('.update + id + query', () =>
|
|
200
|
+
});
|
|
201
|
+
test('.update + id + query', async () => {
|
|
178
202
|
try {
|
|
179
|
-
|
|
203
|
+
await service.update(doug[idProp], {
|
|
180
204
|
name: 'Dougler'
|
|
181
205
|
}, {
|
|
182
206
|
query: { name: 'Tester' }
|
|
@@ -186,34 +210,34 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
186
210
|
catch (error) {
|
|
187
211
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
188
212
|
}
|
|
189
|
-
})
|
|
190
|
-
test('.update + NotFound', () =>
|
|
213
|
+
});
|
|
214
|
+
test('.update + NotFound', async () => {
|
|
191
215
|
try {
|
|
192
|
-
|
|
216
|
+
await service.update('568225fbfe21222432e836ff', { name: 'NotFound' });
|
|
193
217
|
throw new Error('Should never get here');
|
|
194
218
|
}
|
|
195
219
|
catch (error) {
|
|
196
220
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
197
221
|
}
|
|
198
|
-
})
|
|
199
|
-
test('.update + query + NotFound', () =>
|
|
200
|
-
const dave =
|
|
222
|
+
});
|
|
223
|
+
test('.update + query + NotFound', async () => {
|
|
224
|
+
const dave = await service.create({ name: 'Dave' });
|
|
201
225
|
try {
|
|
202
|
-
|
|
226
|
+
await service.update(dave[idProp], { name: 'UpdatedDave' }, { query: { name: 'NotDave' } });
|
|
203
227
|
throw new Error('Should never get here');
|
|
204
228
|
}
|
|
205
229
|
catch (error) {
|
|
206
230
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
207
231
|
}
|
|
208
|
-
|
|
209
|
-
})
|
|
210
|
-
test('.update + id + query id', () =>
|
|
211
|
-
const alice =
|
|
232
|
+
await service.remove(dave[idProp]);
|
|
233
|
+
});
|
|
234
|
+
test('.update + id + query id', async () => {
|
|
235
|
+
const alice = await service.create({
|
|
212
236
|
name: 'Alice',
|
|
213
237
|
age: 12
|
|
214
238
|
});
|
|
215
239
|
try {
|
|
216
|
-
|
|
240
|
+
await service.update(doug[idProp], {
|
|
217
241
|
name: 'Dougler',
|
|
218
242
|
age: 33
|
|
219
243
|
}, {
|
|
@@ -224,30 +248,30 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
224
248
|
catch (error) {
|
|
225
249
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
226
250
|
}
|
|
227
|
-
|
|
228
|
-
})
|
|
251
|
+
await service.remove(alice[idProp]);
|
|
252
|
+
});
|
|
229
253
|
});
|
|
230
254
|
describe('patch', () => {
|
|
231
|
-
test('.patch', () =>
|
|
255
|
+
test('.patch', async () => {
|
|
232
256
|
const originalData = { [idProp]: doug[idProp], name: 'PatchDoug' };
|
|
233
257
|
const originalCopy = Object.assign({}, originalData);
|
|
234
|
-
const data =
|
|
258
|
+
const data = await service.patch(doug[idProp], originalData);
|
|
235
259
|
assert_1.default.deepStrictEqual(originalData, originalCopy, 'original data was not modified');
|
|
236
260
|
assert_1.default.strictEqual(data[idProp].toString(), doug[idProp].toString(), `${idProp} id matches`);
|
|
237
261
|
assert_1.default.strictEqual(data.name, 'PatchDoug', 'data.name matches');
|
|
238
262
|
assert_1.default.strictEqual(data.age, 32, 'data.age matches');
|
|
239
|
-
})
|
|
240
|
-
test('.patch + $select', () =>
|
|
263
|
+
});
|
|
264
|
+
test('.patch + $select', async () => {
|
|
241
265
|
const originalData = { [idProp]: doug[idProp], name: 'PatchDoug' };
|
|
242
|
-
const data =
|
|
266
|
+
const data = await service.patch(doug[idProp], originalData, {
|
|
243
267
|
query: { $select: ['name'] }
|
|
244
268
|
});
|
|
245
269
|
assert_1.default.strictEqual(data.name, 'PatchDoug', 'data.name matches');
|
|
246
270
|
assert_1.default.ok(!data.age, 'data.age is falsy');
|
|
247
|
-
})
|
|
248
|
-
test('.patch + id + query', () =>
|
|
271
|
+
});
|
|
272
|
+
test('.patch + id + query', async () => {
|
|
249
273
|
try {
|
|
250
|
-
|
|
274
|
+
await service.patch(doug[idProp], {
|
|
251
275
|
name: 'id patched doug'
|
|
252
276
|
}, {
|
|
253
277
|
query: { name: 'Tester' }
|
|
@@ -257,10 +281,10 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
257
281
|
catch (error) {
|
|
258
282
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
259
283
|
}
|
|
260
|
-
})
|
|
261
|
-
test('.patch multiple', () =>
|
|
284
|
+
});
|
|
285
|
+
test('.patch multiple', async () => {
|
|
262
286
|
try {
|
|
263
|
-
|
|
287
|
+
await service.patch(null, {});
|
|
264
288
|
throw new Error('Should never get here');
|
|
265
289
|
}
|
|
266
290
|
catch (error) {
|
|
@@ -269,101 +293,144 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
269
293
|
const params = {
|
|
270
294
|
query: { created: true }
|
|
271
295
|
};
|
|
272
|
-
const dave =
|
|
296
|
+
const dave = await service.create({
|
|
273
297
|
name: 'Dave',
|
|
274
298
|
age: 29,
|
|
275
299
|
created: true
|
|
276
300
|
});
|
|
277
|
-
const david =
|
|
301
|
+
const david = await service.create({
|
|
278
302
|
name: 'David',
|
|
279
303
|
age: 3,
|
|
280
304
|
created: true
|
|
281
305
|
});
|
|
282
306
|
service.options.multi = ['patch'];
|
|
283
|
-
const data =
|
|
307
|
+
const data = await service.patch(null, {
|
|
284
308
|
age: 2
|
|
285
309
|
}, params);
|
|
286
310
|
assert_1.default.strictEqual(data.length, 2, 'returned two entries');
|
|
287
311
|
assert_1.default.strictEqual(data[0].age, 2, 'First entry age was updated');
|
|
288
312
|
assert_1.default.strictEqual(data[1].age, 2, 'Second entry age was updated');
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
})
|
|
292
|
-
test('.patch
|
|
313
|
+
await service.remove(dave[idProp]);
|
|
314
|
+
await service.remove(david[idProp]);
|
|
315
|
+
});
|
|
316
|
+
test('.patch multiple no pagination', async () => {
|
|
317
|
+
try {
|
|
318
|
+
await service.remove(doug[idProp]);
|
|
319
|
+
}
|
|
320
|
+
catch (error) { }
|
|
321
|
+
const count = 14;
|
|
322
|
+
const defaultPaginate = 10;
|
|
323
|
+
assert_1.default.ok(count > defaultPaginate, 'count is bigger than default pagination');
|
|
324
|
+
const multiBefore = service.options.multi;
|
|
325
|
+
const paginateBefore = service.options.paginate;
|
|
326
|
+
let ids;
|
|
327
|
+
try {
|
|
328
|
+
service.options.multi = true;
|
|
329
|
+
service.options.paginate = {
|
|
330
|
+
'default': defaultPaginate,
|
|
331
|
+
'max': 100
|
|
332
|
+
};
|
|
333
|
+
const emptyItems = await service.find({ paginate: false });
|
|
334
|
+
assert_1.default.strictEqual(emptyItems.length, 0, 'no items before');
|
|
335
|
+
const createdItems = await service.create(Array.from(Array(count)).map((_, i) => ({ name: `name-${i}`, age: 3, created: true })));
|
|
336
|
+
assert_1.default.strictEqual(createdItems.length, count, `created ${count} items`);
|
|
337
|
+
ids = createdItems.map((item) => item[idProp]);
|
|
338
|
+
const foundItems = await service.find({ paginate: false });
|
|
339
|
+
assert_1.default.strictEqual(foundItems.length, count, `created ${count} items`);
|
|
340
|
+
const foundPaginatedItems = await service.find({});
|
|
341
|
+
assert_1.default.strictEqual(foundPaginatedItems.data.length, defaultPaginate, 'found paginated data');
|
|
342
|
+
const allItems = await service.patch(null, { age: 4 }, { query: { created: true } });
|
|
343
|
+
assert_1.default.strictEqual(allItems.length, count, `patched all ${count} items`);
|
|
344
|
+
}
|
|
345
|
+
finally {
|
|
346
|
+
service.options.multi = multiBefore;
|
|
347
|
+
service.options.paginate = paginateBefore;
|
|
348
|
+
if (ids) {
|
|
349
|
+
await Promise.all(ids.map(id => service.remove(id)));
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
test('.patch multi query same', async () => {
|
|
293
354
|
const service = app.service(serviceName);
|
|
355
|
+
const multiBefore = service.options.multi;
|
|
356
|
+
service.options.multi = true;
|
|
294
357
|
const params = {
|
|
295
358
|
query: { age: { $lt: 10 } }
|
|
296
359
|
};
|
|
297
|
-
const dave =
|
|
360
|
+
const dave = await service.create({
|
|
298
361
|
name: 'Dave',
|
|
299
362
|
age: 8,
|
|
300
363
|
created: true
|
|
301
364
|
});
|
|
302
|
-
const david =
|
|
365
|
+
const david = await service.create({
|
|
303
366
|
name: 'David',
|
|
304
367
|
age: 4,
|
|
305
368
|
created: true
|
|
306
369
|
});
|
|
307
|
-
const data =
|
|
370
|
+
const data = await service.patch(null, {
|
|
308
371
|
age: 2
|
|
309
372
|
}, params);
|
|
310
373
|
assert_1.default.strictEqual(data.length, 2, 'returned two entries');
|
|
311
374
|
assert_1.default.strictEqual(data[0].age, 2, 'First entry age was updated');
|
|
312
375
|
assert_1.default.strictEqual(data[1].age, 2, 'Second entry age was updated');
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
376
|
+
await service.remove(dave[idProp]);
|
|
377
|
+
await service.remove(david[idProp]);
|
|
378
|
+
service.options.multi = multiBefore;
|
|
379
|
+
});
|
|
380
|
+
test('.patch multi query changed', async () => {
|
|
317
381
|
const service = app.service(serviceName);
|
|
382
|
+
const multiBefore = service.options.multi;
|
|
383
|
+
service.options.multi = true;
|
|
318
384
|
const params = {
|
|
319
385
|
query: { age: 10 }
|
|
320
386
|
};
|
|
321
|
-
const dave =
|
|
387
|
+
const dave = await service.create({
|
|
322
388
|
name: 'Dave',
|
|
323
389
|
age: 10,
|
|
324
390
|
created: true
|
|
325
391
|
});
|
|
326
|
-
const david =
|
|
392
|
+
const david = await service.create({
|
|
327
393
|
name: 'David',
|
|
328
394
|
age: 10,
|
|
329
395
|
created: true
|
|
330
396
|
});
|
|
331
|
-
const data =
|
|
397
|
+
const data = await service.patch(null, {
|
|
332
398
|
age: 2
|
|
333
399
|
}, params);
|
|
334
400
|
assert_1.default.strictEqual(data.length, 2, 'returned two entries');
|
|
335
401
|
assert_1.default.strictEqual(data[0].age, 2, 'First entry age was updated');
|
|
336
402
|
assert_1.default.strictEqual(data[1].age, 2, 'Second entry age was updated');
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
403
|
+
await service.remove(dave[idProp]);
|
|
404
|
+
await service.remove(david[idProp]);
|
|
405
|
+
service.options.multi = multiBefore;
|
|
406
|
+
});
|
|
407
|
+
test('.patch + NotFound', async () => {
|
|
341
408
|
try {
|
|
342
|
-
|
|
409
|
+
await service.patch('568225fbfe21222432e836ff', { name: 'PatchDoug' });
|
|
343
410
|
throw new Error('Should never get here');
|
|
344
411
|
}
|
|
345
412
|
catch (error) {
|
|
346
413
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
347
414
|
}
|
|
348
|
-
})
|
|
349
|
-
test('.patch + query + NotFound', () =>
|
|
350
|
-
const dave =
|
|
415
|
+
});
|
|
416
|
+
test('.patch + query + NotFound', async () => {
|
|
417
|
+
const dave = await service.create({ name: 'Dave' });
|
|
351
418
|
try {
|
|
352
|
-
|
|
419
|
+
await service.patch(dave[idProp], { name: 'PatchedDave' }, { query: { name: 'NotDave' } });
|
|
353
420
|
throw new Error('Should never get here');
|
|
354
421
|
}
|
|
355
422
|
catch (error) {
|
|
356
423
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
357
424
|
}
|
|
358
|
-
|
|
359
|
-
})
|
|
360
|
-
test('.patch + id + query id', () =>
|
|
361
|
-
const alice =
|
|
425
|
+
await service.remove(dave[idProp]);
|
|
426
|
+
});
|
|
427
|
+
test('.patch + id + query id', async () => {
|
|
428
|
+
const alice = await service.create({
|
|
362
429
|
name: 'Alice',
|
|
363
430
|
age: 12
|
|
364
431
|
});
|
|
365
432
|
try {
|
|
366
|
-
|
|
433
|
+
await service.patch(doug[idProp], {
|
|
367
434
|
age: 33
|
|
368
435
|
}, {
|
|
369
436
|
query: { [idProp]: alice[idProp] }
|
|
@@ -373,37 +440,37 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
373
440
|
catch (error) {
|
|
374
441
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
375
442
|
}
|
|
376
|
-
|
|
377
|
-
})
|
|
443
|
+
await service.remove(alice[idProp]);
|
|
444
|
+
});
|
|
378
445
|
});
|
|
379
446
|
describe('create', () => {
|
|
380
|
-
test('.create', () =>
|
|
447
|
+
test('.create', async () => {
|
|
381
448
|
const originalData = {
|
|
382
449
|
name: 'Bill',
|
|
383
450
|
age: 40
|
|
384
451
|
};
|
|
385
452
|
const originalCopy = Object.assign({}, originalData);
|
|
386
|
-
const data =
|
|
453
|
+
const data = await service.create(originalData);
|
|
387
454
|
assert_1.default.deepStrictEqual(originalData, originalCopy, 'original data was not modified');
|
|
388
455
|
assert_1.default.ok(data instanceof Object, 'data is an object');
|
|
389
456
|
assert_1.default.strictEqual(data.name, 'Bill', 'data.name matches');
|
|
390
|
-
|
|
391
|
-
})
|
|
392
|
-
test('.create + $select', () =>
|
|
457
|
+
await service.remove(data[idProp]);
|
|
458
|
+
});
|
|
459
|
+
test('.create + $select', async () => {
|
|
393
460
|
const originalData = {
|
|
394
461
|
name: 'William',
|
|
395
462
|
age: 23
|
|
396
463
|
};
|
|
397
|
-
const data =
|
|
464
|
+
const data = await service.create(originalData, {
|
|
398
465
|
query: { $select: ['name'] }
|
|
399
466
|
});
|
|
400
467
|
assert_1.default.strictEqual(data.name, 'William', 'data.name matches');
|
|
401
468
|
assert_1.default.ok(!data.age, 'data.age is falsy');
|
|
402
|
-
|
|
403
|
-
})
|
|
404
|
-
test('.create multi', () =>
|
|
469
|
+
await service.remove(data[idProp]);
|
|
470
|
+
});
|
|
471
|
+
test('.create multi', async () => {
|
|
405
472
|
try {
|
|
406
|
-
|
|
473
|
+
await service.create([], {});
|
|
407
474
|
throw new Error('Should never get here');
|
|
408
475
|
}
|
|
409
476
|
catch (error) {
|
|
@@ -420,15 +487,15 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
420
487
|
}
|
|
421
488
|
];
|
|
422
489
|
service.options.multi = ['create', 'patch'];
|
|
423
|
-
const data =
|
|
490
|
+
const data = await service.create(items);
|
|
424
491
|
assert_1.default.ok(Array.isArray(data), 'data is an array');
|
|
425
492
|
assert_1.default.ok(typeof data[0][idProp] !== 'undefined', 'id is set');
|
|
426
493
|
assert_1.default.strictEqual(data[0].name, 'Gerald', 'first name matches');
|
|
427
494
|
assert_1.default.ok(typeof data[1][idProp] !== 'undefined', 'id is set');
|
|
428
495
|
assert_1.default.strictEqual(data[1].name, 'Herald', 'second name macthes');
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
})
|
|
496
|
+
await service.remove(data[0][idProp]);
|
|
497
|
+
await service.remove(data[1][idProp]);
|
|
498
|
+
});
|
|
432
499
|
});
|
|
433
500
|
describe('doesn\'t call public methods internally', () => {
|
|
434
501
|
let throwing;
|
|
@@ -459,13 +526,13 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
459
526
|
});
|
|
460
527
|
test('internal .find', () => app.service(serviceName).find.call(throwing));
|
|
461
528
|
test('internal .get', () => service.get.call(throwing, doug[idProp]));
|
|
462
|
-
test('internal .create', () =>
|
|
463
|
-
const bob =
|
|
529
|
+
test('internal .create', async () => {
|
|
530
|
+
const bob = await service.create.call(throwing, {
|
|
464
531
|
name: 'Bob',
|
|
465
532
|
age: 25
|
|
466
533
|
});
|
|
467
|
-
|
|
468
|
-
})
|
|
534
|
+
await service.remove(bob[idProp]);
|
|
535
|
+
});
|
|
469
536
|
test('internal .update', () => service.update.call(throwing, doug[idProp], {
|
|
470
537
|
name: 'Dougler'
|
|
471
538
|
}));
|