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