Skip to content

Commit

Permalink
test querying for devices
Browse files Browse the repository at this point in the history
  • Loading branch information
kainpets committed Jul 5, 2024
1 parent fa97a3d commit 00b517c
Showing 1 changed file with 24 additions and 34 deletions.
58 changes: 24 additions & 34 deletions test/integration/devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,49 +59,39 @@ func TestDevices(t *testing.T) {
assert.Len(t, devices, 2)

// query device with id
devices, err = seam.Devices.List(
deviceById, err := seam.Devices.Get(
ctx,
&seamgo.DevicesListRequest{
Manufacturer: seamgo.ManufacturerAugust.Ptr(),
&seamgo.DevicesGetRequest{
DeviceId: &device.DeviceId,
},
)
require.NoError(t, err)
assert.Len(t, devices, 1)
)
require.NoError(t, err)
assert.NotNil(t, deviceById, "Device queried by ID should not be nil")
assert.Equal(t, device.DisplayName, deviceById.DisplayName)
assert.Equal(t, device.DeviceId, deviceById.DeviceId)

deviceWithId, err := seam.Devices.Get(
// query device by name
deviceByName, err := seam.Devices.Get(
ctx,
&seamgo.DevicesGetRequest{
DeviceId: &device.DeviceId,
Name: &device.DisplayName,
},
)
require.NoError(t, err)
assert.Equal(t, device.DisplayName, deviceWithId.DisplayName)

// query device with name
device = getTestDevice(t, seam)
require.NotNil(t, device, "Test device should not be nil")

deviceByName, err := seam.Devices.Get(
ctx,
&seamgo.DevicesGetRequest{
Name: &device.DisplayName,
},
)
require.NoError(t, err)
assert.NotNil(t, deviceByName, "Device queried by name should not be nil")
assert.Equal(t, device.DisplayName, deviceByName.DisplayName)

deviceByNameAndId, err := seam.Devices.Get(
ctx,
&seamgo.DevicesGetRequest{
Name: &device.DisplayName,
DeviceId: &device.DeviceId,
},
)
require.NoError(t, err)
assert.NotNil(t, deviceByNameAndId, "Device queried by name and ID should not be nil")
assert.Equal(t, device.DisplayName, deviceByNameAndId.DisplayName)
assert.Equal(t, device.DeviceId, deviceByNameAndId.DeviceId)
assert.Equal(t, device.DeviceId, deviceByName.DeviceId)

// querying with both name and ID returns an error
_, err = seam.Devices.Get(
ctx,
&seamgo.DevicesGetRequest{
Name: &device.DisplayName,
DeviceId: &device.DeviceId,
},
)
assert.Error(t, err, "Expected an error when querying with both name and ID")
assert.Contains(t, err.Error(), "Either 'device_id' or 'name' is required")

locks, err := seam.Locks.List(
ctx,
Expand All @@ -125,4 +115,4 @@ func getTestDevice(t *testing.T, seam *seamclient.Client) *seamgo.Device {
require.NoError(t, err)
require.GreaterOrEqual(t, len(devices), 1)
return devices[0]
}
}

0 comments on commit 00b517c

Please sign in to comment.