From 47105caaa99473b0e036d9078403ecbcfb0a96ac Mon Sep 17 00:00:00 2001 From: kirahsapong <102400653+kirahsapong@users.noreply.github.com> Date: Thu, 4 Jan 2024 11:04:03 -0800 Subject: [PATCH] Remove HttpResponse and ErrorResponse from `http-client` types (#124) * Remove ErrorResponse type from tests Fix invalid JSON expect statement * Remove HttpResponse and ErrorResponse types * Update http-server tests * Add changeset --- .changeset/smooth-keys-roll.md | 6 ++++++ packages/http-client/src/types.ts | 20 +------------------ .../http-server/tests/submit-close.spec.ts | 12 +++++------ .../http-server/tests/submit-order.spec.ts | 10 +++++----- packages/http-server/tests/submit-rfq.spec.ts | 8 ++++---- 5 files changed, 22 insertions(+), 34 deletions(-) create mode 100644 .changeset/smooth-keys-roll.md diff --git a/.changeset/smooth-keys-roll.md b/.changeset/smooth-keys-roll.md new file mode 100644 index 00000000..8c28df2d --- /dev/null +++ b/.changeset/smooth-keys-roll.md @@ -0,0 +1,6 @@ +--- +"@tbdex/http-client": patch +"@tbdex/http-server": patch +--- + +Removes HttpResponse and ErrorResponse types from http-client package diff --git a/packages/http-client/src/types.ts b/packages/http-client/src/types.ts index 75ca4614..5cb18083 100644 --- a/packages/http-client/src/types.ts +++ b/packages/http-client/src/types.ts @@ -24,22 +24,4 @@ export type ErrorDetail = { } /** A meta object containing non-standard meta-information about the error. */ meta?: Record -} - -/** - * HTTP Response - * @beta - */ -export type HttpResponse = { - status: number - headers: Headers -} - -/** - * HTTP Response with errors - * @beta - */ -export type ErrorResponse = HttpResponse & { - data?: never - errors: ErrorDetail[] -} +} \ No newline at end of file diff --git a/packages/http-server/tests/submit-close.spec.ts b/packages/http-server/tests/submit-close.spec.ts index 4595c0d3..73db1b19 100644 --- a/packages/http-server/tests/submit-close.spec.ts +++ b/packages/http-server/tests/submit-close.spec.ts @@ -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' @@ -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 @@ -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 () => { @@ -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 @@ -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 diff --git a/packages/http-server/tests/submit-order.spec.ts b/packages/http-server/tests/submit-order.spec.ts index 96108836..6d6f49b2 100644 --- a/packages/http-server/tests/submit-order.spec.ts +++ b/packages/http-server/tests/submit-order.spec.ts @@ -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' @@ -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 @@ -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 () => { @@ -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 diff --git a/packages/http-server/tests/submit-rfq.spec.ts b/packages/http-server/tests/submit-rfq.spec.ts index 78f30377..b5244a16 100644 --- a/packages/http-server/tests/submit-rfq.spec.ts +++ b/packages/http-server/tests/submit-rfq.spec.ts @@ -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' @@ -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 @@ -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')