From bc8faaedddcf0450dba776fca9ec799c8761e4c3 Mon Sep 17 00:00:00 2001 From: mroloux Date: Tue, 17 Oct 2023 13:33:29 +0200 Subject: [PATCH] Added usage_cutoff_date to summary report for all months (#91) * Added usage_cutoff_date to summary report for all months * Fixed test name * Exposed DEMO_COMPANY_SECRET_KEY to tests --- .github/workflows/build.yml | 2 ++ lib/seatsio/domain.rb | 20 ++++++------ lib/seatsio/usage_reports.rb | 2 +- test/events/create_events_test.rb | 2 +- test/reports/usage/usage_reports_test.rb | 39 ++++++++++++++++++++++++ test/seatsio_test_client.rb | 10 ++++++ 6 files changed, 64 insertions(+), 11 deletions(-) create mode 100644 test/reports/usage/usage_reports_test.rb diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 561b89e..bdee497 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -24,3 +24,5 @@ jobs: with: timezone: Europe/Brussels - run: bundle exec rake + env: + DEMO_COMPANY_SECRET_KEY: ${{ secrets.DEMO_COMPANY_SECRET_KEY }} diff --git a/lib/seatsio/domain.rb b/lib/seatsio/domain.rb index b39490e..9afc505 100644 --- a/lib/seatsio/domain.rb +++ b/lib/seatsio/domain.rb @@ -419,18 +419,22 @@ def initialize(data) end class UsageSummaryForAllMonths - attr_reader :items + attr_reader :usage_cutoff_date, :usage def initialize(data) - items = [] - data.each do |item| - items << UsageSummaryForMonth.new(item) + usage = [] + data['usage'].each do |item| + usage << UsageSummaryForMonth.new(item) end - @items = items + @usage = usage + @usage_cutoff_date = DateTime.iso8601(data['usageCutoffDate']) end end class UsageSummaryForMonth + + attr_reader :month, :num_used_objects + def initialize(data) @month = Month.from_json(data['month']) @num_used_objects = data['numUsedObjects'] @@ -489,7 +493,7 @@ def initialize(data) class UsageForObjectV1 - attr_reader :object, :num_first_bookings, :first_booking_date, :num_first_bookings, :num_first_bookings_or_selections + attr_reader :object, :num_first_bookings, :first_booking_date, :num_first_selections, :num_first_bookings_or_selections def initialize(data) @object = data['object'] @@ -516,9 +520,7 @@ class Month attr_reader :year, :month def self.from_json(data) - @year = data['year'] - @month = data['month'] - self + return Month.new(data['year'], data['month']) end def initialize(year, month) diff --git a/lib/seatsio/usage_reports.rb b/lib/seatsio/usage_reports.rb index b57aad4..c31e2d3 100644 --- a/lib/seatsio/usage_reports.rb +++ b/lib/seatsio/usage_reports.rb @@ -11,7 +11,7 @@ def initialize(http_client) end def summary_for_all_months - url = "reports/usage" + url = "reports/usage?version=2" body = @http_client.get(url) UsageSummaryForAllMonths.new(body) end diff --git a/test/events/create_events_test.rb b/test/events/create_events_test.rb index 748e36d..3e9c4ba 100644 --- a/test/events/create_events_test.rb +++ b/test/events/create_events_test.rb @@ -2,7 +2,7 @@ require 'util' require 'seatsio/domain' -class ChartReportsTest < SeatsioTestClient +class CreateEventsTest < SeatsioTestClient def test_multiple_events chart_key = create_test_chart diff --git a/test/reports/usage/usage_reports_test.rb b/test/reports/usage/usage_reports_test.rb new file mode 100644 index 0000000..a0e8aca --- /dev/null +++ b/test/reports/usage/usage_reports_test.rb @@ -0,0 +1,39 @@ +require 'test_helper' +require 'util' +require 'seatsio/domain' +require 'seatsio/exception' + +class UsageReportsTest < SeatsioTestClient + def test_usage_report_for_all_months + assert_demo_company_secret_key_set + client = test_client(demo_company_secret_key, nil) + + report = client.usage_reports.summary_for_all_months + + assert_not_nil(report.usage_cutoff_date) + assert_true(report.usage.length > 0) + assert_equal(2014, report.usage[0].month.year) + assert_equal(2, report.usage[0].month.month) + end + + def test_usage_report_month + assert_demo_company_secret_key_set + client = test_client(demo_company_secret_key, nil) + + report = client.usage_reports.details_for_month(Seatsio::Month.new(2021, 11)) + + assert_true(report.length > 0) + assert_true(report[0].usage_by_chart.length > 0) + assert_equal(143, report[0].usage_by_chart[0].usage_by_event[0].num_used_objects) + end + + def test_usage_report_event_in_month + assert_demo_company_secret_key_set + client = test_client(demo_company_secret_key, nil) + + report = client.usage_reports.details_for_event_in_month(580293, Seatsio::Month.new(2021, 11)) + + assert_true(report.length > 0) + assert_equal(1, report[0].num_first_selections) + end +end diff --git a/test/seatsio_test_client.rb b/test/seatsio_test_client.rb index 83c3e8b..474e362 100644 --- a/test/seatsio_test_client.rb +++ b/test/seatsio_test_client.rb @@ -28,4 +28,14 @@ def wait_for_status_changes(event, num_status_changes) end end end + + def demo_company_secret_key + ENV["DEMO_COMPANY_SECRET_KEY"] + end + + def assert_demo_company_secret_key_set + if demo_company_secret_key.nil? + skip "DEMO_COMPANY_SECRET_KEY environment variable not set, skipping test" + end + end end