Skip to content

Commit

Permalink
Remove HttpResponse and ErrorResponse from http-client types (#124)
Browse files Browse the repository at this point in the history
* Remove ErrorResponse type from tests

Fix invalid JSON expect statement

* Remove HttpResponse and ErrorResponse types

* Update http-server tests

* Add changeset
  • Loading branch information
kirahsapong authored Jan 4, 2024
1 parent 9e1015e commit 47105ca
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 34 deletions.
6 changes: 6 additions & 0 deletions .changeset/smooth-keys-roll.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@tbdex/http-client": patch
"@tbdex/http-server": patch
---

Removes HttpResponse and ErrorResponse types from http-client package
20 changes: 1 addition & 19 deletions packages/http-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,4 @@ export type ErrorDetail = {
}
/** A meta object containing non-standard meta-information about the error. */
meta?: Record<string, any>
}

/**
* HTTP Response
* @beta
*/
export type HttpResponse = {
status: number
headers: Headers
}

/**
* HTTP Response with errors
* @beta
*/
export type ErrorResponse = HttpResponse & {
data?: never
errors: ErrorDetail[]
}
}
12 changes: 6 additions & 6 deletions packages/http-server/tests/submit-close.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ErrorResponse } from '@tbdex/http-client'
import type { ErrorDetail } from '@tbdex/http-client'
import type { Server } from 'http'

import { Close, DevTools, TbdexHttpServer } from '../src/main.js'
Expand Down Expand Up @@ -30,7 +30,7 @@ describe('POST /exchanges/:exchangeId/close', () => {

expect(resp.status).to.equal(400)

const responseBody = await resp.json() as ErrorResponse
const responseBody = await resp.json() as { errors: ErrorDetail[] }
expect(responseBody.errors.length).to.equal(1)

const [ error ] = responseBody.errors
Expand All @@ -46,12 +46,12 @@ describe('POST /exchanges/:exchangeId/close', () => {

expect(resp.status).to.equal(400)

const responseBody = await resp.json() as ErrorResponse
const responseBody = await resp.json() as { errors: ErrorDetail[] }
expect(responseBody.errors.length).to.equal(1)

const [ error ] = responseBody.errors
expect(error.detail).to.exist
expect(error.detail).to.include('not valid JSON')
expect(error.detail).to.include('JSON')
})

it(`returns a 404 if the exchange doesn't exist`, async () => {
Expand All @@ -71,7 +71,7 @@ describe('POST /exchanges/:exchangeId/close', () => {

expect(resp.status).to.equal(404)

const responseBody = await resp.json() as ErrorResponse
const responseBody = await resp.json() as { errors: ErrorDetail[] }
expect(responseBody.errors.length).to.equal(1)

const [ error ] = responseBody.errors
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('POST /exchanges/:exchangeId/close', () => {

expect(resp.status).to.equal(409)

const responseBody = await resp.json() as ErrorResponse
const responseBody = await resp.json() as { errors: ErrorDetail[] }
expect(responseBody.errors.length).to.equal(1)

const [ error ] = responseBody.errors
Expand Down
10 changes: 5 additions & 5 deletions packages/http-server/tests/submit-order.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ErrorResponse } from '@tbdex/http-client'
import type { ErrorDetail } from '@tbdex/http-client'
import type { Server } from 'http'

import { DevTools, Order, TbdexHttpServer } from '../src/main.js'
Expand All @@ -25,7 +25,7 @@ describe('POST /exchanges/:exchangeId/order', () => {

expect(resp.status).to.equal(400)

const responseBody = await resp.json() as ErrorResponse
const responseBody = await resp.json() as { errors: ErrorDetail[] }
expect(responseBody.errors.length).to.equal(1)

const [ error ] = responseBody.errors
Expand All @@ -41,12 +41,12 @@ describe('POST /exchanges/:exchangeId/order', () => {

expect(resp.status).to.equal(400)

const responseBody = await resp.json() as ErrorResponse
const responseBody = await resp.json() as { errors: ErrorDetail[] }
expect(responseBody.errors.length).to.equal(1)

const [ error ] = responseBody.errors
expect(error.detail).to.exist
expect(error.detail).to.include('not valid JSON')
expect(error.detail).to.include('JSON')
})

it(`returns a 404 if the exchange doesn't exist`, async () => {
Expand All @@ -65,7 +65,7 @@ describe('POST /exchanges/:exchangeId/order', () => {

expect(resp.status).to.equal(404)

const responseBody = await resp.json() as ErrorResponse
const responseBody = await resp.json() as { errors: ErrorDetail[] }
expect(responseBody.errors.length).to.equal(1)

const [ error ] = responseBody.errors
Expand Down
8 changes: 4 additions & 4 deletions packages/http-server/tests/submit-rfq.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ErrorResponse } from '@tbdex/http-client'
import type { ErrorDetail } from '@tbdex/http-client'
import type { Server } from 'http'

import { TbdexHttpServer } from '../src/main.js'
Expand All @@ -24,7 +24,7 @@ describe('POST /exchanges/:exchangeId/rfq', () => {

expect(resp.status).to.equal(400)

const responseBody = await resp.json() as ErrorResponse
const responseBody = await resp.json() as { errors: ErrorDetail[] }
expect(responseBody.errors.length).to.equal(1)

const [ error ] = responseBody.errors
Expand All @@ -40,12 +40,12 @@ describe('POST /exchanges/:exchangeId/rfq', () => {

expect(resp.status).to.equal(400)

const responseBody = await resp.json() as ErrorResponse
const responseBody = await resp.json() as { errors: ErrorDetail[] }
expect(responseBody.errors.length).to.equal(1)

const [ error ] = responseBody.errors
expect(error.detail).to.exist
expect(error.detail).to.include('not valid JSON')
expect(error.detail).to.include('JSON')
})

xit('returns a 400 if request body is not a valid RFQ')
Expand Down

0 comments on commit 47105ca

Please sign in to comment.