Skip to content

Commit

Permalink
feat(events): Add Batch events endpoint (#169)
Browse files Browse the repository at this point in the history
* feat(events): Add Batch events endpoint

* fix specs
  • Loading branch information
jdenquin authored Jan 17, 2024
1 parent 02f22fc commit b26ba70
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
9 changes: 1 addition & 8 deletions lib/lago/api/resources/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,7 @@ def whitelist_params(params)

def whitelist_batch_params(params)
{
root_name => {
transaction_id: params[:transaction_id],
external_customer_id: params[:external_customer_id],
code: params[:code],
timestamp: params[:timestamp],
external_subscription_ids: params[:external_subscription_ids],
properties: params[:properties],
}.compact,
events: params[:events],
}
end

Expand Down
20 changes: 12 additions & 8 deletions spec/factories/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@
end

factory :batch_event, class: OpenStruct do
transaction_id { 'UNIQUE_ID' }
external_subscription_ids { %w[5eb02857-a71e-4ea2-bcf9-57d8885990ba 5eb02857-a71e-4ea2-bcf9-57d8885990ba] }
code { '123' }
timestamp { '2022-05-05T12:27:30Z' }
properties do
{
'custom_field' => 'custom'
}
events do
[
{
'transaction_id' => 'UNIQUE_ID',
'external_subscription_id' => '5eb02857-a71e-4ea2-bcf9-57d8885990ba',
'code' => '123',
'timestamp' => '2022-05-05T12:27:30Z',
'properties' => {
'custom_field' => 'custom',
},
},
]
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/lago/api/resources/event_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
context 'when event is successfully processed' do
before do
stub_request(:post, 'https://api.getlago.com/api/v1/events/batch')
.with(body: { event: params })
.with(body: params)
.to_return(body: '', status: 200)
end

Expand Down

0 comments on commit b26ba70

Please sign in to comment.