Skip to content

Commit 537492c

Browse files
authored
Merge pull request #15 from seamapi/test-get-param
test: Add explicit get request array serialization test
2 parents 9c94be7 + f1eca21 commit 537492c

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

test/seam/connect/serialization.test.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import test from 'ava'
22
import { getTestServer } from 'fixtures/seam/connect/api.js'
33

4-
import { SeamHttp } from '@seamapi/http/connect'
4+
import { type DevicesListResponse, SeamHttp } from '@seamapi/http/connect'
55

66
test('serializes array params when undefined', async (t) => {
77
const { seed, endpoint } = await getTestServer(t)
@@ -31,3 +31,41 @@ test('serializes array params when non-empty', async (t) => {
3131
t.true(devices.some((d) => d.device_id === seed.august_device_1))
3232
t.true(devices.some((d) => d.device_id === seed.ecobee_device_1))
3333
})
34+
35+
test('serializes array params when undefined and explicitly using get', async (t) => {
36+
const { seed, endpoint } = await getTestServer(t)
37+
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, { endpoint })
38+
const { data } = await seam.client.get<DevicesListResponse>('/devices/list', {
39+
params: {
40+
device_ids: undefined,
41+
},
42+
})
43+
const devices = data?.devices
44+
t.is(devices.length, 4)
45+
})
46+
47+
test('serializes array params when empty and explicitly using get', async (t) => {
48+
const { seed, endpoint } = await getTestServer(t)
49+
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, { endpoint })
50+
const { data } = await seam.client.get<DevicesListResponse>('/devices/list', {
51+
params: {
52+
device_ids: [],
53+
},
54+
})
55+
const devices = data?.devices
56+
t.is(devices.length, 0)
57+
})
58+
59+
test('serializes array params when non-empty and explicitly using get', async (t) => {
60+
const { seed, endpoint } = await getTestServer(t)
61+
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, { endpoint })
62+
const { data } = await seam.client.get<DevicesListResponse>('/devices/list', {
63+
params: {
64+
device_ids: [seed.august_device_1, seed.ecobee_device_1],
65+
},
66+
})
67+
const devices = data?.devices
68+
t.is(devices.length, 2)
69+
t.true(devices.some((d) => d.device_id === seed.august_device_1))
70+
t.true(devices.some((d) => d.device_id === seed.ecobee_device_1))
71+
})

0 commit comments

Comments
 (0)