Skip to content

Commit

Permalink
wip: more fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kainpets committed Jul 5, 2024
1 parent 50b534c commit a4db80d
Showing 1 changed file with 15 additions and 33 deletions.
48 changes: 15 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,55 +99,44 @@ 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)
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{
DeviceIds: deviceIds,
},
)
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{}{}
}
Expand Down

0 comments on commit a4db80d

Please sign in to comment.