Skip to content

Commit

Permalink
Add test for invite
Browse files Browse the repository at this point in the history
  • Loading branch information
kwoodhouse93 committed Nov 4, 2022
1 parent 2ed8ec9 commit f505e4b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 10 deletions.
9 changes: 8 additions & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,20 @@ type Client interface {
// Among other things, the response also contains the query params of the action
// link as separate JSON fields for convenience (along with the email OTP from
// which the corresponding token is generated).
//
// Requires admin token.
AdminGenerateLink(req types.AdminGenerateLinkRequest) (*types.AdminGenerateLinkResponse, error)
// POST /admin/users
//
// Creates the user based on the user_id specified.
//
// Requires admin token.
AdminCreateUser(req types.AdminCreateUserRequest) (*types.AdminCreateUserResponse, error)
// GET /admin/users
//
// Get a list of users.
//
// Requires admin token.
AdminListUsers() (*types.AdminListUsersResponse, error)

// GET /health
Expand All @@ -61,7 +67,8 @@ type Client interface {
// POST /invite
//
// Invites a new user with an email.
// This endpoint requires the service_role or supabase_admin JWT set using WithToken.
//
// Requires service_role or admin token.
Invite(req types.InviteRequest) (*types.InviteResponse, error)

// GET /settings
Expand Down
2 changes: 1 addition & 1 deletion integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func withAdmin(c gotrue.Client) gotrue.Client {
}

func TestMain(m *testing.M) {
// Please refer to docker-compose.yaml and /testing/README.md for more info
// Please refer to ./setup/docker-compose.yaml and ./README.md for more info
// on this test set up.
client = gotrue.New(projectReference, apiKey).WithCustomGoTrueURL("http://localhost:9999")
autoconfirmClient = gotrue.New(projectReference, apiKey).WithCustomGoTrueURL("http://localhost:9998")
Expand Down
30 changes: 30 additions & 0 deletions integration_test/invite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package integration_test

import (
"testing"
"time"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/kwoodhouse93/gotrue-go/types"
)

func TestInvite(t *testing.T) {
assert := assert.New(t)
require := require.New(t)

admin := withAdmin(client)

email := randomEmail()
user, err := admin.Invite(types.InviteRequest{
Email: email,
})
require.NoError(err)
assert.NotEqual(user.ID, uuid.Nil)
assert.Equal(email, user.Email)
assert.InDelta(time.Now().Unix(), user.CreatedAt.Unix(), float64(time.Second))
assert.InDelta(time.Now().Unix(), user.UpdatedAt.Unix(), float64(time.Second))
assert.InDelta(time.Now().Unix(), user.InvitedAt.Unix(), float64(time.Second))
}
11 changes: 3 additions & 8 deletions types/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
"errors"
"fmt"
"time"
)

// --- Errors ---
Expand Down Expand Up @@ -81,16 +80,12 @@ type HealthCheckResponse struct {
}

type InviteRequest struct {
Email string `json:"email"`
Email string `json:"email"`
Data map[string]interface{} `json:"data"`
}

type InviteResponse struct {
ID string `json:"id"`
Email string `json:"email"`
ConfirmationSentAt time.Time `json:"confirmation_sent_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
InvitedAt time.Time `json:"invited_at"`
User
}

type ExternalProviders struct {
Expand Down

0 comments on commit f505e4b

Please sign in to comment.