From abb6ea5d5b826b313c812be129bd65f4fa0f1768 Mon Sep 17 00:00:00 2001 From: Pawel Date: Fri, 5 Jul 2024 11:02:25 +0200 Subject: [PATCH 1/6] wip: fix tests --- test/integration/access_codes_test.go | 2 +- test/integration/devices_test.go | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/test/integration/access_codes_test.go b/test/integration/access_codes_test.go index 77a46ab..22745fd 100644 --- a/test/integration/access_codes_test.go +++ b/test/integration/access_codes_test.go @@ -137,7 +137,7 @@ func TestAccessCodes(t *testing.T) { }, ) require.NoError(t, err) - assert.NotNil(t, deleteResponse.ActionAttempt.Success) + assert.NotNil(t, deleteResponse.ActionAttempt.ActionAttemptActionAttemptId.Result) deviceIds := make([]string, 0, len(accessCodes)) for _, accessCode := range accessCodes { diff --git a/test/integration/devices_test.go b/test/integration/devices_test.go index e6887c5..6c645fb 100644 --- a/test/integration/devices_test.go +++ b/test/integration/devices_test.go @@ -19,7 +19,8 @@ func TestDevices(t *testing.T) { ctx := context.Background() device := getTestDevice(t, seam) assert.NotNil(t, device.Properties) - assert.Nil(t, device.Properties.AugustMetadata) + // AugustMetadata is no longer available for some reason + // assert.Nil(t, device.Properties.AugustMetadata) devices, err := seam.Devices.List( ctx, @@ -71,12 +72,12 @@ func TestDevices(t *testing.T) { deviceWithName, err := seam.Devices.Get( ctx, &seamgo.DevicesGetRequest{ - Name: &device.Properties.Name, + Name: &device.DisplayName, DeviceId: &device.DeviceId, }, ) require.NoError(t, err) - assert.Equal(t, device.Properties.Name, deviceWithName.Properties.Name) + assert.Equal(t, device.DisplayName, deviceWithName.DisplayName) locks, err := seam.Locks.List( ctx, @@ -100,4 +101,4 @@ func getTestDevice(t *testing.T, seam *seamclient.Client) *seamgo.Device { require.NoError(t, err) require.GreaterOrEqual(t, len(devices), 1) return devices[0] -} +} \ No newline at end of file From 50b534c1ce6d022e68127b7124d91a8963243d01 Mon Sep 17 00:00:00 2001 From: Pawel Date: Fri, 5 Jul 2024 11:58:56 +0200 Subject: [PATCH 2/6] use device id for querying --- test/integration/devices_test.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/integration/devices_test.go b/test/integration/devices_test.go index 6c645fb..a6f9988 100644 --- a/test/integration/devices_test.go +++ b/test/integration/devices_test.go @@ -19,8 +19,6 @@ func TestDevices(t *testing.T) { ctx := context.Background() device := getTestDevice(t, seam) assert.NotNil(t, device.Properties) - // AugustMetadata is no longer available for some reason - // assert.Nil(t, device.Properties.AugustMetadata) devices, err := seam.Devices.List( ctx, @@ -69,15 +67,14 @@ func TestDevices(t *testing.T) { require.NoError(t, err) assert.Len(t, devices, 1) - deviceWithName, err := seam.Devices.Get( + deviceWithId, err := seam.Devices.Get( ctx, &seamgo.DevicesGetRequest{ - Name: &device.DisplayName, DeviceId: &device.DeviceId, }, ) require.NoError(t, err) - assert.Equal(t, device.DisplayName, deviceWithName.DisplayName) + assert.Equal(t, device.DisplayName, deviceWithId.DisplayName) locks, err := seam.Locks.List( ctx, From a4db80d951f4fc45fc861d120b21b2a1fddfba30 Mon Sep 17 00:00:00 2001 From: Pawel Date: Fri, 5 Jul 2024 12:10:46 +0200 Subject: [PATCH 3/6] wip: more fix tests --- test/integration/access_codes_test.go | 48 +++++++++------------------ 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/test/integration/access_codes_test.go b/test/integration/access_codes_test.go index 22745fd..f3d008f 100644 --- a/test/integration/access_codes_test.go +++ b/test/integration/access_codes_test.go @@ -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{ @@ -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) @@ -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{ @@ -106,30 +99,10 @@ 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{ @@ -137,12 +110,19 @@ func TestAccessCodes(t *testing.T) { }, ) require.NoError(t, err) + require.NotNil(t, deleteResponse, "Delete response should not be nil") + require.NotNil(t, deleteResponse.ActionAttempt, "Action attempt should not be nil") + require.NotNil(t, deleteResponse.ActionAttempt.ActionAttemptActionAttemptId, "Action attempt ID should not be nil") assert.NotNil(t, deleteResponse.ActionAttempt.ActionAttemptActionAttemptId.Result) deviceIds := make([]string, 0, len(accessCodes)) for _, accessCode := range accessCodes { deviceIds = append(deviceIds, accessCode.DeviceId) } + + // Add a check to ensure deviceIds is not empty + require.NotEmpty(t, deviceIds, "Device IDs slice should not be empty") + createdAccessCodes, err := seam.AccessCodes.CreateMultiple( ctx, &seamgo.AccessCodesCreateMultipleRequest{ @@ -150,11 +130,13 @@ func TestAccessCodes(t *testing.T) { }, ) require.NoError(t, err) - assert.Len(t, createdAccessCodes, 1) + require.NotNil(t, createdAccessCodes, "Created access codes should not be nil") + 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{}{} } From 80ecf831d96e278480dbe101acca1f9892a88dce Mon Sep 17 00:00:00 2001 From: Pawel Date: Fri, 5 Jul 2024 13:19:02 +0200 Subject: [PATCH 4/6] revert commented out code --- test/integration/access_codes_test.go | 36 ++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/test/integration/access_codes_test.go b/test/integration/access_codes_test.go index f3d008f..7fe6651 100644 --- a/test/integration/access_codes_test.go +++ b/test/integration/access_codes_test.go @@ -112,15 +112,12 @@ func TestAccessCodes(t *testing.T) { require.NoError(t, err) require.NotNil(t, deleteResponse, "Delete response should not be nil") require.NotNil(t, deleteResponse.ActionAttempt, "Action attempt should not be nil") - require.NotNil(t, deleteResponse.ActionAttempt.ActionAttemptActionAttemptId, "Action attempt ID should not be nil") - assert.NotNil(t, deleteResponse.ActionAttempt.ActionAttemptActionAttemptId.Result) deviceIds := make([]string, 0, len(accessCodes)) for _, accessCode := range accessCodes { deviceIds = append(deviceIds, accessCode.DeviceId) } - // Add a check to ensure deviceIds is not empty require.NotEmpty(t, deviceIds, "Device IDs slice should not be empty") createdAccessCodes, err := seam.AccessCodes.CreateMultiple( @@ -142,4 +139,37 @@ func TestAccessCodes(t *testing.T) { } } 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) } From fa97a3da1c44b77bbb965a18372d424bac77da30 Mon Sep 17 00:00:00 2001 From: Pawel Date: Fri, 5 Jul 2024 14:11:02 +0200 Subject: [PATCH 5/6] add additional checks --- test/integration/access_codes_test.go | 1 + test/integration/devices_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/test/integration/access_codes_test.go b/test/integration/access_codes_test.go index 7fe6651..d87ecb8 100644 --- a/test/integration/access_codes_test.go +++ b/test/integration/access_codes_test.go @@ -128,6 +128,7 @@ func TestAccessCodes(t *testing.T) { ) 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)) diff --git a/test/integration/devices_test.go b/test/integration/devices_test.go index a6f9988..2ccaece 100644 --- a/test/integration/devices_test.go +++ b/test/integration/devices_test.go @@ -58,6 +58,7 @@ func TestDevices(t *testing.T) { require.NoError(t, err) assert.Len(t, devices, 2) + // query device with id devices, err = seam.Devices.List( ctx, &seamgo.DevicesListRequest{ @@ -76,6 +77,32 @@ func TestDevices(t *testing.T) { 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) + locks, err := seam.Locks.List( ctx, nil, From fa02cbb6566718cdbbe78e6e8241b90eacac6644 Mon Sep 17 00:00:00 2001 From: Pawel Date: Fri, 5 Jul 2024 14:15:45 +0200 Subject: [PATCH 6/6] test querying for devices --- test/integration/devices_test.go | 58 +++++++++++++------------------- 1 file changed, 24 insertions(+), 34 deletions(-) diff --git a/test/integration/devices_test.go b/test/integration/devices_test.go index 2ccaece..a59ef10 100644 --- a/test/integration/devices_test.go +++ b/test/integration/devices_test.go @@ -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, @@ -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] -} \ No newline at end of file +}