Skip to content

Commit

Permalink
Add OrganizationId parameter to Events API (#330)
Browse files Browse the repository at this point in the history
* Add organizationId to events

* Clean spacing

* Update casing
  • Loading branch information
alisherry authored Apr 30, 2024
1 parent ec25425 commit 90b594d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/events/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ type ListEventsOpts struct {

// Date range end for stream of Events.
RangeEnd string `url:"range_end,omitempty"`

OrganizationId string `url:"organization_id,omitempty"`
}

// GetEventsResponse describes the response structure when requesting
Expand Down
33 changes: 33 additions & 0 deletions pkg/events/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,39 @@ func TestListEvents(t *testing.T) {
require.NoError(t, err)
require.Equal(t, expectedResponse, events)
})

t.Run("ListEvents succeeds to fetch Events with an organization_id", func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(ListEventsTestHandler))
defer server.Close()
client := &Client{
HTTPClient: server.Client(),
Endpoint: server.URL,
APIKey: "test",
}

params := ListEventsOpts{
Events: []string{"dsync.user.created"},
OrganizationId: "org_1234",
}

expectedResponse := ListEventsResponse{
Data: []Event{
{
ID: "event_abcd1234",
Event: "dsync.user.created",
Data: json.RawMessage(`{"foo":"bar"}`),
},
},
ListMetadata: common.ListMetadata{
After: "",
},
}

events, err := client.ListEvents(context.Background(), params)

require.NoError(t, err)
require.Equal(t, expectedResponse, events)
})
}

func ListEventsTestHandler(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 90b594d

Please sign in to comment.