2022-05-03 15:10:13 +00:00
|
|
|
import * as httpm from '../lib'
|
|
|
|
|
|
|
|
describe('basics', () => {
|
|
|
|
let _http: httpm.HttpClient
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
_http = new httpm.HttpClient('http-client-tests', [], {keepAlive: true})
|
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
_http.dispose()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('does basic http get request with keepAlive true', async () => {
|
|
|
|
const res: httpm.HttpClientResponse = await _http.get(
|
2023-05-23 11:23:56 +00:00
|
|
|
'http://postman-echo.com/get'
|
2022-05-03 15:10:13 +00:00
|
|
|
)
|
|
|
|
expect(res.message.statusCode).toBe(200)
|
|
|
|
const body: string = await res.readBody()
|
|
|
|
const obj = JSON.parse(body)
|
2023-05-23 11:23:56 +00:00
|
|
|
expect(obj.url).toBe('http://postman-echo.com/get')
|
2022-05-03 15:10:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('does basic head request with keepAlive true', async () => {
|
|
|
|
const res: httpm.HttpClientResponse = await _http.head(
|
2023-05-23 11:23:56 +00:00
|
|
|
'http://postman-echo.com/get'
|
2022-05-03 15:10:13 +00:00
|
|
|
)
|
|
|
|
expect(res.message.statusCode).toBe(200)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('does basic http delete request with keepAlive true', async () => {
|
|
|
|
const res: httpm.HttpClientResponse = await _http.del(
|
2023-05-23 11:23:56 +00:00
|
|
|
'http://postman-echo.com/delete'
|
2022-05-03 15:10:13 +00:00
|
|
|
)
|
|
|
|
expect(res.message.statusCode).toBe(200)
|
|
|
|
const body: string = await res.readBody()
|
|
|
|
JSON.parse(body)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('does basic http post request with keepAlive true', async () => {
|
|
|
|
const b = 'Hello World!'
|
|
|
|
const res: httpm.HttpClientResponse = await _http.post(
|
2023-05-23 11:23:56 +00:00
|
|
|
'http://postman-echo.com/post',
|
2022-05-03 15:10:13 +00:00
|
|
|
b
|
|
|
|
)
|
|
|
|
expect(res.message.statusCode).toBe(200)
|
|
|
|
const body: string = await res.readBody()
|
|
|
|
const obj = JSON.parse(body)
|
|
|
|
expect(obj.data).toBe(b)
|
2023-05-23 11:23:56 +00:00
|
|
|
expect(obj.url).toBe('http://postman-echo.com/post')
|
2022-05-03 15:10:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('does basic http patch request with keepAlive true', async () => {
|
|
|
|
const b = 'Hello World!'
|
|
|
|
const res: httpm.HttpClientResponse = await _http.patch(
|
2023-05-23 11:23:56 +00:00
|
|
|
'http://postman-echo.com/patch',
|
2022-05-03 15:10:13 +00:00
|
|
|
b
|
|
|
|
)
|
|
|
|
expect(res.message.statusCode).toBe(200)
|
|
|
|
const body: string = await res.readBody()
|
|
|
|
const obj = JSON.parse(body)
|
|
|
|
expect(obj.data).toBe(b)
|
2023-05-23 11:23:56 +00:00
|
|
|
expect(obj.url).toBe('http://postman-echo.com/patch')
|
2022-05-03 15:10:13 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
it('does basic http options request with keepAlive true', async () => {
|
|
|
|
const res: httpm.HttpClientResponse = await _http.options(
|
2023-05-23 11:23:56 +00:00
|
|
|
'http://postman-echo.com'
|
2022-05-03 15:10:13 +00:00
|
|
|
)
|
|
|
|
expect(res.message.statusCode).toBe(200)
|
|
|
|
await res.readBody()
|
|
|
|
})
|
|
|
|
})
|