Skip to content

Commit

Permalink
feat: Add expiration support to invitations (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
kostaspt authored Sep 20, 2024
1 parent ff233cb commit 1e54584
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions invitation.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Invitation struct {
Revoked bool `json:"revoked,omitempty"`
Status string `json:"status"`
URL string `json:"url,omitempty"`
ExpiresAt *int64 `json:"expires_at"`
CreatedAt int64 `json:"created_at"`
UpdatedAt int64 `json:"updated_at"`
}
Expand Down
1 change: 1 addition & 0 deletions invitation/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type CreateParams struct {
RedirectURL *string `json:"redirect_url,omitempty"`
Notify *bool `json:"notify,omitempty"`
IgnoreExisting *bool `json:"ignore_existing,omitempty"`
ExpiresInDays *int64 `json:"expires_in_days,omitempty"`
}

// Create adds a new identifier to the allowlist.
Expand Down
27 changes: 27 additions & 0 deletions invitation/invitation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,33 @@ func TestInvitationCreate(t *testing.T) {
require.Equal(t, emailAddress, invitation.EmailAddress)
}

func TestInvitationCreateWithExpiration(t *testing.T) {
emailAddress := "[email protected]"
id := "inv_123"
expiresInDays := int64(7)
expiresAt := int64(1700000000)
clerk.SetBackend(clerk.NewBackend(&clerk.BackendConfig{
HTTPClient: &http.Client{
Transport: &clerktest.RoundTripper{
T: t,
In: json.RawMessage(fmt.Sprintf(`{"email_address":"%s","expires_in_days":%d}`, emailAddress, expiresInDays)),
Out: json.RawMessage(fmt.Sprintf(`{"id":"%s","email_address":"%s","expires_at":%d}`, id, emailAddress, expiresAt)),
Method: http.MethodPost,
Path: "/v1/invitations",
},
},
}))

invitation, err := Create(context.Background(), &CreateParams{
EmailAddress: emailAddress,
ExpiresInDays: &expiresInDays,
})
require.NoError(t, err)
require.Equal(t, id, invitation.ID)
require.Equal(t, emailAddress, invitation.EmailAddress)
require.Equal(t, expiresAt, *invitation.ExpiresAt)
}

func TestInvitationCreate_Error(t *testing.T) {
clerk.SetBackend(clerk.NewBackend(&clerk.BackendConfig{
HTTPClient: &http.Client{
Expand Down

0 comments on commit 1e54584

Please sign in to comment.