Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add expiration support to invitations #327

Merged
merged 1 commit into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading