From f2955321368f817a278e80e0e1be01dc6e16ab47 Mon Sep 17 00:00:00 2001 From: denio-rus Date: Wed, 25 Jun 2025 21:15:44 +0700 Subject: [PATCH] Add create report route --- CHANGELOG.md | 4 ++++ README.md | 9 +++++++ lib/boapi/client.rb | 4 ++++ spec/boapi/client_spec.rb | 41 ++++++++++++++++++++++++++++++++ spec/fixtures/report_fixtures.rb | 40 +++++++++++++++++++++++++++++++ spec/spec_helper.rb | 1 + 6 files changed, 99 insertions(+) create mode 100644 spec/fixtures/report_fixtures.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index e71fa32..4f0750b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [Released] +## [0.11.0] - 2025-06-25 + +- Add create report request + ## [0.10.0] - 2025-02-19 - Change get_balances method diff --git a/README.md b/README.md index 3b3d05e..0055305 100644 --- a/README.md +++ b/README.md @@ -224,6 +224,15 @@ response.data # {"balances"=>{"generated_at"=>"2024-08-30T13:02:00Z", "as_of_date"=>"2024-09-13T00:00:00.145823Z", "currencies"=>[{"currency"=>"BYN", "merchants"=>[{"id"=>47, "company_name"=>"John Deere LTD", "available_balance"=>100, "shops"=>[{ ... ``` +Create report +```ruby +params = { user_id: 1, type: 'balance_records_report', format: 'csv', + request_params: { currency: 'USD', merchant_id: 12, date_from: '2025-01-01T00:00:00', date_to: '2025-03-16T23:59:59' } } +client.create_report(params) +response.data +# "{\"data\":{\"report\":{\"id\":\"961c3be2-c7b0-44ab-9f79-48cabd30c519\",\"status\":\"pending\",\"type\":\"balance_records_report\",\"format\":\"csv\",\"engine\":\"oban\",\"user_id\":1,\"language\":\"en\",\"updated_at\":\"2025-06-25T13:41:38.976093Z\",\"created_at\":\"2025-06-25T13:41:38.976093Z\",\"psp_id\":1,\"generated_at\":null,\"expiry_date\":null,\"file_url\":null,\"notification_email\":null,\"request_params\":{...}}}}" +``` + ## Errors Unauthorized diff --git a/lib/boapi/client.rb b/lib/boapi/client.rb index 78d94fe..43da2f6 100644 --- a/lib/boapi/client.rb +++ b/lib/boapi/client.rb @@ -81,6 +81,10 @@ def delete_rate(id) send_request(:delete, rate_path(id)) end + def create_report(params) + send_request(:post, '/api/v2/reports', params) + end + def send_request(method, path, params = nil) response = begin diff --git a/spec/boapi/client_spec.rb b/spec/boapi/client_spec.rb index 7e84f8b..7cb84e7 100644 --- a/spec/boapi/client_spec.rb +++ b/spec/boapi/client_spec.rb @@ -528,4 +528,45 @@ end end end + + describe '.create_report' do + let(:response) do + Boapi::Client.new(account_id: account_id, account_secret: account_secret).create_report(params) + end + let(:http_status) { 201 } + + let(:url) { "#{Boapi.configuration.api_host}/api/v2/reports" } + let(:report_request_params) do + { + date_from: '2025-01-01T00:00:00+00:00', + date_to: '2025-03-16T23:59:59+00:00', + currency: 'USD', + merchant_id: 12, + shop_id: 12, + gateway_id: 12 + } + end + let(:params) do + { + id: '961c3be2-c7b0-44ab-9f79-48cabd30c519', + user_id: 1, + type: 'balance_records_report', + format: 'csv', + request_params: report_request_params + } + end + + before do + stub_request(:post, url).with(body: params.to_json) + .to_return(status: http_status, body: ReportFixtures.successful_create_report_response) + end + + it 'returns successful response' do + expect(response.status).to be http_status + + expect(response.success?).to be true + expect(response.error?).to be false + expect(response.data).to eq(ReportFixtures.successful_create_report_response_message) + end + end end diff --git a/spec/fixtures/report_fixtures.rb b/spec/fixtures/report_fixtures.rb new file mode 100644 index 0000000..dd716ae --- /dev/null +++ b/spec/fixtures/report_fixtures.rb @@ -0,0 +1,40 @@ +# frozen_string_literal: true + +# rubocop:disable Metrics/MethodLength +module ReportFixtures + module_function + + def successful_create_report_response_message + { + 'report' => { + 'id' => '961c3be2-c7b0-44ab-9f79-48cabd30c519', + 'status' => 'pending', + 'type' => 'balance_records_report', + 'format' => 'csv', + 'engine' => 'oban', + 'user_id' => 1, + 'language' => 'en', + 'updated_at' => '2025-06-25T13:41:38.976093Z', + 'created_at' => '2025-06-25T13:41:38.976093Z', + 'psp_id' => 1, + 'generated_at' => nil, + 'expiry_date' => nil, + 'file_url' => nil, + 'notification_email' => nil, + 'request_params' => { + 'currency' => 'USD', + 'merchant_id' => 12, + 'shop_id' => 12, + 'gateway_id' => 12, + 'date_from' => '2025-01-01T00:00:00+00:00', + 'date_to' => '2025-03-16T23:59:59+00:00' + } + } + } + end + + def successful_create_report_response + %({"data":#{successful_create_report_response_message.to_json}}) + end +end +# rubocop:enable Metrics/MethodLength diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3b85a5d..6886cf2 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,6 +9,7 @@ require 'fixtures/transaction_fixtures' require 'fixtures/balance_fixtures' require 'fixtures/balance_record_fixtures' +require 'fixtures/report_fixtures' WebMock.disable_net_connect!(allow_localhost: false)