-
Notifications
You must be signed in to change notification settings - Fork 308
/
fixtures.ts
122 lines (119 loc) · 3.35 KB
/
fixtures.ts
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
import nock from 'nock'
const fileUploadMatches = (expected: string) => (body: string) => {
const lines = body.split('\r\n')
return lines.length === 7 && lines[4] === expected
}
export const mockIpfsSuccessfulResponse = (): nock.Scope =>
nock('http://127.0.0.1:5001', { encodedQueryParams: true })
.persist()
.post('/api/v0/add', fileUploadMatches('some simple text'))
.query({ 'stream-channels': 'true', 'cid-version': '0', progress: 'false' })
.reply(
200,
{
Name: 'QmXLpPi3yorJmGe6NsdBfyWSFvLnkX12EJR5zitwv4q8Tf',
Hash: 'QmXLpPi3yorJmGe6NsdBfyWSFvLnkX12EJR5zitwv4q8Tf',
Size: '24',
},
[
'Access-Control-Allow-Headers',
'X-Stream-Output, X-Chunked-Output, X-Content-Length',
'Access-Control-Expose-Headers',
'X-Stream-Output, X-Chunked-Output, X-Content-Length',
'Connection',
'close',
'Content-Type',
'application/json',
'Server',
'go-ipfs/0.9.1',
'Trailer',
'X-Stream-Error',
'Vary',
'Origin',
'X-Chunked-Output',
'1',
'Date',
'Mon, 13 Sep 2021 15:25:10 GMT',
'Transfer-Encoding',
'chunked',
],
)
.post('/api/v0/cat')
.query({ arg: 'QmPChd2hVbrJ6bfo3WBcTW4iZnpHm8TEzWkLHmLpXhF68A' })
.reply(200, 'Hello, <YOUR NAME HERE>', [
'Access-Control-Allow-Headers',
'X-Stream-Output, X-Chunked-Output, X-Content-Length',
'Access-Control-Expose-Headers',
'X-Stream-Output, X-Chunked-Output, X-Content-Length',
'Content-Type',
'text/plain',
'Server',
'go-ipfs/0.9.1',
'Trailer',
'X-Stream-Error',
'Vary',
'Origin',
'X-Content-Length',
'23',
'X-Stream-Output',
'1',
'Date',
'Tue, 14 Sep 2021 10:41:02 GMT',
'Transfer-Encoding',
'chunked',
])
.post('/api/v0/cat')
.query({ arg: 'QmXLpPi3yorJmGe6NsdBfyWSFvLnkX12EJR5zitwv4q8Tf' })
.reply(200, 'some simple text', [
'Access-Control-Allow-Headers',
'X-Stream-Output, X-Chunked-Output, X-Content-Length',
'Access-Control-Expose-Headers',
'X-Stream-Output, X-Chunked-Output, X-Content-Length',
'Content-Type',
'text/plain',
'Server',
'go-ipfs/0.9.1',
'Trailer',
'X-Stream-Error',
'Vary',
'Origin',
'X-Content-Length',
'16',
'X-Stream-Output',
'1',
'Date',
'Tue, 14 Sep 2021 10:41:02 GMT',
'Transfer-Encoding',
'chunked',
])
export const mockIpfsErrorResponse = (): nock.Scope =>
nock('http://127.0.0.1:5001', { encodedQueryParams: true })
.persist()
.post('/api/v0/cat')
.query({ arg: 'not_real' })
.reply(
500,
{
Message: 'invalid path "not_real": selected encoding not supported',
Code: 0,
Type: 'error',
},
[
'Access-Control-Allow-Headers',
'X-Stream-Output, X-Chunked-Output, X-Content-Length',
'Access-Control-Expose-Headers',
'X-Stream-Output, X-Chunked-Output, X-Content-Length',
'Content-Type',
'application/json',
'Server',
'go-ipfs/0.9.1',
'Trailer',
'X-Stream-Error',
'Vary',
'Origin',
'Date',
'Tue, 14 Sep 2021 10:41:02 GMT',
'Transfer-Encoding',
'chunked',
],
)