From 4c3e782dbe2276aee207808c1c49575f7b514cf6 Mon Sep 17 00:00:00 2001 From: Evan Sosenko Date: Fri, 6 Oct 2023 15:48:24 -0700 Subject: [PATCH] Add client tests --- test/seam/connect/client.test.ts | 43 ++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/test/seam/connect/client.test.ts b/test/seam/connect/client.test.ts index bc96358a..f1b68511 100644 --- a/test/seam/connect/client.test.ts +++ b/test/seam/connect/client.test.ts @@ -3,6 +3,12 @@ import { getTestServer } from 'fixtures/seam/connect/api.js' import { SeamHttp } from '@seamapi/http/connect' +import type { + DevicesGetResponse, + DevicesListBody, + DevicesListResponse, +} from 'lib/seam/connect/routes/devices.js' + test('SeamHttp: fromClient returns instance that uses client', async (t) => { const { seed, endpoint } = await getTestServer(t) const seam = SeamHttp.fromClient( @@ -27,6 +33,43 @@ test('SeamHttp: constructor returns instance that uses client', async (t) => { t.is(device.device_id, seed.august_device_1) }) +test('SeamHttp: can use client to make requests', async (t) => { + const { seed, endpoint } = await getTestServer(t) + const seam = new SeamHttp({ + client: SeamHttp.fromApiKey(seed.seam_apikey1_token, { endpoint }).client, + }) + const { + data: { device }, + status, + } = await seam.client.get('/devices/get', { + params: { device_id: seed.august_device_1 }, + }) + t.is(status, 200) + t.is(device.workspace_id, seed.seed_workspace_1) + t.is(device.device_id, seed.august_device_1) +}) + +test('SeamHttp: client serializes array params', async (t) => { + const { seed, endpoint } = await getTestServer(t) + const seam = new SeamHttp({ + client: SeamHttp.fromApiKey(seed.seam_apikey1_token, { endpoint }).client, + }) + const params: DevicesListBody = { + device_ids: [seed.august_device_1], + } + const { + data: { devices }, + status, + } = await seam.client.get('/devices/list', { + params, + }) + t.is(status, 200) + t.is(devices.length, 1) + const [device] = devices + t.is(device?.workspace_id, seed.seed_workspace_1) + t.is(device?.device_id, seed.august_device_1) +}) + test('SeamHttp: merges axiosOptions when creating client', async (t) => { const { seed, endpoint } = await getTestServer(t) const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, {