-
-
Notifications
You must be signed in to change notification settings - Fork 798
Expand file tree
/
Copy pathfixture.ts
More file actions
133 lines (108 loc) · 2.72 KB
/
Copy pathfixture.ts
File metadata and controls
133 lines (108 loc) · 2.72 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
129
130
131
132
133
import assert from 'assert'
const clone = (data: any) => JSON.parse(JSON.stringify(data))
const findAllData = [
{
id: 0,
description: 'You have to do something'
},
{
id: 1,
description: 'You have to do laundry'
}
]
export class Service {
events = ['log']
async find() {
return findAllData
}
async get(name: string, params: any) {
if (params.query.error) {
throw new Error(`Something for ${name} went wrong`)
}
if (params.query.runtimeError) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
thingThatDoesNotExist() // eslint-disable-line
}
return Promise.resolve({
id: name,
description: `You have to do ${name}!`
})
}
async create(data: any) {
const result = Object.assign({}, clone(data), {
id: 42,
status: 'created'
})
if (Array.isArray(data)) {
result.many = true
}
return result
}
async update(id: any, data: any) {
const result = Object.assign({}, clone(data), {
id,
status: 'updated'
})
if (id === null) {
result.many = true
}
return result
}
async patch(id: any, data: any) {
const result = Object.assign({}, clone(data), {
id,
status: 'patched'
})
if (id === null) {
result.many = true
}
return result
}
async remove(id: any) {
return { id }
}
async customMethod(data: any, params: any) {
return {
data,
method: 'customMethod',
provider: params.provider
}
}
async internalMethod() {
throw new Error('Should never get here')
}
}
export const verify = {
find(data: any) {
assert.deepStrictEqual(findAllData, clone(data), 'Data as expected')
},
get(id: any, data: any) {
assert.strictEqual(data.id, id, 'Got id in data')
assert.strictEqual(data.description, `You have to do ${id}!`, 'Got description')
},
create(original: any, current: any) {
const expected = Object.assign({}, clone(original), {
id: 42,
status: 'created'
})
assert.deepStrictEqual(expected, clone(current), 'Data ran through .create as expected')
},
update(id: any, original: any, current: any) {
const expected = Object.assign({}, clone(original), {
id,
status: 'updated'
})
assert.deepStrictEqual(expected, clone(current), 'Data ran through .update as expected')
},
patch(id: any, original: any, current: any) {
const expected = Object.assign({}, clone(original), {
id,
status: 'patched'
})
assert.deepStrictEqual(expected, clone(current), 'Data ran through .patch as expected')
},
remove(id: any, data: any) {
assert.deepStrictEqual({ id }, clone(data), '.remove called')
}
}