Skip to content

Commit

Permalink
🌿 Add integration tests (#2)
Browse files Browse the repository at this point in the history
* Add integration tests

* Use exact length checks

---------

Co-authored-by: Deep Singhvi <[email protected]>
  • Loading branch information
amckinney and dsinghvi authored Oct 28, 2023
1 parent 3c6d015 commit 94a66bb
Show file tree
Hide file tree
Showing 12 changed files with 744 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .fernignore
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

3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
163 changes: 163 additions & 0 deletions test/integration/access_codes_test.go
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)
}
38 changes: 38 additions & 0 deletions test/integration/action_attempts_test.go
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)
}
56 changes: 56 additions & 0 deletions test/integration/connect_webviews_test.go
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)
}
71 changes: 71 additions & 0 deletions test/integration/connected_accounts_test.go
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]
}
Loading

0 comments on commit 94a66bb

Please sign in to comment.