Skip to content

Commit

Permalink
Make events parameter required for list_events (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgd authored Jun 6, 2024
1 parent 519531a commit a2cabff
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 39 deletions.
2 changes: 2 additions & 0 deletions lib/workos/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class << self
#
# @return [Hash]
def list_events(options = {})
raise ArgumentError, 'Events parameter is required.' if options[:events].nil?

response = execute_request(
request: get_request(
path: '/events',
Expand Down
23 changes: 11 additions & 12 deletions spec/lib/workos/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@

describe '.list_events' do
context 'with no options' do
it 'returns events and metadata' do
expected_metadata = {
'after' => nil,
}

it 'raises ArgumentError' do
VCR.use_cassette 'events/list_events_with_no_options' do
events = described_class.list_events

expect(events.data.size).to eq(1)
expect(events.list_metadata).to eq(expected_metadata)
expect do
described_class.list_events
end.to raise_error(ArgumentError)
end
end
end
Expand Down Expand Up @@ -44,7 +39,7 @@
context 'with the after option' do
it 'forms the proper request to the API' do
request_args = [
'/events?after=event_01FGCPNV312FHFRCX0BYWHVSE1',
'/events?after=event_01FGCPNV312FHFRCX0BYWHVSE1&events=dsync.user.created',
'Content-Type' => 'application/json'
]

Expand All @@ -54,7 +49,10 @@
and_return(expected_request)

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

expect(events.data.size).to eq(1)
end
Expand All @@ -64,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?events=dsync.user.created&range_start=2023-01-01T00%3A00%3A00Z&range_end=2023-01-03T00%3A00%3A00Z',
'Content-Type' => 'application/json'
]

Expand All @@ -75,6 +73,7 @@

VCR.use_cassette 'events/list_events_with_range' do
events = described_class.list_events(
events: ['dsync.user.created'],
range_start: '2023-01-01T00:00:00Z',
range_end: '2023-01-03T00:00:00Z',
)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a2cabff

Please sign in to comment.