-
-
Notifications
You must be signed in to change notification settings - Fork 798
Expand file tree
/
Copy pathmethods.ts
More file actions
128 lines (98 loc) · 2.96 KB
/
Copy pathmethods.ts
File metadata and controls
128 lines (98 loc) · 2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import { strict as assert } from 'assert'
import { verify } from '@feathersjs/tests'
export default (name: string, options: any) => {
const call = (method: string, ...args: any[]) =>
new Promise((resolve, reject) => {
const { socket } = options
const prefix = [method, name]
const emitArgs = prefix.concat(args)
socket.emit(...emitArgs, (error: any, result: any) => (error ? reject(error) : resolve(result)))
})
it('invalid arguments cause an error', async () => {
await assert.rejects(() => call('find', 1, {}), {
message: "Too many arguments for 'find' method"
})
})
it('.find', () => async () => {
await call('find', {}).then((data) => verify.find(data))
})
it('.get', () => async () => {
await call('get', 'laundry').then((data) => verify.get('laundry', data))
})
it('.get with error', () => async () => {
try {
await call('get', 'laundry', { error: true })
assert.fail('Should never get here')
} catch (error: any) {
assert.strictEqual(error.message, 'Something for laundry went wrong')
}
})
it('.get with runtime error', () => async () => {
try {
await call('get', 'laundry', { runtimeError: true })
assert.fail('Should never get here')
} catch (error: any) {
assert.strictEqual(error.message, 'thingThatDoesNotExist is not defined')
}
})
it('.get with error in hook', () => async () => {
try {
await call('get', 'laundry', { hookError: true })
assert.fail('Should never get here')
} catch (error: any) {
assert.strictEqual(error.message, 'Error from get, before hook')
}
})
it('.create', async () => {
const original = {
name: 'creating'
}
const data = await call('create', original, {})
verify.create(original, data)
})
it('.create without parameters', async () => {
const original = {
name: 'creating again'
}
const data = await call('create', original)
verify.create(original, data)
})
it('.update', async () => {
const original = {
name: 'updating'
}
const data = await call('update', 23, original, {})
verify.update(23, original, data)
})
it('.update many', async () => {
const original = {
name: 'updating',
many: true
}
const data = await call('update', null, original)
verify.update(null, original, data)
})
it('.patch', async () => {
const original = {
name: 'patching'
}
const data = await call('patch', 25, original)
verify.patch(25, original, data)
})
it('.patch many', async () => {
const original = {
name: 'patching',
many: true
}
const data = await call('patch', null, original)
verify.patch(null, original, data)
})
it('.remove', () => async () => {
const data = await call('remove', 11)
verify.remove(11, data)
})
it('.remove many', async () => {
const data = await call('remove', null)
verify.remove(null, data)
})
}