Skip to content

Commit

Permalink
Added usage_cutoff_date to summary report for all months (#91)
Browse files Browse the repository at this point in the history
* Added usage_cutoff_date to summary report for all months

* Fixed test name

* Exposed DEMO_COMPANY_SECRET_KEY to tests
  • Loading branch information
mroloux authored Oct 17, 2023
1 parent d8eb018 commit bc8faae
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ jobs:
with:
timezone: Europe/Brussels
- run: bundle exec rake
env:
DEMO_COMPANY_SECRET_KEY: ${{ secrets.DEMO_COMPANY_SECRET_KEY }}
20 changes: 11 additions & 9 deletions lib/seatsio/domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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']
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/seatsio/usage_reports.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/events/create_events_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
require 'util'
require 'seatsio/domain'

class ChartReportsTest < SeatsioTestClient
class CreateEventsTest < SeatsioTestClient

def test_multiple_events
chart_key = create_test_chart
Expand Down
39 changes: 39 additions & 0 deletions test/reports/usage/usage_reports_test.rb
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions test/seatsio_test_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit bc8faae

Please sign in to comment.