Skip to content

Commit

Permalink
test(http): add test for raw Axios HTTP client
Browse files Browse the repository at this point in the history
  • Loading branch information
xzhayon committed Jul 28, 2023
1 parent 6ec51fc commit 736c436
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions packages/http-raw-axios/src/AxiosHttp.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { DateClock } from '@imho/clock-raw'
import { HttpError, HttpResponseError } from '@imho/http'
import { VoidLog } from '@imho/log-raw'
import axios from 'axios'
import { AxiosHttp } from './AxiosHttp'

describe('AxiosHttp', () => {
const http = new AxiosHttp(axios, new DateClock(), new VoidLog())

describe('get', () => {
test('throwing `HttpError` on invalid request', async () => {
const response = http.get(`foo://bar`)
await expect(response).rejects.toThrow(HttpError)
await expect(response).rejects.not.toThrow(HttpResponseError)
})
test('throwing `HttpResponseError` on HTTP error', async () => {
await expect(http.get(`${process.env.NGINX_URL}/404`)).rejects.toThrow(
HttpResponseError,
)
})
test.each([
['JSON', 'json', 'application/json', { foo: 'bar' }],
['text', 'text', 'text/plain', 'foobar'],
['XML', 'xml', 'application/xml', '<foo>bar</foo>'],
])('forwarding %s response', async (_type, path, mimeType, body) => {
await expect(
http.get(`${process.env.NGINX_URL}/${path}`),
).resolves.toMatchObject({
status: 200,
headers: { 'content-type': mimeType },
body,
})
})
})
})

0 comments on commit 736c436

Please sign in to comment.