-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserialization.test.ts
82 lines (73 loc) · 2.83 KB
/
serialization.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import test from 'ava'
import { getTestServer } from 'fixtures/seam/connect/api.js'
import { type DevicesListResponse, SeamHttp } from '@seamapi/http/connect'
test('serializes array params when undefined', async (t) => {
const { seed, endpoint } = await getTestServer(t)
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, { endpoint })
const devices = await seam.devices.list({
device_ids: undefined,
})
const { data: db } = await seam.client.get('/_fake/database')
t.is(devices.length, db.devices.length)
})
test('serializes array params when empty', async (t) => {
const { seed, endpoint } = await getTestServer(t)
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, { endpoint })
const devices = await seam.devices.list({
device_ids: [],
})
t.is(devices.length, 0)
})
test('serializes array params when non-empty', async (t) => {
const { seed, endpoint } = await getTestServer(t)
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, { endpoint })
const devices = await seam.devices.list({
device_ids: [seed.august_device_1, seed.ecobee_device_1],
})
t.is(devices.length, 2)
t.true(devices.some((d) => d.device_id === seed.august_device_1))
t.true(devices.some((d) => d.device_id === seed.ecobee_device_1))
})
test('serializes array params when undefined and explicitly using get', async (t) => {
const { seed, endpoint } = await getTestServer(t)
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, { endpoint })
const { data } = await seam.client.get<DevicesListResponse>('/devices/list', {
params: {
device_ids: undefined,
},
})
const devices = data?.devices
const { data: db } = await seam.client.get('/_fake/database')
t.is(devices.length, db.devices.length)
})
// UPSTREAM: nextlove parses device_ids= to [''] but should parse this to []
test.failing(
'serializes array params when empty and explicitly using get',
async (t) => {
const { seed, endpoint } = await getTestServer(t)
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, { endpoint })
const { data } = await seam.client.get<DevicesListResponse>(
'/devices/list',
{
params: {
device_ids: [],
},
},
)
const devices = data?.devices
t.is(devices.length, 0)
},
)
test('serializes array params when non-empty and explicitly using get', async (t) => {
const { seed, endpoint } = await getTestServer(t)
const seam = SeamHttp.fromApiKey(seed.seam_apikey1_token, { endpoint })
const { data } = await seam.client.get<DevicesListResponse>('/devices/list', {
params: {
device_ids: [seed.august_device_1, seed.ecobee_device_1],
},
})
const devices = data?.devices
t.is(devices.length, 2)
t.true(devices.some((d) => d.device_id === seed.august_device_1))
t.true(devices.some((d) => d.device_id === seed.ecobee_device_1))
})