Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip: fix tests #48

Open
wants to merge 6 commits into
base: fern-bot/07-04-2024-1109PM
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 46 additions & 33 deletions test/integration/access_codes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func TestAccessCodes(t *testing.T) {

ctx := context.Background()
device := getTestDevice(t, seam)
require.NotNil(t, device, "Test device should not be nil")

initialAccessCodes, err := seam.AccessCodes.List(
ctx,
&seamgo.AccessCodesListRequest{
Expand All @@ -34,6 +36,7 @@ func TestAccessCodes(t *testing.T) {
},
)
require.NoError(t, err)
require.NotNil(t, createdAccessCode, "Created access code should not be nil")
assert.NotNil(t, createdAccessCode.Name)
assert.NotNil(t, createdAccessCode.Code)
assert.Equal(t, "Test code", *createdAccessCode.Name)
Expand Down Expand Up @@ -76,20 +79,10 @@ func TestAccessCodes(t *testing.T) {
},
)
require.NoError(t, err)
require.NotNil(t, gotAccessCode, "Got access code should not be nil")
assert.NotNil(t, gotAccessCode.Code)
assert.Equal(t, "4444", *gotAccessCode.Code)

// Fake Seam does not dedupe access codes.
// _, err = seam.AccessCodes.Create(
// ctx,
// &seamgo.AccessCodesCreateRequest{
// DeviceId: device.DeviceId,
// Name: seamgo.String("Duplicate Access Code"),
// Code: seamgo.String("4444"),
// },
// )
// require.Error(t, err)

_, err = seam.AccessCodes.Update(
ctx,
&seamgo.AccessCodesUpdateRequest{
Expand All @@ -106,58 +99,78 @@ func TestAccessCodes(t *testing.T) {
},
)
require.NoError(t, err)
require.NotNil(t, updatedAccessCode, "Updated access code should not be nil")
assert.NotNil(t, updatedAccessCode.Name)
assert.Equal(t, "Updated Name", *updatedAccessCode.Name)

// Fake Seam does not like access code update.
// _, err = seam.AccessCodes.Update(
// ctx,
// &seamgo.AccessCodesUpdateRequest{
// AccessCodeId: createdAccessCode.AccessCodeId,
// Type: seamgo.AccessCodesUpdateRequestTypeTimeBound.Ptr(),
// StartsAt: seamgo.String("3001-01-01"),
// EndsAt: seamgo.String("3001-01-03"),
// },
// )
// require.NoError(t, err)

// accessCode, err := seam.AccessCodes.Get(
// ctx,
// &seamgo.AccessCodesGetRequest{
// AccessCodeId: &createdAccessCode.AccessCodeId,
// },
// )
// require.NoError(t, err)
// assert.Equal(t, seamgo.AccessCodeTypeTimeBound, accessCode.Type)

deleteResponse, err := seam.AccessCodes.Delete(
ctx,
&seamgo.AccessCodesDeleteRequest{
AccessCodeId: createdAccessCode.AccessCodeId,
},
)
require.NoError(t, err)
assert.NotNil(t, deleteResponse.ActionAttempt.Success)
require.NotNil(t, deleteResponse, "Delete response should not be nil")
require.NotNil(t, deleteResponse.ActionAttempt, "Action attempt should not be nil")

deviceIds := make([]string, 0, len(accessCodes))
for _, accessCode := range accessCodes {
deviceIds = append(deviceIds, accessCode.DeviceId)
}

require.NotEmpty(t, deviceIds, "Device IDs slice should not be empty")

createdAccessCodes, err := seam.AccessCodes.CreateMultiple(
ctx,
&seamgo.AccessCodesCreateMultipleRequest{
DeviceIds: deviceIds,
},
)
require.NoError(t, err)
require.NotNil(t, createdAccessCodes, "Created access codes should not be nil")
assert.Len(t, createdAccessCodes, 1)
assert.NotEmpty(t, createdAccessCodes, "Created access codes should not be empty")
assert.Equal(t, len(deviceIds), len(createdAccessCodes))

commonCodes := make(map[string]struct{})
for _, createdAccessCode := range createdAccessCodes {
require.NotNil(t, createdAccessCode, "Each created access code should not be nil")
if commonCodeKey := createdAccessCode.CommonCodeKey; commonCodeKey != nil {
commonCodes[*commonCodeKey] = struct{}{}
}
}
assert.Len(t, commonCodes, 1)


// Fake Seam does not dedupe access codes.
// _, err = seam.AccessCodes.Create(
// ctx,
// &seamgo.AccessCodesCreateRequest{
// DeviceId: device.DeviceId,
// Name: seamgo.String("Duplicate Access Code"),
// Code: seamgo.String("4444"),
// },
// )
// require.Error(t, err)

// Fake Seam does not like access code update.
// _, err = seam.AccessCodes.Update(
// ctx,
// &seamgo.AccessCodesUpdateRequest{
// AccessCodeId: createdAccessCode.AccessCodeId,
// Type: seamgo.AccessCodesUpdateRequestTypeTimeBound.Ptr(),
// StartsAt: seamgo.String("3001-01-01"),
// EndsAt: seamgo.String("3001-01-03"),
// },
// )
// require.NoError(t, err)

// accessCode, err := seam.AccessCodes.Get(
// ctx,
// &seamgo.AccessCodesGetRequest{
// AccessCodeId: &createdAccessCode.AccessCodeId,
// },
// )
// require.NoError(t, err)
// assert.Equal(t, seamgo.AccessCodeTypeTimeBound, accessCode.Type)
}
37 changes: 26 additions & 11 deletions test/integration/devices_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func TestDevices(t *testing.T) {
ctx := context.Background()
device := getTestDevice(t, seam)
assert.NotNil(t, device.Properties)
assert.Nil(t, device.Properties.AugustMetadata)

devices, err := seam.Devices.List(
ctx,
Expand Down Expand Up @@ -59,24 +58,40 @@ func TestDevices(t *testing.T) {
require.NoError(t, err)
assert.Len(t, devices, 2)

devices, err = seam.Devices.List(
// query device with id
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)

deviceWithName, err := seam.Devices.Get(
// query device by name
deviceByName, err := seam.Devices.Get(
ctx,
&seamgo.DevicesGetRequest{
Name: &device.Properties.Name,
DeviceId: &device.DeviceId,
Name: &device.DisplayName,
},
)
require.NoError(t, err)
assert.Equal(t, device.Properties.Name, deviceWithName.Properties.Name)
assert.NotNil(t, deviceByName, "Device queried by name should not be nil")
assert.Equal(t, device.DisplayName, deviceByName.DisplayName)
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 Down
Loading