From a4db80d951f4fc45fc861d120b21b2a1fddfba30 Mon Sep 17 00:00:00 2001 From: Pawel Date: Fri, 5 Jul 2024 12:10:46 +0200 Subject: [PATCH] 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{}{} }