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