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