Skip to content

Commit

Permalink
Check for events existence.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgd committed Apr 24, 2024
1 parent 27840d4 commit f819c8c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
9 changes: 4 additions & 5 deletions lib/workos/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ class << self
# after a provided Event ID.
#
# @return [Hash]
def list_events(events:, options: {})
def list_events(options = {})
raise ArgumentError, 'Events parameter is required.' if options[:events].nil?

response = execute_request(
request: get_request(
path: '/events',
auth: true,
params: {
**options,
events: events,
},
params: options,
),
)

Expand Down
24 changes: 15 additions & 9 deletions spec/lib/workos/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,17 @@
it_behaves_like 'client'

describe '.list_events' do
context 'with events option' do
context 'with no options' do
it 'raises ArgumentError' do
VCR.use_cassette 'events/list_events_with_no_options' do
expect do
described_class.list_events
end.to raise_error(ArgumentError)
end
end
end

context 'with event option' do
it 'forms the proper request to the API' do
request_args = [
'/events?events=connection.activated',
Expand Down Expand Up @@ -40,10 +50,8 @@

VCR.use_cassette 'events/list_events_with_after' do
events = described_class.list_events(
after: 'event_01FGCPNV312FHFRCX0BYWHVSE1',
events: ['dsync.user.created'],
options: {
after: 'event_01FGCPNV312FHFRCX0BYWHVSE1',
},
)

expect(events.data.size).to eq(1)
Expand All @@ -54,7 +62,7 @@
context 'with the range_start and range_end options' do
it 'forms the proper request to the API' do
request_args = [
'/events?range_start=2023-01-01T00%3A00%3A00Z&range_end=2023-01-03T00%3A00%3A00Z&events=dsync.user.created',
'/events?events=dsync.user.created&range_start=2023-01-01T00%3A00%3A00Z&range_end=2023-01-03T00%3A00%3A00Z',
'Content-Type' => 'application/json'
]

Expand All @@ -66,10 +74,8 @@
VCR.use_cassette 'events/list_events_with_range' do
events = described_class.list_events(
events: ['dsync.user.created'],
options: {
range_start: '2023-01-01T00:00:00Z',
range_end: '2023-01-03T00:00:00Z',
},
range_start: '2023-01-01T00:00:00Z',
range_end: '2023-01-03T00:00:00Z',
)

expect(events.data.size).to eq(1)
Expand Down

0 comments on commit f819c8c

Please sign in to comment.