|
| 1 | +import test from 'ava' |
| 2 | +import { getTestServer } from 'fixtures/seam/connect/api.js' |
| 3 | + |
| 4 | +import { SeamHttp } from '@seamapi/http/connect' |
| 5 | +import { |
| 6 | + SeamHttpRequest, |
| 7 | + type ResponseFromSeamHttpRequest, |
| 8 | +} from 'lib/seam/connect/seam-http-request.js' |
| 9 | + |
| 10 | +test('serializes array params when undefined', async (t) => { |
| 11 | + const { seed, endpoint } = await getTestServer(t) |
| 12 | + const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, { endpoint }) |
| 13 | + |
| 14 | + const deviceRequest = seam.devices.get({ device_id: seed.august_device_1 }) |
| 15 | + |
| 16 | + t.true(deviceRequest instanceof SeamHttpRequest) |
| 17 | + t.is(deviceRequest.url, '/devices/get') |
| 18 | + t.deepEqual(deviceRequest.data, { |
| 19 | + device_id: seed.august_device_1, |
| 20 | + }) |
| 21 | + t.is(deviceRequest.resourceKey, 'device') |
| 22 | + const device = await deviceRequest |
| 23 | + t.is(device.workspace_id, seed.seed_workspace_1) |
| 24 | + t.is(device.device_id, seed.august_device_1) |
| 25 | + |
| 26 | + // Ensure that the type of the response is correct. |
| 27 | + type Expected = ResponseFromSeamHttpRequest<typeof deviceRequest> |
| 28 | + |
| 29 | + const validDeviceType: Expected['device_type'] = 'august_lock' |
| 30 | + t.truthy(validDeviceType) |
| 31 | + |
| 32 | + // @ts-expect-error because it's an invalid device type. |
| 33 | + const invalidDeviceType: Expected['device_type'] = 'invalid_device_type' |
| 34 | + t.truthy(invalidDeviceType) |
| 35 | +}) |
0 commit comments