diff --git a/invitation.go b/invitation.go index d94a6bc..92d8166 100644 --- a/invitation.go +++ b/invitation.go @@ -16,6 +16,11 @@ type Invitation struct { UpdatedAt int64 `json:"updated_at"` } +type Invitations struct { + APIResource + Invitations []*Invitation `json:"data"` +} + type InvitationList struct { APIResource Invitations []*Invitation `json:"data"` diff --git a/invitation/api.go b/invitation/api.go index 2f46044..72e18d5 100644 --- a/invitation/api.go +++ b/invitation/api.go @@ -19,7 +19,7 @@ func Create(ctx context.Context, params *CreateParams) (*clerk.Invitation, error } // BulkCreate creates multiple invitations. -func BulkCreate(ctx context.Context, params *BulkCreateParams) (*clerk.InvitationList, error) { +func BulkCreate(ctx context.Context, params *BulkCreateParams) (*clerk.Invitations, error) { return getClient().BulkCreate(ctx, params) } diff --git a/invitation/client.go b/invitation/client.go index db8bdb8..1926449 100644 --- a/invitation/client.go +++ b/invitation/client.go @@ -85,30 +85,29 @@ func (b BulkCreateParams) MarshalJSON() ([]byte, error) { return json.Marshal(b.Invitations) } -type BulkCreateResponse struct { +type bulkCreateResponse struct { clerk.APIResource Invitations []*clerk.Invitation } -func (b *BulkCreateResponse) UnmarshalJSON(data []byte) error { +func (b *bulkCreateResponse) UnmarshalJSON(data []byte) error { return json.Unmarshal(data, &b.Invitations) } // BulkCreate creates multiple invitations. -func (c *Client) BulkCreate(ctx context.Context, params *BulkCreateParams) (*clerk.InvitationList, error) { +func (c *Client) BulkCreate(ctx context.Context, params *BulkCreateParams) (*clerk.Invitations, error) { req := clerk.NewAPIRequest(http.MethodPost, fmt.Sprintf("%s/bulk", path)) req.SetParams(params) - res := &BulkCreateResponse{} + res := &bulkCreateResponse{} err := c.Backend.Call(ctx, req, res) if err != nil { return nil, err } - return &clerk.InvitationList{ + return &clerk.Invitations{ APIResource: res.APIResource, Invitations: res.Invitations, - TotalCount: int64(len(res.Invitations)), }, nil } diff --git a/invitation/invitation_test.go b/invitation/invitation_test.go index a3f2998..1fad64c 100644 --- a/invitation/invitation_test.go +++ b/invitation/invitation_test.go @@ -192,11 +192,11 @@ func TestBulkInvitationCreate(t *testing.T) { }, } - invitationList, err := BulkCreate(context.Background(), ¶ms) + response, err := BulkCreate(context.Background(), ¶ms) require.NoError(t, err) - require.Equal(t, int64(len(invitations)), invitationList.TotalCount) + require.Len(t, invitations, 2) - for i, invitation := range invitationList.Invitations { + for i, invitation := range response.Invitations { require.Equal(t, ids[i], invitation.ID) require.Equal(t, emailAddresses[i], invitation.EmailAddress) }