-
-
Notifications
You must be signed in to change notification settings - Fork 796
Expand file tree
/
Copy pathrest.ts
More file actions
94 lines (70 loc) · 2.59 KB
/
rest.ts
File metadata and controls
94 lines (70 loc) · 2.59 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
import assert from 'assert'
import axios from 'axios'
import { verify } from './fixture'
export function restTests(description: string, name: string, port: number) {
describe(description, () => {
it('GET .find', async () => {
const res = await axios.get<any>(`http://localhost:${port}/${name}`)
assert.ok(res.status === 200, 'Got OK status code')
verify.find(res.data)
})
it('GET .get', async () => {
const res = await axios.get<any>(`http://localhost:${port}/${name}/dishes`)
assert.ok(res.status === 200, 'Got OK status code')
verify.get('dishes', res.data)
})
it('POST .create', async () => {
const original = {
description: 'POST .create'
}
const res = await axios.post<any>(`http://localhost:${port}/${name}`, original)
assert.ok(res.status === 201, 'Got CREATED status code')
verify.create(original, res.data)
})
it('PUT .update', async () => {
const original = {
description: 'PUT .update'
}
const res = await axios.put(`http://localhost:${port}/${name}/544`, original)
assert.ok(res.status === 200, 'Got OK status code')
verify.update('544', original, res.data)
})
it('PUT .update many', async () => {
const original = {
description: 'PUT .update',
many: true
}
const res = await axios.put(`http://localhost:${port}/${name}`, original)
const { data } = res
assert.ok(res.status === 200, 'Got OK status code')
verify.update(null, original, data)
})
it('PATCH .patch', async () => {
const original = {
description: 'PATCH .patch'
}
const res = await axios.patch(`http://localhost:${port}/${name}/544`, original)
assert.ok(res.status === 200, 'Got OK status code')
verify.patch('544', original, res.data)
})
it('PATCH .patch many', async () => {
const original = {
description: 'PATCH .patch',
many: true
}
const res = await axios.patch(`http://localhost:${port}/${name}`, original)
assert.ok(res.status === 200, 'Got OK status code')
verify.patch(null, original, res.data)
})
it('DELETE .remove', async () => {
const res = await axios.delete(`http://localhost:${port}/${name}/233`)
assert.ok(res.status === 200, 'Got OK status code')
verify.remove('233', res.data)
})
it('DELETE .remove many', async () => {
const res = await axios.delete(`http://localhost:${port}/${name}`)
assert.ok(res.status === 200, 'Got OK status code')
verify.remove(null, res.data)
})
})
}