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