Skip to content

Commit

Permalink
Add client tests
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Oct 6, 2023
1 parent a6bb1bc commit 4c3e782
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions test/seam/connect/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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<DevicesGetResponse>('/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<DevicesListResponse>('/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, {
Expand Down

0 comments on commit 4c3e782

Please sign in to comment.