-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.js
138 lines (121 loc) · 3.79 KB
/
test.js
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
134
135
136
137
138
describe('request tests', async () =>
{
const
expect = require('chai').expect,
context = require('mochawesome/addContext'),
Request = require('.'),
request = new Request({ debug:false })
after(() =>
{
console.log('\n')
process.env.HTTP_PROXY
? console.log(`HTTP_PROXY env variable is set to: ${process.env.HTTP_PROXY}`)
: console.log('HTTP_PROXY env variable is not set')
})
it('simple GET http request', async () =>
{
const response = await request.get('http://httpbin.org/get?foo=bar')
expect(response.status).to.be.equal(200)
expect(response.data.args.foo).to.be.equal('bar')
})
it('simple GET https request', async () =>
{
const response = await request.get('https://httpbin.org/get?foo=bar')
expect(response.status).to.be.equal(200)
expect(response.data.args.foo).to.be.equal('bar')
})
it('simple POST http request', async () =>
{
const
url = 'http://httpbin.org/post',
data = { foo:'bar' },
response = await request.post({ url, data })
expect(response.status).to.be.equal(200)
expect(response.data.data).to.be.equal('foo=bar')
})
it('simple POST https request', async () =>
{
const
url = 'https://httpbin.org/post',
data = { foo:'bar' },
response = await request.post({ url, data })
expect(response.status).to.be.equal(200)
expect(response.data.data).to.be.equal('foo=bar')
})
it('simple PUT http request', async () =>
{
const
url = 'http://httpbin.org/put',
data = { foo:'bar' },
response = await request.put({ url, data })
expect(response.status).to.be.equal(200)
expect(response.data.data).to.be.equal('foo=bar')
})
it('simple PUT https request', async () =>
{
const
url = 'https://httpbin.org/put',
data = { foo:'bar' },
response = await request.put({ url, data })
expect(response.status).to.be.equal(200)
expect(response.data.data).to.be.equal('foo=bar')
})
it('simple DELETE http request', async () =>
{
const
url = 'http://httpbin.org/delete',
data = { foo:'bar' },
response = await request.delete({ url, data })
expect(response.status).to.be.equal(200)
expect(response.data.data).to.be.equal('foo=bar')
})
it('simple DELETE https request', async () =>
{
const
url = 'https://httpbin.org/delete',
data = { foo:'bar' },
response = await request.delete({ url, data })
expect(response.status).to.be.equal(200)
expect(response.data.data).to.be.equal('foo=bar')
})
it('simple GET http request', async () =>
{
const
url = 'http://httpbin.org/get?foo=bar',
headers = { 'content-type':'json/application' },
response = await request.get({ url, headers })
expect(response.status).to.be.equal(200)
expect(response.data.args.foo).to.be.equal('bar')
})
it('204 status test', async () =>
{
const
url = 'http://httpbin.org/status/204',
headers = { 'content-type':'json/application', accept:'json/application' },
response = await request.put({ url, headers, retry:3 })
expect(response.status).to.be.equal(204)
})
it('500 error test', async () =>
{
const
url = 'http://httpbin.org/status/500',
headers = { 'content-type':'json/application' },
response = await request.get({ url, headers, retry:3 })
expect(response.status).to.be.equal(500)
})
it('408 error test', async () =>
{
const
url = 'http://httpbin.org/delay/2',
headers = { 'content-type':'json/application' }
try
{
const response = await request.get({ url, headers, timeout:10 })
expect(response).to.be.equal('should never happen')
}
catch(error)
{
expect(error.code).to.be.equal('E_REQUEST_CLIENT_TIMEOUT')
}
})
})