-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add integration tests * Use exact length checks --------- Co-authored-by: Deep Singhvi <[email protected]>
- Loading branch information
Showing
12 changed files
with
744 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
# Specify files that shouldn't be modified by Fern | ||
|
||
|
||
# Integration Tests | ||
test/ | ||
|
||
# ci.yml installs Fake Seam | ||
.github/workflows/ci.yml | ||
|
||
# Add GetById client methods. | ||
accesscodes/client/get_by_id.go | ||
actionattempts/get_by_id.go | ||
clientsessions/get_by_id.go | ||
connectwebviews/get_by_id.go | ||
webhooks/get_by_id.go | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,5 +23,8 @@ jobs: | |
- name: Set up go | ||
uses: actions/setup-go@v4 | ||
|
||
- name: Install Fake Seam | ||
run: npm install -g @seamapi/[email protected] | ||
|
||
- name: Test | ||
run: go test ./... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package integration | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
seamgo "github.com/seamapi/go" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestAccessCodes(t *testing.T) { | ||
t.Parallel() | ||
|
||
seam, cleanup := newFakeSeam(t) | ||
defer cleanup() | ||
|
||
ctx := context.Background() | ||
device := getTestDevice(t, seam) | ||
initialAccessCodes, err := seam.AccessCodes.List( | ||
ctx, | ||
&seamgo.AccessCodesListRequest{ | ||
DeviceId: device.DeviceId, | ||
}, | ||
) | ||
require.NoError(t, err) | ||
|
||
createdAccessCode, err := seam.AccessCodes.Create( | ||
ctx, | ||
&seamgo.AccessCodesCreateRequest{ | ||
DeviceId: device.DeviceId, | ||
Name: seamgo.String("Test code"), | ||
Code: seamgo.String("4444"), | ||
}, | ||
) | ||
require.NoError(t, err) | ||
assert.NotNil(t, createdAccessCode.Name) | ||
assert.NotNil(t, createdAccessCode.Code) | ||
assert.Equal(t, "Test code", *createdAccessCode.Name) | ||
assert.Equal(t, "4444", *createdAccessCode.Code) | ||
assert.Equal(t, seamgo.AccessCodeStatusSetting, createdAccessCode.Status) | ||
|
||
_, err = seam.AccessCodes.Create( | ||
ctx, | ||
&seamgo.AccessCodesCreateRequest{ | ||
DeviceId: device.DeviceId, | ||
Name: seamgo.String("Test code 2"), | ||
Code: seamgo.String("5555"), | ||
}, | ||
) | ||
require.NoError(t, err) | ||
|
||
accessCodes, err := seam.AccessCodes.List( | ||
ctx, | ||
&seamgo.AccessCodesListRequest{ | ||
DeviceId: device.DeviceId, | ||
}, | ||
) | ||
require.NoError(t, err) | ||
assert.Len(t, accessCodes, len(initialAccessCodes)+2) | ||
|
||
accessCodes, err = seam.AccessCodes.List( | ||
ctx, | ||
&seamgo.AccessCodesListRequest{ | ||
DeviceId: device.DeviceId, | ||
AccessCodeIds: []string{createdAccessCode.AccessCodeId}, | ||
}, | ||
) | ||
require.NoError(t, err) | ||
assert.Len(t, accessCodes, 1) | ||
|
||
gotAccessCode, err := seam.AccessCodes.Get( | ||
ctx, | ||
&seamgo.AccessCodesGetRequest{ | ||
AccessCodeId: &createdAccessCode.AccessCodeId, | ||
}, | ||
) | ||
require.NoError(t, err) | ||
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{ | ||
AccessCodeId: createdAccessCode.AccessCodeId, | ||
Name: seamgo.String("Updated Name"), | ||
}, | ||
) | ||
require.NoError(t, err) | ||
|
||
updatedAccessCode, err := seam.AccessCodes.Get( | ||
ctx, | ||
&seamgo.AccessCodesGetRequest{ | ||
AccessCodeId: &createdAccessCode.AccessCodeId, | ||
}, | ||
) | ||
require.NoError(t, err) | ||
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) | ||
|
||
deleteAcitonAttempt, err := seam.AccessCodes.Delete( | ||
ctx, | ||
&seamgo.AccessCodesDeleteRequest{ | ||
AccessCodeId: createdAccessCode.AccessCodeId, | ||
}, | ||
) | ||
require.NoError(t, err) | ||
assert.NotNil(t, deleteAcitonAttempt.Success) | ||
|
||
deviceIds := make([]string, 0, len(accessCodes)) | ||
for _, accessCode := range accessCodes { | ||
deviceIds = append(deviceIds, accessCode.DeviceId) | ||
} | ||
createdAccessCodes, err := seam.AccessCodes.CreateMultiple( | ||
ctx, | ||
&seamgo.AccessCodesCreateMultipleRequest{ | ||
DeviceIds: deviceIds, | ||
}, | ||
) | ||
require.NoError(t, err) | ||
assert.Len(t, createdAccessCodes, 1) | ||
assert.Equal(t, len(deviceIds), len(createdAccessCodes)) | ||
|
||
commonCodes := make(map[string]struct{}) | ||
for _, createdAccessCode := range createdAccessCodes { | ||
if commonCodeKey := createdAccessCode.CommonCodeKey; commonCodeKey != nil { | ||
commonCodes[*commonCodeKey] = struct{}{} | ||
} | ||
} | ||
assert.Len(t, commonCodes, 1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package integration | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
seamgo "github.com/seamapi/go" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestActionAttempts(t *testing.T) { | ||
t.Parallel() | ||
|
||
seam, cleanup := newFakeSeam(t) | ||
defer cleanup() | ||
|
||
ctx := context.Background() | ||
device := getTestDevice(t, seam) | ||
createdAccessCode, err := seam.AccessCodes.Create( | ||
ctx, | ||
&seamgo.AccessCodesCreateRequest{ | ||
DeviceId: device.DeviceId, | ||
Name: seamgo.String("Test code"), | ||
Code: seamgo.String("4444"), | ||
}, | ||
) | ||
require.NoError(t, err) | ||
|
||
actionAttempt, err := seam.AccessCodes.Delete( | ||
ctx, | ||
&seamgo.AccessCodesDeleteRequest{ | ||
AccessCodeId: createdAccessCode.AccessCodeId, | ||
}, | ||
) | ||
require.NoError(t, err) | ||
assert.NotNil(t, actionAttempt) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package integration | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
seamgo "github.com/seamapi/go" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestConnectWebviews(t *testing.T) { | ||
t.Parallel() | ||
|
||
seam, cleanup := newFakeSeam(t) | ||
defer cleanup() | ||
|
||
ctx := context.Background() | ||
createdWebview, err := seam.ConnectWebviews.Create( | ||
ctx, | ||
&seamgo.ConnectWebviewsCreateRequest{ | ||
AcceptedProviders: []seamgo.ConnectWebviewsCreateRequestAcceptedProvidersItem{ | ||
seamgo.ConnectWebviewsCreateRequestAcceptedProvidersItemSchlage, | ||
}, | ||
}, | ||
) | ||
require.NoError(t, err) | ||
assert.NotEmpty(t, createdWebview.ConnectWebviewId) | ||
|
||
gotWebview, err := seam.ConnectWebviews.Get( | ||
ctx, | ||
&seamgo.ConnectWebviewsGetRequest{ | ||
ConnectWebviewId: createdWebview.ConnectWebviewId, | ||
}, | ||
) | ||
require.NoError(t, err) | ||
assert.Equal(t, createdWebview.ConnectWebviewId, gotWebview.ConnectWebviewId) | ||
|
||
newWebview, err := seam.ConnectWebviews.Create( | ||
ctx, | ||
&seamgo.ConnectWebviewsCreateRequest{ | ||
ProviderCategory: seamgo.ConnectWebviewsCreateRequestProviderCategoryStable.Ptr(), | ||
}, | ||
) | ||
require.NoError(t, err) | ||
assert.NotEmpty(t, newWebview.ConnectWebviewId) | ||
|
||
gotWebview, err = seam.ConnectWebviews.Get( | ||
ctx, | ||
&seamgo.ConnectWebviewsGetRequest{ | ||
ConnectWebviewId: newWebview.ConnectWebviewId, | ||
}, | ||
) | ||
require.NoError(t, err) | ||
assert.Len(t, gotWebview.AcceptedProviders, 1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package integration | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
seamgo "github.com/seamapi/go" | ||
seamclient "github.com/seamapi/go/client" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const email = "[email protected]" | ||
|
||
func TestConnectedAccounts(t *testing.T) { | ||
t.Parallel() | ||
|
||
seam, cleanup := newFakeSeam(t) | ||
defer cleanup() | ||
|
||
ctx := context.Background() | ||
connectedAccount := getTestConnectedAccount(t, seam) | ||
connectedAccountID := *connectedAccount.ConnectedAccountId | ||
|
||
connectedAccount, err := seam.ConnectedAccounts.Get( | ||
ctx, | ||
seamgo.NewConnectedAccountsGetRequestFromConnectedAccountsGetRequestConnectedAccountId( | ||
&seamgo.ConnectedAccountsGetRequestConnectedAccountId{ | ||
ConnectedAccountId: connectedAccountID, | ||
}, | ||
), | ||
) | ||
require.NoError(t, err) | ||
assert.NotNil(t, connectedAccount.ConnectedAccountId) | ||
assert.Equal(t, connectedAccountID, *connectedAccount.ConnectedAccountId) | ||
|
||
// Fake Seam does not like email creation. | ||
// emailAccount, err := seam.ConnectedAccounts.Get( | ||
// ctx, | ||
// seamgo.NewConnectedAccountsGetRequestFromConnectedAccountsGetRequestEmail( | ||
// &seamgo.ConnectedAccountsGetRequestEmail{ | ||
// Email: email, | ||
// }, | ||
// ), | ||
// ) | ||
// require.NoError(t, err) | ||
// assert.Equal(t, connectedAccountID, emailAccount.ConnectedAccountId) | ||
|
||
connectedAccounts, err := seam.ConnectedAccounts.List(ctx) | ||
require.NoError(t, err) | ||
assert.Len(t, connectedAccounts, 2) | ||
|
||
_, err = seam.ConnectedAccounts.Delete( | ||
ctx, | ||
&seamgo.ConnectedAccountsDeleteRequest{ | ||
ConnectedAccountId: connectedAccountID, | ||
}, | ||
) | ||
require.NoError(t, err) | ||
|
||
connectedAccounts, err = seam.ConnectedAccounts.List(ctx) | ||
require.NoError(t, err) | ||
assert.Len(t, connectedAccounts, 1) | ||
} | ||
|
||
func getTestConnectedAccount(t *testing.T, seam *seamclient.Client) *seamgo.ConnectedAccount { | ||
connectedAccounts, err := seam.ConnectedAccounts.List(context.Background()) | ||
require.NoError(t, err) | ||
require.GreaterOrEqual(t, len(connectedAccounts), 1) | ||
return connectedAccounts[0] | ||
} |
Oops, something went wrong.