@feathersjs/adapter-tests 5.0.0-pre.3 → 5.0.0-pre.31
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 +108 -130
- 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 +24 -6
- package/lib/index.js.map +1 -1
- package/lib/methods.d.ts +2 -1
- package/lib/methods.js +224 -140
- package/lib/methods.js.map +1 -1
- package/lib/syntax.d.ts +2 -1
- package/lib/syntax.js +117 -94
- package/lib/syntax.js.map +1 -1
- package/package.json +17 -14
- package/src/basic.ts +51 -30
- package/src/declarations.ts +90 -0
- package/src/index.ts +36 -28
- package/src/methods.ts +438 -334
- package/src/syntax.ts +180 -142
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,79 @@ 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) => ({
|
|
148
|
+
name: `name-${i}`,
|
|
149
|
+
age: 3,
|
|
150
|
+
created: true
|
|
151
|
+
})));
|
|
152
|
+
assert_1.default.strictEqual(createdItems.length, count, `created ${count} items`);
|
|
153
|
+
const foundItems = await service.find({ paginate: false });
|
|
154
|
+
assert_1.default.strictEqual(foundItems.length, count, `created ${count} items`);
|
|
155
|
+
const foundPaginatedItems = await service.find({});
|
|
156
|
+
assert_1.default.strictEqual(foundPaginatedItems.data.length, defaultPaginate, 'found paginated items');
|
|
157
|
+
const allItems = await service.remove(null, {
|
|
158
|
+
query: { created: true }
|
|
159
|
+
});
|
|
160
|
+
assert_1.default.strictEqual(allItems.length, count, `removed all ${count} items`);
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
await service.remove(null, {
|
|
164
|
+
query: { created: true },
|
|
165
|
+
paginate: false
|
|
166
|
+
});
|
|
167
|
+
service.options.multi = multiBefore;
|
|
168
|
+
service.options.paginate = paginateBefore;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
test('.remove + id + query id', async () => {
|
|
172
|
+
const alice = await service.create({
|
|
140
173
|
name: 'Alice',
|
|
141
174
|
age: 12
|
|
142
175
|
});
|
|
143
176
|
try {
|
|
144
|
-
|
|
177
|
+
await service.remove(doug[idProp], {
|
|
145
178
|
query: { [idProp]: alice[idProp] }
|
|
146
179
|
});
|
|
147
180
|
throw new Error('Should never get here');
|
|
@@ -149,34 +182,34 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
149
182
|
catch (error) {
|
|
150
183
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
151
184
|
}
|
|
152
|
-
|
|
153
|
-
})
|
|
185
|
+
await service.remove(alice[idProp]);
|
|
186
|
+
});
|
|
154
187
|
});
|
|
155
188
|
describe('update', () => {
|
|
156
|
-
test('.update', () =>
|
|
189
|
+
test('.update', async () => {
|
|
157
190
|
const originalData = { [idProp]: doug[idProp], name: 'Dougler' };
|
|
158
191
|
const originalCopy = Object.assign({}, originalData);
|
|
159
|
-
const data =
|
|
192
|
+
const data = await service.update(doug[idProp], originalData);
|
|
160
193
|
assert_1.default.deepStrictEqual(originalData, originalCopy, 'data was not modified');
|
|
161
194
|
assert_1.default.strictEqual(data[idProp].toString(), doug[idProp].toString(), `${idProp} id matches`);
|
|
162
195
|
assert_1.default.strictEqual(data.name, 'Dougler', 'data.name matches');
|
|
163
196
|
assert_1.default.ok(!data.age, 'data.age is falsy');
|
|
164
|
-
})
|
|
165
|
-
test('.update + $select', () =>
|
|
197
|
+
});
|
|
198
|
+
test('.update + $select', async () => {
|
|
166
199
|
const originalData = {
|
|
167
200
|
[idProp]: doug[idProp],
|
|
168
201
|
name: 'Dougler',
|
|
169
202
|
age: 10
|
|
170
203
|
};
|
|
171
|
-
const data =
|
|
204
|
+
const data = await service.update(doug[idProp], originalData, {
|
|
172
205
|
query: { $select: ['name'] }
|
|
173
206
|
});
|
|
174
207
|
assert_1.default.strictEqual(data.name, 'Dougler', 'data.name matches');
|
|
175
208
|
assert_1.default.ok(!data.age, 'data.age is falsy');
|
|
176
|
-
})
|
|
177
|
-
test('.update + id + query', () =>
|
|
209
|
+
});
|
|
210
|
+
test('.update + id + query', async () => {
|
|
178
211
|
try {
|
|
179
|
-
|
|
212
|
+
await service.update(doug[idProp], {
|
|
180
213
|
name: 'Dougler'
|
|
181
214
|
}, {
|
|
182
215
|
query: { name: 'Tester' }
|
|
@@ -186,34 +219,36 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
186
219
|
catch (error) {
|
|
187
220
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
188
221
|
}
|
|
189
|
-
})
|
|
190
|
-
test('.update + NotFound', () =>
|
|
222
|
+
});
|
|
223
|
+
test('.update + NotFound', async () => {
|
|
191
224
|
try {
|
|
192
|
-
|
|
225
|
+
await service.update('568225fbfe21222432e836ff', {
|
|
226
|
+
name: 'NotFound'
|
|
227
|
+
});
|
|
193
228
|
throw new Error('Should never get here');
|
|
194
229
|
}
|
|
195
230
|
catch (error) {
|
|
196
231
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
197
232
|
}
|
|
198
|
-
})
|
|
199
|
-
test('.update + query + NotFound', () =>
|
|
200
|
-
const dave =
|
|
233
|
+
});
|
|
234
|
+
test('.update + query + NotFound', async () => {
|
|
235
|
+
const dave = await service.create({ name: 'Dave' });
|
|
201
236
|
try {
|
|
202
|
-
|
|
237
|
+
await service.update(dave[idProp], { name: 'UpdatedDave' }, { query: { name: 'NotDave' } });
|
|
203
238
|
throw new Error('Should never get here');
|
|
204
239
|
}
|
|
205
240
|
catch (error) {
|
|
206
241
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
207
242
|
}
|
|
208
|
-
|
|
209
|
-
})
|
|
210
|
-
test('.update + id + query id', () =>
|
|
211
|
-
const alice =
|
|
243
|
+
await service.remove(dave[idProp]);
|
|
244
|
+
});
|
|
245
|
+
test('.update + id + query id', async () => {
|
|
246
|
+
const alice = await service.create({
|
|
212
247
|
name: 'Alice',
|
|
213
248
|
age: 12
|
|
214
249
|
});
|
|
215
250
|
try {
|
|
216
|
-
|
|
251
|
+
await service.update(doug[idProp], {
|
|
217
252
|
name: 'Dougler',
|
|
218
253
|
age: 33
|
|
219
254
|
}, {
|
|
@@ -224,30 +259,30 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
224
259
|
catch (error) {
|
|
225
260
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
226
261
|
}
|
|
227
|
-
|
|
228
|
-
})
|
|
262
|
+
await service.remove(alice[idProp]);
|
|
263
|
+
});
|
|
229
264
|
});
|
|
230
265
|
describe('patch', () => {
|
|
231
|
-
test('.patch', () =>
|
|
266
|
+
test('.patch', async () => {
|
|
232
267
|
const originalData = { [idProp]: doug[idProp], name: 'PatchDoug' };
|
|
233
268
|
const originalCopy = Object.assign({}, originalData);
|
|
234
|
-
const data =
|
|
269
|
+
const data = await service.patch(doug[idProp], originalData);
|
|
235
270
|
assert_1.default.deepStrictEqual(originalData, originalCopy, 'original data was not modified');
|
|
236
271
|
assert_1.default.strictEqual(data[idProp].toString(), doug[idProp].toString(), `${idProp} id matches`);
|
|
237
272
|
assert_1.default.strictEqual(data.name, 'PatchDoug', 'data.name matches');
|
|
238
273
|
assert_1.default.strictEqual(data.age, 32, 'data.age matches');
|
|
239
|
-
})
|
|
240
|
-
test('.patch + $select', () =>
|
|
274
|
+
});
|
|
275
|
+
test('.patch + $select', async () => {
|
|
241
276
|
const originalData = { [idProp]: doug[idProp], name: 'PatchDoug' };
|
|
242
|
-
const data =
|
|
277
|
+
const data = await service.patch(doug[idProp], originalData, {
|
|
243
278
|
query: { $select: ['name'] }
|
|
244
279
|
});
|
|
245
280
|
assert_1.default.strictEqual(data.name, 'PatchDoug', 'data.name matches');
|
|
246
281
|
assert_1.default.ok(!data.age, 'data.age is falsy');
|
|
247
|
-
})
|
|
248
|
-
test('.patch + id + query', () =>
|
|
282
|
+
});
|
|
283
|
+
test('.patch + id + query', async () => {
|
|
249
284
|
try {
|
|
250
|
-
|
|
285
|
+
await service.patch(doug[idProp], {
|
|
251
286
|
name: 'id patched doug'
|
|
252
287
|
}, {
|
|
253
288
|
query: { name: 'Tester' }
|
|
@@ -257,10 +292,10 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
257
292
|
catch (error) {
|
|
258
293
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
259
294
|
}
|
|
260
|
-
})
|
|
261
|
-
test('.patch multiple', () =>
|
|
295
|
+
});
|
|
296
|
+
test('.patch multiple', async () => {
|
|
262
297
|
try {
|
|
263
|
-
|
|
298
|
+
await service.patch(null, {});
|
|
264
299
|
throw new Error('Should never get here');
|
|
265
300
|
}
|
|
266
301
|
catch (error) {
|
|
@@ -269,101 +304,150 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
269
304
|
const params = {
|
|
270
305
|
query: { created: true }
|
|
271
306
|
};
|
|
272
|
-
const dave =
|
|
307
|
+
const dave = await service.create({
|
|
273
308
|
name: 'Dave',
|
|
274
309
|
age: 29,
|
|
275
310
|
created: true
|
|
276
311
|
});
|
|
277
|
-
const david =
|
|
312
|
+
const david = await service.create({
|
|
278
313
|
name: 'David',
|
|
279
314
|
age: 3,
|
|
280
315
|
created: true
|
|
281
316
|
});
|
|
282
317
|
service.options.multi = ['patch'];
|
|
283
|
-
const data =
|
|
318
|
+
const data = await service.patch(null, {
|
|
284
319
|
age: 2
|
|
285
320
|
}, params);
|
|
286
321
|
assert_1.default.strictEqual(data.length, 2, 'returned two entries');
|
|
287
322
|
assert_1.default.strictEqual(data[0].age, 2, 'First entry age was updated');
|
|
288
323
|
assert_1.default.strictEqual(data[1].age, 2, 'Second entry age was updated');
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
})
|
|
292
|
-
test('.patch
|
|
324
|
+
await service.remove(dave[idProp]);
|
|
325
|
+
await service.remove(david[idProp]);
|
|
326
|
+
});
|
|
327
|
+
test('.patch multiple no pagination', async () => {
|
|
328
|
+
try {
|
|
329
|
+
await service.remove(doug[idProp]);
|
|
330
|
+
}
|
|
331
|
+
catch (error) { }
|
|
332
|
+
const count = 14;
|
|
333
|
+
const defaultPaginate = 10;
|
|
334
|
+
assert_1.default.ok(count > defaultPaginate, 'count is bigger than default pagination');
|
|
335
|
+
const multiBefore = service.options.multi;
|
|
336
|
+
const paginateBefore = service.options.paginate;
|
|
337
|
+
let ids;
|
|
338
|
+
try {
|
|
339
|
+
service.options.multi = true;
|
|
340
|
+
service.options.paginate = {
|
|
341
|
+
default: defaultPaginate,
|
|
342
|
+
max: 100
|
|
343
|
+
};
|
|
344
|
+
const emptyItems = await service.find({ paginate: false });
|
|
345
|
+
assert_1.default.strictEqual(emptyItems.length, 0, 'no items before');
|
|
346
|
+
const createdItems = await service.create(Array.from(Array(count)).map((_, i) => ({
|
|
347
|
+
name: `name-${i}`,
|
|
348
|
+
age: 3,
|
|
349
|
+
created: true
|
|
350
|
+
})));
|
|
351
|
+
assert_1.default.strictEqual(createdItems.length, count, `created ${count} items`);
|
|
352
|
+
ids = createdItems.map((item) => item[idProp]);
|
|
353
|
+
const foundItems = await service.find({ paginate: false });
|
|
354
|
+
assert_1.default.strictEqual(foundItems.length, count, `created ${count} items`);
|
|
355
|
+
const foundPaginatedItems = await service.find({});
|
|
356
|
+
assert_1.default.strictEqual(foundPaginatedItems.data.length, defaultPaginate, 'found paginated data');
|
|
357
|
+
const allItems = await service.patch(null, { age: 4 }, { query: { created: true } });
|
|
358
|
+
assert_1.default.strictEqual(allItems.length, count, `patched all ${count} items`);
|
|
359
|
+
}
|
|
360
|
+
finally {
|
|
361
|
+
service.options.multi = multiBefore;
|
|
362
|
+
service.options.paginate = paginateBefore;
|
|
363
|
+
if (ids) {
|
|
364
|
+
await Promise.all(ids.map((id) => service.remove(id)));
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
});
|
|
368
|
+
test('.patch multi query same', async () => {
|
|
293
369
|
const service = app.service(serviceName);
|
|
370
|
+
const multiBefore = service.options.multi;
|
|
371
|
+
service.options.multi = true;
|
|
294
372
|
const params = {
|
|
295
373
|
query: { age: { $lt: 10 } }
|
|
296
374
|
};
|
|
297
|
-
const dave =
|
|
375
|
+
const dave = await service.create({
|
|
298
376
|
name: 'Dave',
|
|
299
377
|
age: 8,
|
|
300
378
|
created: true
|
|
301
379
|
});
|
|
302
|
-
const david =
|
|
380
|
+
const david = await service.create({
|
|
303
381
|
name: 'David',
|
|
304
382
|
age: 4,
|
|
305
383
|
created: true
|
|
306
384
|
});
|
|
307
|
-
const data =
|
|
385
|
+
const data = await service.patch(null, {
|
|
308
386
|
age: 2
|
|
309
387
|
}, params);
|
|
310
388
|
assert_1.default.strictEqual(data.length, 2, 'returned two entries');
|
|
311
389
|
assert_1.default.strictEqual(data[0].age, 2, 'First entry age was updated');
|
|
312
390
|
assert_1.default.strictEqual(data[1].age, 2, 'Second entry age was updated');
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
391
|
+
await service.remove(dave[idProp]);
|
|
392
|
+
await service.remove(david[idProp]);
|
|
393
|
+
service.options.multi = multiBefore;
|
|
394
|
+
});
|
|
395
|
+
test('.patch multi query changed', async () => {
|
|
317
396
|
const service = app.service(serviceName);
|
|
397
|
+
const multiBefore = service.options.multi;
|
|
398
|
+
service.options.multi = true;
|
|
318
399
|
const params = {
|
|
319
400
|
query: { age: 10 }
|
|
320
401
|
};
|
|
321
|
-
const dave =
|
|
402
|
+
const dave = await service.create({
|
|
322
403
|
name: 'Dave',
|
|
323
404
|
age: 10,
|
|
324
405
|
created: true
|
|
325
406
|
});
|
|
326
|
-
const david =
|
|
407
|
+
const david = await service.create({
|
|
327
408
|
name: 'David',
|
|
328
409
|
age: 10,
|
|
329
410
|
created: true
|
|
330
411
|
});
|
|
331
|
-
const data =
|
|
412
|
+
const data = await service.patch(null, {
|
|
332
413
|
age: 2
|
|
333
414
|
}, params);
|
|
334
415
|
assert_1.default.strictEqual(data.length, 2, 'returned two entries');
|
|
335
416
|
assert_1.default.strictEqual(data[0].age, 2, 'First entry age was updated');
|
|
336
417
|
assert_1.default.strictEqual(data[1].age, 2, 'Second entry age was updated');
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
418
|
+
await service.remove(dave[idProp]);
|
|
419
|
+
await service.remove(david[idProp]);
|
|
420
|
+
service.options.multi = multiBefore;
|
|
421
|
+
});
|
|
422
|
+
test('.patch + NotFound', async () => {
|
|
341
423
|
try {
|
|
342
|
-
|
|
424
|
+
await service.patch('568225fbfe21222432e836ff', {
|
|
425
|
+
name: 'PatchDoug'
|
|
426
|
+
});
|
|
343
427
|
throw new Error('Should never get here');
|
|
344
428
|
}
|
|
345
429
|
catch (error) {
|
|
346
430
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
347
431
|
}
|
|
348
|
-
})
|
|
349
|
-
test('.patch + query + NotFound', () =>
|
|
350
|
-
const dave =
|
|
432
|
+
});
|
|
433
|
+
test('.patch + query + NotFound', async () => {
|
|
434
|
+
const dave = await service.create({ name: 'Dave' });
|
|
351
435
|
try {
|
|
352
|
-
|
|
436
|
+
await service.patch(dave[idProp], { name: 'PatchedDave' }, { query: { name: 'NotDave' } });
|
|
353
437
|
throw new Error('Should never get here');
|
|
354
438
|
}
|
|
355
439
|
catch (error) {
|
|
356
440
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Error is a NotFound Feathers error');
|
|
357
441
|
}
|
|
358
|
-
|
|
359
|
-
})
|
|
360
|
-
test('.patch + id + query id', () =>
|
|
361
|
-
const alice =
|
|
442
|
+
await service.remove(dave[idProp]);
|
|
443
|
+
});
|
|
444
|
+
test('.patch + id + query id', async () => {
|
|
445
|
+
const alice = await service.create({
|
|
362
446
|
name: 'Alice',
|
|
363
447
|
age: 12
|
|
364
448
|
});
|
|
365
449
|
try {
|
|
366
|
-
|
|
450
|
+
await service.patch(doug[idProp], {
|
|
367
451
|
age: 33
|
|
368
452
|
}, {
|
|
369
453
|
query: { [idProp]: alice[idProp] }
|
|
@@ -373,37 +457,37 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
373
457
|
catch (error) {
|
|
374
458
|
assert_1.default.strictEqual(error.name, 'NotFound', 'Got a NotFound Feathers error');
|
|
375
459
|
}
|
|
376
|
-
|
|
377
|
-
})
|
|
460
|
+
await service.remove(alice[idProp]);
|
|
461
|
+
});
|
|
378
462
|
});
|
|
379
463
|
describe('create', () => {
|
|
380
|
-
test('.create', () =>
|
|
464
|
+
test('.create', async () => {
|
|
381
465
|
const originalData = {
|
|
382
466
|
name: 'Bill',
|
|
383
467
|
age: 40
|
|
384
468
|
};
|
|
385
469
|
const originalCopy = Object.assign({}, originalData);
|
|
386
|
-
const data =
|
|
470
|
+
const data = await service.create(originalData);
|
|
387
471
|
assert_1.default.deepStrictEqual(originalData, originalCopy, 'original data was not modified');
|
|
388
472
|
assert_1.default.ok(data instanceof Object, 'data is an object');
|
|
389
473
|
assert_1.default.strictEqual(data.name, 'Bill', 'data.name matches');
|
|
390
|
-
|
|
391
|
-
})
|
|
392
|
-
test('.create + $select', () =>
|
|
474
|
+
await service.remove(data[idProp]);
|
|
475
|
+
});
|
|
476
|
+
test('.create + $select', async () => {
|
|
393
477
|
const originalData = {
|
|
394
478
|
name: 'William',
|
|
395
479
|
age: 23
|
|
396
480
|
};
|
|
397
|
-
const data =
|
|
481
|
+
const data = await service.create(originalData, {
|
|
398
482
|
query: { $select: ['name'] }
|
|
399
483
|
});
|
|
400
484
|
assert_1.default.strictEqual(data.name, 'William', 'data.name matches');
|
|
401
485
|
assert_1.default.ok(!data.age, 'data.age is falsy');
|
|
402
|
-
|
|
403
|
-
})
|
|
404
|
-
test('.create multi', () =>
|
|
486
|
+
await service.remove(data[idProp]);
|
|
487
|
+
});
|
|
488
|
+
test('.create multi', async () => {
|
|
405
489
|
try {
|
|
406
|
-
|
|
490
|
+
await service.create([], {});
|
|
407
491
|
throw new Error('Should never get here');
|
|
408
492
|
}
|
|
409
493
|
catch (error) {
|
|
@@ -420,17 +504,17 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
420
504
|
}
|
|
421
505
|
];
|
|
422
506
|
service.options.multi = ['create', 'patch'];
|
|
423
|
-
const data =
|
|
507
|
+
const data = await service.create(items);
|
|
424
508
|
assert_1.default.ok(Array.isArray(data), 'data is an array');
|
|
425
509
|
assert_1.default.ok(typeof data[0][idProp] !== 'undefined', 'id is set');
|
|
426
510
|
assert_1.default.strictEqual(data[0].name, 'Gerald', 'first name matches');
|
|
427
511
|
assert_1.default.ok(typeof data[1][idProp] !== 'undefined', 'id is set');
|
|
428
512
|
assert_1.default.strictEqual(data[1].name, 'Herald', 'second name macthes');
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
})
|
|
513
|
+
await service.remove(data[0][idProp]);
|
|
514
|
+
await service.remove(data[1][idProp]);
|
|
515
|
+
});
|
|
432
516
|
});
|
|
433
|
-
describe(
|
|
517
|
+
describe("doesn't call public methods internally", () => {
|
|
434
518
|
let throwing;
|
|
435
519
|
before(() => {
|
|
436
520
|
throwing = Object.assign(Object.create(app.service(serviceName)), {
|
|
@@ -459,13 +543,13 @@ exports.default = (test, app, _errors, serviceName, idProp) => {
|
|
|
459
543
|
});
|
|
460
544
|
test('internal .find', () => app.service(serviceName).find.call(throwing));
|
|
461
545
|
test('internal .get', () => service.get.call(throwing, doug[idProp]));
|
|
462
|
-
test('internal .create', () =>
|
|
463
|
-
const bob =
|
|
546
|
+
test('internal .create', async () => {
|
|
547
|
+
const bob = await service.create.call(throwing, {
|
|
464
548
|
name: 'Bob',
|
|
465
549
|
age: 25
|
|
466
550
|
});
|
|
467
|
-
|
|
468
|
-
})
|
|
551
|
+
await service.remove(bob[idProp]);
|
|
552
|
+
});
|
|
469
553
|
test('internal .update', () => service.update.call(throwing, doug[idProp], {
|
|
470
554
|
name: 'Dougler'
|
|
471
555
|
}));
|