Skip to content

Commit

Permalink
test: fix?
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviera9 committed Jul 21, 2023
1 parent f5f5bc2 commit 18805c6
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions packages/ptokens-helpers/test/http-utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createServer, Server } from 'http'
import { createServer, Server } from 'node:http'

import { http, errors } from '../src/'

Expand All @@ -21,22 +21,22 @@ describe('Http general tests', () => {

test('Should reject when timeout expires', async () => {
try {
await http.getRequest('http://localhost:3000/golong', {}, 100)
await http.getRequest('http://127.0.0.1:3000/golong', {}, 100)
fail()
} catch (err) {
expect(err.message).toStrictEqual(errors.ERROR_TIMEOUT)
}
})

test('Should not reject fetching the correct data', async () => {
const result = await http.getRequest('http://localhost:3000', {}, 400)
const result = await http.getRequest('http://127.0.0.1:3000', {}, 400)
const data = await result.text()
expect(data).toStrictEqual('data')
})

test('Should reject when timeout expires', async () => {
try {
await http.postRequest('http://localhost:3000/golong', {}, {}, 100)
await http.postRequest('http://127.0.0.1:3000/golong', {}, {}, 100)
fail()
} catch (err) {
expect(err.message).toStrictEqual(errors.ERROR_TIMEOUT)
Expand All @@ -53,7 +53,7 @@ describe('Http general tests', () => {
})

test('Should not reject fetching the correct data', async () => {
const result = await http.postRequest('http://localhost:3000', {}, {}, 400)
const result = await http.postRequest('http://127.0.0.1:3000', {}, {}, 400)
const data = await result.text()
expect(data).toStrictEqual('data')
})
Expand All @@ -80,14 +80,14 @@ describe('Http general tests', () => {
})

test('Should not reject performing a GET request', async () => {
const result = await http.fetchJsonByGet('http://localhost:3000')
const result = await http.fetchJsonByGet('http://127.0.0.1:3000')
const expected = { Hello: 'World' }
expect(result).toStrictEqual(expected)
})

test('Should reject performing a GET request', async () => {
try {
await http.fetchJsonByGet('http://localhost:3000/incorrect')
await http.fetchJsonByGet('http://127.0.0.1:3000/incorrect')
fail()
} catch (err) {
expect(err.message).toStrictEqual('Failed to extract the json from the response:{"size":0,"timeout":0}')
Expand All @@ -96,7 +96,7 @@ describe('Http general tests', () => {

test('Should reject performing a GET request', async () => {
try {
await http.fetchJsonByGet('http://localhost:3000/error')
await http.fetchJsonByGet('http://127.0.0.1:3000/error')
fail()
} catch (err) {
expect(err.message).toStrictEqual("Unexpected HTTP status - '500 Internal Server Error'")
Expand Down Expand Up @@ -135,14 +135,14 @@ describe('Http general tests', () => {

test('Should not reject returning the correct response', async () => {
const body = { hello: 'world' }
const result = await http.fetchJsonByPost('http://localhost:3000', body)
const result = await http.fetchJsonByPost('http://127.0.0.1:3000', body)
expect(result).toStrictEqual(body)
})

test('Should reject with incorrect output', async () => {
const body = { hello: 'incorrect' }
try {
await http.fetchJsonByPost('http://localhost:3000', body)
await http.fetchJsonByPost('http://127.0.0.1:3000', body)
fail()
} catch (err) {
expect(err.message).toStrictEqual('Failed to extract the json from the response:{"size":0,"timeout":0}')
Expand All @@ -152,7 +152,7 @@ describe('Http general tests', () => {
test('Should reject with incorrect output', async () => {
const body = { hello: 'error' }
try {
await http.fetchJsonByPost('http://localhost:3000', body)
await http.fetchJsonByPost('http://127.0.0.1:3000', body)
fail()
} catch (err) {
expect(err.message).toStrictEqual("Unexpected HTTP status - '500 Internal Server Error'")
Expand Down

0 comments on commit 18805c6

Please sign in to comment.