mirror of
https://github.com/actions/toolkit.git
synced 2026-08-20 00:00:14 +02:00
Update HTTP tests to use HTTPS for postman-echo.com
This commit is contained in:
@@ -15,7 +15,7 @@ describe('auth', () => {
|
|||||||
bh
|
bh
|
||||||
])
|
])
|
||||||
const res: httpm.HttpClientResponse = await http.get(
|
const res: httpm.HttpClientResponse = await http.get(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
@@ -26,7 +26,7 @@ describe('auth', () => {
|
|||||||
'base64'
|
'base64'
|
||||||
).toString()
|
).toString()
|
||||||
expect(creds).toBe('johndoe:password')
|
expect(creds).toBe('johndoe:password')
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does basic http get request with pat token auth', async () => {
|
it('does basic http get request with pat token auth', async () => {
|
||||||
@@ -38,7 +38,7 @@ describe('auth', () => {
|
|||||||
ph
|
ph
|
||||||
])
|
])
|
||||||
const res: httpm.HttpClientResponse = await http.get(
|
const res: httpm.HttpClientResponse = await http.get(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
@@ -49,7 +49,7 @@ describe('auth', () => {
|
|||||||
'base64'
|
'base64'
|
||||||
).toString()
|
).toString()
|
||||||
expect(creds).toBe(`PAT:${token}`)
|
expect(creds).toBe(`PAT:${token}`)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does basic http get request with pat token auth', async () => {
|
it('does basic http get request with pat token auth', async () => {
|
||||||
@@ -60,13 +60,13 @@ describe('auth', () => {
|
|||||||
ph
|
ph
|
||||||
])
|
])
|
||||||
const res: httpm.HttpClientResponse = await http.get(
|
const res: httpm.HttpClientResponse = await http.get(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
const auth: string = obj.headers.authorization
|
const auth: string = obj.headers.authorization
|
||||||
expect(auth).toBe(`Bearer ${token}`)
|
expect(auth).toBe(`Bearer ${token}`)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -37,41 +37,41 @@ describe('basics', () => {
|
|||||||
// "user-agent": "typed-test-client-tests"
|
// "user-agent": "typed-test-client-tests"
|
||||||
// },
|
// },
|
||||||
// "origin": "173.95.152.44",
|
// "origin": "173.95.152.44",
|
||||||
// "url": "http://postman-echo.com/get"
|
// "url": "https://postman-echo.com/get"
|
||||||
// }
|
// }
|
||||||
|
|
||||||
it('does basic http get request', async () => {
|
it('does basic http get request', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.get(
|
const res: httpm.HttpClientResponse = await _http.get(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
expect(obj.headers['user-agent']).toBeTruthy()
|
expect(obj.headers['user-agent']).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does basic http get request with no user agent', async () => {
|
it('does basic http get request with no user agent', async () => {
|
||||||
const http: httpm.HttpClient = new httpm.HttpClient()
|
const http: httpm.HttpClient = new httpm.HttpClient()
|
||||||
const res: httpm.HttpClientResponse = await http.get(
|
const res: httpm.HttpClientResponse = await http.get(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
expect(obj.headers['user-agent']).toBeFalsy()
|
expect(obj.headers['user-agent']).toBeFalsy()
|
||||||
})
|
})
|
||||||
|
|
||||||
/* TODO write a mock rather then relying on a third party
|
/* TODO write a mock rather then relying on a third party
|
||||||
it('does basic https get request', async () => {
|
it('does basic https get request', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.get(
|
const res: httpm.HttpClientResponse = await _http.get(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
it('does basic http get request with default headers', async () => {
|
it('does basic http get request with default headers', async () => {
|
||||||
@@ -86,14 +86,14 @@ describe('basics', () => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
const res: httpm.HttpClientResponse = await http.get(
|
const res: httpm.HttpClientResponse = await http.get(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.headers.accept).toBe('application/json')
|
expect(obj.headers.accept).toBe('application/json')
|
||||||
expect(obj.headers['content-type']).toBe('application/json')
|
expect(obj.headers['content-type']).toBe('application/json')
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does basic http get request with merged headers', async () => {
|
it('does basic http get request with merged headers', async () => {
|
||||||
@@ -108,7 +108,7 @@ describe('basics', () => {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
const res: httpm.HttpClientResponse = await http.get(
|
const res: httpm.HttpClientResponse = await http.get(
|
||||||
'http://postman-echo.com/get',
|
'https://postman-echo.com/get',
|
||||||
{
|
{
|
||||||
'content-type': 'application/x-www-form-urlencoded'
|
'content-type': 'application/x-www-form-urlencoded'
|
||||||
}
|
}
|
||||||
@@ -120,18 +120,18 @@ describe('basics', () => {
|
|||||||
expect(obj.headers['content-type']).toBe(
|
expect(obj.headers['content-type']).toBe(
|
||||||
'application/x-www-form-urlencoded'
|
'application/x-www-form-urlencoded'
|
||||||
)
|
)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('pipes a get request', async () => {
|
it('pipes a get request', async () => {
|
||||||
return new Promise<void>(async resolve => {
|
return new Promise<void>(async resolve => {
|
||||||
const file = fs.createWriteStream(sampleFilePath)
|
const file = fs.createWriteStream(sampleFilePath)
|
||||||
;(await _http.get('http://postman-echo.com/get')).message
|
;(await _http.get('https://postman-echo.com/get')).message
|
||||||
.pipe(file)
|
.pipe(file)
|
||||||
.on('close', () => {
|
.on('close', () => {
|
||||||
const body: string = fs.readFileSync(sampleFilePath).toString()
|
const body: string = fs.readFileSync(sampleFilePath).toString()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -139,32 +139,32 @@ describe('basics', () => {
|
|||||||
|
|
||||||
it('does basic get request with redirects', async () => {
|
it('does basic get request with redirects', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.get(
|
const res: httpm.HttpClientResponse = await _http.get(
|
||||||
`http://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
`https://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)}`
|
)}`
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does basic get request with redirects (303)', async () => {
|
it('does basic get request with redirects (303)', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.get(
|
const res: httpm.HttpClientResponse = await _http.get(
|
||||||
`http://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
`https://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)}&status_code=303`
|
)}&status_code=303`
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns 404 for not found get request on redirect', async () => {
|
it('returns 404 for not found get request on redirect', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.get(
|
const res: httpm.HttpClientResponse = await _http.get(
|
||||||
`http://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
`https://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
||||||
'http://postman-echo.com/status/404'
|
'https://postman-echo.com/status/404'
|
||||||
)}&status_code=303`
|
)}&status_code=303`
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(404)
|
expect(res.message.statusCode).toBe(404)
|
||||||
@@ -178,8 +178,8 @@ describe('basics', () => {
|
|||||||
{allowRedirects: false}
|
{allowRedirects: false}
|
||||||
)
|
)
|
||||||
const res: httpm.HttpClientResponse = await http.get(
|
const res: httpm.HttpClientResponse = await http.get(
|
||||||
`http://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
`https://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)}`
|
)}`
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(302)
|
expect(res.message.statusCode).toBe(302)
|
||||||
@@ -192,7 +192,7 @@ describe('basics', () => {
|
|||||||
authorization: 'shhh'
|
authorization: 'shhh'
|
||||||
}
|
}
|
||||||
const res: httpm.HttpClientResponse = await _http.get(
|
const res: httpm.HttpClientResponse = await _http.get(
|
||||||
`http://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
`https://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
||||||
'http://www.postman-echo.com/get'
|
'http://www.postman-echo.com/get'
|
||||||
)}`,
|
)}`,
|
||||||
headers
|
headers
|
||||||
@@ -214,7 +214,7 @@ describe('basics', () => {
|
|||||||
Authorization: 'shhh'
|
Authorization: 'shhh'
|
||||||
}
|
}
|
||||||
const res: httpm.HttpClientResponse = await _http.get(
|
const res: httpm.HttpClientResponse = await _http.get(
|
||||||
`http://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
`https://postman-echo.com/redirect-to?url=${encodeURIComponent(
|
||||||
'http://www.postman-echo.com/get'
|
'http://www.postman-echo.com/get'
|
||||||
)}`,
|
)}`,
|
||||||
headers
|
headers
|
||||||
@@ -232,14 +232,14 @@ describe('basics', () => {
|
|||||||
|
|
||||||
it('does basic head request', async () => {
|
it('does basic head request', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.head(
|
const res: httpm.HttpClientResponse = await _http.head(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does basic http delete request', async () => {
|
it('does basic http delete request', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.del(
|
const res: httpm.HttpClientResponse = await _http.del(
|
||||||
'http://postman-echo.com/delete'
|
'https://postman-echo.com/delete'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
@@ -249,32 +249,32 @@ describe('basics', () => {
|
|||||||
it('does basic http post request', async () => {
|
it('does basic http post request', async () => {
|
||||||
const b = 'Hello World!'
|
const b = 'Hello World!'
|
||||||
const res: httpm.HttpClientResponse = await _http.post(
|
const res: httpm.HttpClientResponse = await _http.post(
|
||||||
'http://postman-echo.com/post',
|
'https://postman-echo.com/post',
|
||||||
b
|
b
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.data).toBe(b)
|
expect(obj.data).toBe(b)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/post')
|
expect(obj.url).toBe('https://postman-echo.com/post')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does basic http patch request', async () => {
|
it('does basic http patch request', async () => {
|
||||||
const b = 'Hello World!'
|
const b = 'Hello World!'
|
||||||
const res: httpm.HttpClientResponse = await _http.patch(
|
const res: httpm.HttpClientResponse = await _http.patch(
|
||||||
'http://postman-echo.com/patch',
|
'https://postman-echo.com/patch',
|
||||||
b
|
b
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.data).toBe(b)
|
expect(obj.data).toBe(b)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/patch')
|
expect(obj.url).toBe('https://postman-echo.com/patch')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does basic http options request', async () => {
|
it('does basic http options request', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.options(
|
const res: httpm.HttpClientResponse = await _http.options(
|
||||||
'http://postman-echo.com'
|
'https://postman-echo.com'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
await res.readBody()
|
await res.readBody()
|
||||||
@@ -282,7 +282,7 @@ describe('basics', () => {
|
|||||||
|
|
||||||
it('returns 404 for not found get request', async () => {
|
it('returns 404 for not found get request', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.get(
|
const res: httpm.HttpClientResponse = await _http.get(
|
||||||
'http://postman-echo.com/status/404'
|
'https://postman-echo.com/status/404'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(404)
|
expect(res.message.statusCode).toBe(404)
|
||||||
await res.readBody()
|
await res.readBody()
|
||||||
@@ -290,11 +290,11 @@ describe('basics', () => {
|
|||||||
|
|
||||||
it('gets a json object', async () => {
|
it('gets a json object', async () => {
|
||||||
const jsonObj = await _http.getJson<HttpBinData>(
|
const jsonObj = await _http.getJson<HttpBinData>(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(jsonObj.statusCode).toBe(200)
|
expect(jsonObj.statusCode).toBe(200)
|
||||||
expect(jsonObj.result).toBeDefined()
|
expect(jsonObj.result).toBeDefined()
|
||||||
expect(jsonObj.result?.url).toBe('http://postman-echo.com/get')
|
expect(jsonObj.result?.url).toBe('https://postman-echo.com/get')
|
||||||
expect(jsonObj.result?.headers[httpm.Headers.Accept]).toBe(
|
expect(jsonObj.result?.headers[httpm.Headers.Accept]).toBe(
|
||||||
httpm.MediaTypes.ApplicationJson
|
httpm.MediaTypes.ApplicationJson
|
||||||
)
|
)
|
||||||
@@ -305,7 +305,7 @@ describe('basics', () => {
|
|||||||
|
|
||||||
it('getting a non existent json object returns null', async () => {
|
it('getting a non existent json object returns null', async () => {
|
||||||
const jsonObj = await _http.getJson<HttpBinData>(
|
const jsonObj = await _http.getJson<HttpBinData>(
|
||||||
'http://postman-echo.com/status/404'
|
'https://postman-echo.com/status/404'
|
||||||
)
|
)
|
||||||
expect(jsonObj.statusCode).toBe(404)
|
expect(jsonObj.statusCode).toBe(404)
|
||||||
expect(jsonObj.result).toBeNull()
|
expect(jsonObj.result).toBeNull()
|
||||||
@@ -314,12 +314,12 @@ describe('basics', () => {
|
|||||||
it('posts a json object', async () => {
|
it('posts a json object', async () => {
|
||||||
const res = {name: 'foo'}
|
const res = {name: 'foo'}
|
||||||
const restRes = await _http.postJson<HttpBinData>(
|
const restRes = await _http.postJson<HttpBinData>(
|
||||||
'http://postman-echo.com/post',
|
'https://postman-echo.com/post',
|
||||||
res
|
res
|
||||||
)
|
)
|
||||||
expect(restRes.statusCode).toBe(200)
|
expect(restRes.statusCode).toBe(200)
|
||||||
expect(restRes.result).toBeDefined()
|
expect(restRes.result).toBeDefined()
|
||||||
expect(restRes.result?.url).toBe('http://postman-echo.com/post')
|
expect(restRes.result?.url).toBe('https://postman-echo.com/post')
|
||||||
expect(restRes.result?.json.name).toBe('foo')
|
expect(restRes.result?.json.name).toBe('foo')
|
||||||
expect(restRes.result?.headers[httpm.Headers.Accept]).toBe(
|
expect(restRes.result?.headers[httpm.Headers.Accept]).toBe(
|
||||||
httpm.MediaTypes.ApplicationJson
|
httpm.MediaTypes.ApplicationJson
|
||||||
@@ -335,12 +335,12 @@ describe('basics', () => {
|
|||||||
it('puts a json object', async () => {
|
it('puts a json object', async () => {
|
||||||
const res = {name: 'foo'}
|
const res = {name: 'foo'}
|
||||||
const restRes = await _http.putJson<HttpBinData>(
|
const restRes = await _http.putJson<HttpBinData>(
|
||||||
'http://postman-echo.com/put',
|
'https://postman-echo.com/put',
|
||||||
res
|
res
|
||||||
)
|
)
|
||||||
expect(restRes.statusCode).toBe(200)
|
expect(restRes.statusCode).toBe(200)
|
||||||
expect(restRes.result).toBeDefined()
|
expect(restRes.result).toBeDefined()
|
||||||
expect(restRes.result?.url).toBe('http://postman-echo.com/put')
|
expect(restRes.result?.url).toBe('https://postman-echo.com/put')
|
||||||
expect(restRes.result?.json.name).toBe('foo')
|
expect(restRes.result?.json.name).toBe('foo')
|
||||||
|
|
||||||
expect(restRes.result?.headers[httpm.Headers.Accept]).toBe(
|
expect(restRes.result?.headers[httpm.Headers.Accept]).toBe(
|
||||||
@@ -357,12 +357,12 @@ describe('basics', () => {
|
|||||||
it('patch a json object', async () => {
|
it('patch a json object', async () => {
|
||||||
const res = {name: 'foo'}
|
const res = {name: 'foo'}
|
||||||
const restRes = await _http.patchJson<HttpBinData>(
|
const restRes = await _http.patchJson<HttpBinData>(
|
||||||
'http://postman-echo.com/patch',
|
'https://postman-echo.com/patch',
|
||||||
res
|
res
|
||||||
)
|
)
|
||||||
expect(restRes.statusCode).toBe(200)
|
expect(restRes.statusCode).toBe(200)
|
||||||
expect(restRes.result).toBeDefined()
|
expect(restRes.result).toBeDefined()
|
||||||
expect(restRes.result?.url).toBe('http://postman-echo.com/patch')
|
expect(restRes.result?.url).toBe('https://postman-echo.com/patch')
|
||||||
expect(restRes.result?.json.name).toBe('foo')
|
expect(restRes.result?.json.name).toBe('foo')
|
||||||
expect(restRes.result?.headers[httpm.Headers.Accept]).toBe(
|
expect(restRes.result?.headers[httpm.Headers.Accept]).toBe(
|
||||||
httpm.MediaTypes.ApplicationJson
|
httpm.MediaTypes.ApplicationJson
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ describe('headers', () => {
|
|||||||
it('preserves existing headers on getJson', async () => {
|
it('preserves existing headers on getJson', async () => {
|
||||||
const additionalHeaders = {[httpm.Headers.Accept]: 'foo'}
|
const additionalHeaders = {[httpm.Headers.Accept]: 'foo'}
|
||||||
let jsonObj = await _http.getJson<any>(
|
let jsonObj = await _http.getJson<any>(
|
||||||
'http://postman-echo.com/get',
|
'https://postman-echo.com/get',
|
||||||
additionalHeaders
|
additionalHeaders
|
||||||
)
|
)
|
||||||
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('foo')
|
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('foo')
|
||||||
@@ -26,7 +26,7 @@ describe('headers', () => {
|
|||||||
[httpm.Headers.Accept]: 'baz'
|
[httpm.Headers.Accept]: 'baz'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsonObj = await httpWithHeaders.getJson<any>('http://postman-echo.com/get')
|
jsonObj = await httpWithHeaders.getJson<any>('https://postman-echo.com/get')
|
||||||
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('baz')
|
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('baz')
|
||||||
expect(jsonObj.headers[httpm.Headers.ContentType]).toContain(
|
expect(jsonObj.headers[httpm.Headers.ContentType]).toContain(
|
||||||
httpm.MediaTypes.ApplicationJson
|
httpm.MediaTypes.ApplicationJson
|
||||||
@@ -36,7 +36,7 @@ describe('headers', () => {
|
|||||||
it('preserves existing headers on postJson', async () => {
|
it('preserves existing headers on postJson', async () => {
|
||||||
const additionalHeaders = {[httpm.Headers.Accept]: 'foo'}
|
const additionalHeaders = {[httpm.Headers.Accept]: 'foo'}
|
||||||
let jsonObj = await _http.postJson<any>(
|
let jsonObj = await _http.postJson<any>(
|
||||||
'http://postman-echo.com/post',
|
'https://postman-echo.com/post',
|
||||||
{},
|
{},
|
||||||
additionalHeaders
|
additionalHeaders
|
||||||
)
|
)
|
||||||
@@ -52,7 +52,7 @@ describe('headers', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsonObj = await httpWithHeaders.postJson<any>(
|
jsonObj = await httpWithHeaders.postJson<any>(
|
||||||
'http://postman-echo.com/post',
|
'https://postman-echo.com/post',
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('baz')
|
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('baz')
|
||||||
@@ -64,7 +64,7 @@ describe('headers', () => {
|
|||||||
it('preserves existing headers on putJson', async () => {
|
it('preserves existing headers on putJson', async () => {
|
||||||
const additionalHeaders = {[httpm.Headers.Accept]: 'foo'}
|
const additionalHeaders = {[httpm.Headers.Accept]: 'foo'}
|
||||||
let jsonObj = await _http.putJson<any>(
|
let jsonObj = await _http.putJson<any>(
|
||||||
'http://postman-echo.com/put',
|
'https://postman-echo.com/put',
|
||||||
{},
|
{},
|
||||||
additionalHeaders
|
additionalHeaders
|
||||||
)
|
)
|
||||||
@@ -80,7 +80,7 @@ describe('headers', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsonObj = await httpWithHeaders.putJson<any>(
|
jsonObj = await httpWithHeaders.putJson<any>(
|
||||||
'http://postman-echo.com/put',
|
'https://postman-echo.com/put',
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('baz')
|
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('baz')
|
||||||
@@ -92,7 +92,7 @@ describe('headers', () => {
|
|||||||
it('preserves existing headers on patchJson', async () => {
|
it('preserves existing headers on patchJson', async () => {
|
||||||
const additionalHeaders = {[httpm.Headers.Accept]: 'foo'}
|
const additionalHeaders = {[httpm.Headers.Accept]: 'foo'}
|
||||||
let jsonObj = await _http.patchJson<any>(
|
let jsonObj = await _http.patchJson<any>(
|
||||||
'http://postman-echo.com/patch',
|
'https://postman-echo.com/patch',
|
||||||
{},
|
{},
|
||||||
additionalHeaders
|
additionalHeaders
|
||||||
)
|
)
|
||||||
@@ -108,7 +108,7 @@ describe('headers', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
jsonObj = await httpWithHeaders.patchJson<any>(
|
jsonObj = await httpWithHeaders.patchJson<any>(
|
||||||
'http://postman-echo.com/patch',
|
'https://postman-echo.com/patch',
|
||||||
{}
|
{}
|
||||||
)
|
)
|
||||||
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('baz')
|
expect(jsonObj.result.headers[httpm.Headers.Accept]).toBe('baz')
|
||||||
|
|||||||
@@ -13,30 +13,30 @@ describe('basics', () => {
|
|||||||
|
|
||||||
it.each([true, false])('creates Agent with keepAlive %s', keepAlive => {
|
it.each([true, false])('creates Agent with keepAlive %s', keepAlive => {
|
||||||
const http = new httpm.HttpClient('http-client-tests', [], {keepAlive})
|
const http = new httpm.HttpClient('http-client-tests', [], {keepAlive})
|
||||||
const agent = http.getAgent('http://postman-echo.com')
|
const agent = http.getAgent('https://postman-echo.com')
|
||||||
expect(agent).toHaveProperty('keepAlive', keepAlive)
|
expect(agent).toHaveProperty('keepAlive', keepAlive)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does basic http get request with keepAlive true', async () => {
|
it('does basic http get request with keepAlive true', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.get(
|
const res: httpm.HttpClientResponse = await _http.get(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does basic head request with keepAlive true', async () => {
|
it('does basic head request with keepAlive true', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.head(
|
const res: httpm.HttpClientResponse = await _http.head(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does basic http delete request with keepAlive true', async () => {
|
it('does basic http delete request with keepAlive true', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.del(
|
const res: httpm.HttpClientResponse = await _http.del(
|
||||||
'http://postman-echo.com/delete'
|
'https://postman-echo.com/delete'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
@@ -46,32 +46,32 @@ describe('basics', () => {
|
|||||||
it('does basic http post request with keepAlive true', async () => {
|
it('does basic http post request with keepAlive true', async () => {
|
||||||
const b = 'Hello World!'
|
const b = 'Hello World!'
|
||||||
const res: httpm.HttpClientResponse = await _http.post(
|
const res: httpm.HttpClientResponse = await _http.post(
|
||||||
'http://postman-echo.com/post',
|
'https://postman-echo.com/post',
|
||||||
b
|
b
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.data).toBe(b)
|
expect(obj.data).toBe(b)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/post')
|
expect(obj.url).toBe('https://postman-echo.com/post')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does basic http patch request with keepAlive true', async () => {
|
it('does basic http patch request with keepAlive true', async () => {
|
||||||
const b = 'Hello World!'
|
const b = 'Hello World!'
|
||||||
const res: httpm.HttpClientResponse = await _http.patch(
|
const res: httpm.HttpClientResponse = await _http.patch(
|
||||||
'http://postman-echo.com/patch',
|
'https://postman-echo.com/patch',
|
||||||
b
|
b
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.data).toBe(b)
|
expect(obj.data).toBe(b)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/patch')
|
expect(obj.url).toBe('https://postman-echo.com/patch')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('does basic http options request with keepAlive true', async () => {
|
it('does basic http options request with keepAlive true', async () => {
|
||||||
const res: httpm.HttpClientResponse = await _http.options(
|
const res: httpm.HttpClientResponse = await _http.options(
|
||||||
'http://postman-echo.com'
|
'https://postman-echo.com'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
await res.readBody()
|
await res.readBody()
|
||||||
|
|||||||
@@ -199,13 +199,13 @@ describe('proxy', () => {
|
|||||||
process.env['http_proxy'] = _proxyUrl
|
process.env['http_proxy'] = _proxyUrl
|
||||||
const httpClient = new httpm.HttpClient()
|
const httpClient = new httpm.HttpClient()
|
||||||
const res: httpm.HttpClientResponse = await httpClient.get(
|
const res: httpm.HttpClientResponse = await httpClient.get(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
expect(_proxyConnects).toEqual(['postman-echo.com:80'])
|
expect(_proxyConnects).toEqual(['postman-echo.com:443'])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('HttpClient does basic http get request when bypass proxy', async () => {
|
it('HttpClient does basic http get request when bypass proxy', async () => {
|
||||||
@@ -213,12 +213,12 @@ describe('proxy', () => {
|
|||||||
process.env['no_proxy'] = 'postman-echo.com'
|
process.env['no_proxy'] = 'postman-echo.com'
|
||||||
const httpClient = new httpm.HttpClient()
|
const httpClient = new httpm.HttpClient()
|
||||||
const res: httpm.HttpClientResponse = await httpClient.get(
|
const res: httpm.HttpClientResponse = await httpClient.get(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
expect(_proxyConnects).toHaveLength(0)
|
expect(_proxyConnects).toHaveLength(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -228,12 +228,12 @@ describe('proxy', () => {
|
|||||||
process.env['https_proxy'] = _proxyUrl
|
process.env['https_proxy'] = _proxyUrl
|
||||||
const httpClient = new httpm.HttpClient()
|
const httpClient = new httpm.HttpClient()
|
||||||
const res: httpm.HttpClientResponse = await httpClient.get(
|
const res: httpm.HttpClientResponse = await httpClient.get(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
expect(_proxyConnects).toEqual(['postman-echo.com:443'])
|
expect(_proxyConnects).toEqual(['postman-echo.com:443'])
|
||||||
})
|
})
|
||||||
*/
|
*/
|
||||||
@@ -243,12 +243,12 @@ describe('proxy', () => {
|
|||||||
process.env['no_proxy'] = 'postman-echo.com'
|
process.env['no_proxy'] = 'postman-echo.com'
|
||||||
const httpClient = new httpm.HttpClient()
|
const httpClient = new httpm.HttpClient()
|
||||||
const res: httpm.HttpClientResponse = await httpClient.get(
|
const res: httpm.HttpClientResponse = await httpClient.get(
|
||||||
'http://postman-echo.com/get'
|
'https://postman-echo.com/get'
|
||||||
)
|
)
|
||||||
expect(res.message.statusCode).toBe(200)
|
expect(res.message.statusCode).toBe(200)
|
||||||
const body: string = await res.readBody()
|
const body: string = await res.readBody()
|
||||||
const obj = JSON.parse(body)
|
const obj = JSON.parse(body)
|
||||||
expect(obj.url).toBe('http://postman-echo.com/get')
|
expect(obj.url).toBe('https://postman-echo.com/get')
|
||||||
expect(_proxyConnects).toHaveLength(0)
|
expect(_proxyConnects).toHaveLength(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user