Skip to content

Commit

Permalink
Added tests for usage reports
Browse files Browse the repository at this point in the history
Added usageCutoffDate to summary report for all months
  • Loading branch information
mroloux committed Oct 13, 2023
1 parent afab41c commit f6123a7
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 34 deletions.
4 changes: 3 additions & 1 deletion src/main/java/seatsio/reports/usage/Month.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package seatsio.reports.usage;

import seatsio.util.ValueObject;

import static org.apache.commons.lang3.StringUtils.leftPad;

public class Month {
public class Month extends ValueObject {

public int month;
public int year;
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/seatsio/reports/usage/UsageReports.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import seatsio.reports.usage.detailsForEventInMonth.UsageForObjectV1;
import seatsio.reports.usage.detailsForEventInMonth.UsageForObjectV2;
import seatsio.reports.usage.detailsForMonth.UsageDetails;
import seatsio.reports.usage.summaryForMonths.UsageSummaryForAllMonths;
import seatsio.reports.usage.summaryForMonths.UsageSummaryForMonth;
import seatsio.util.UnirestWrapper;

Expand All @@ -24,11 +25,9 @@ public UsageReports(String baseUrl, UnirestWrapper unirest) {
this.unirest = unirest;
}

public List<UsageSummaryForMonth> summaryForAllMonths() {
String response = unirest.stringResponse(get(baseUrl + "/reports/usage"));
TypeToken<List<UsageSummaryForMonth>> typeToken = new TypeToken<>() {
};
return gson().fromJson(response, typeToken.getType());
public UsageSummaryForAllMonths summaryForAllMonths() {
String response = unirest.stringResponse(get(baseUrl + "/reports/usage?version=2"));
return gson().fromJson(response, UsageSummaryForAllMonths.class);
}

public List<UsageDetails> detailsForMonth(Month month) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
package seatsio.reports.usage.detailsForEventInMonth;

import seatsio.util.ValueObject;

import java.time.Instant;

public class UsageForObjectV1 {
public class UsageForObjectV1 extends ValueObject {

public final String object;
public final int numFirstBookings;
public final Instant firstBookingDate;
public final int numFirstSelections;
public final int numFirstBookingsOrSelections;

public String object;
public int numFirstBookings;
public Instant firstBookingDate;
public int numFirstSelections;
public int numFirstBookingsOrSelections;
public UsageForObjectV1(String object, int numFirstBookings, Instant firstBookingDate, int numFirstSelections, int numFirstBookingsOrSelections) {
this.object = object;
this.numFirstBookings = numFirstBookings;
this.firstBookingDate = firstBookingDate;
this.numFirstSelections = numFirstSelections;
this.numFirstBookingsOrSelections = numFirstBookingsOrSelections;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package seatsio.reports.usage.detailsForEventInMonth;

import seatsio.reports.usage.UsageReason;
import seatsio.util.ValueObject;

import java.util.Map;

public class UsageForObjectV2 {
public class UsageForObjectV2 extends ValueObject {

public String object;
public int numUsedObjects;
public Map<UsageReason, Integer> usageByReason;
public final String object;
public final int numUsedObjects;
public final Map<UsageReason, Integer> usageByReason;

public UsageForObjectV2(String object, int numUsedObjects, Map<UsageReason, Integer> usageByReason) {
this.object = object;
this.numUsedObjects = numUsedObjects;
this.usageByReason = usageByReason;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package seatsio.reports.usage.detailsForMonth;

import seatsio.util.ValueObject;

import java.util.List;

public class UsageByChart {
public class UsageByChart extends ValueObject {

public final UsageChart chart;
public final List<UsageByEvent> usageByEvent;

public UsageChart chart;
public List<UsageByEvent> usageByEvent;
public UsageByChart(UsageChart chart, List<UsageByEvent> usageByEvent) {
this.chart = chart;
this.usageByEvent = usageByEvent;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package seatsio.reports.usage.detailsForMonth;

public class UsageByEvent {
import seatsio.util.ValueObject;

public UsageEvent event;
public int numUsedObjects;
public class UsageByEvent extends ValueObject {

public final UsageEvent event;
public final int numUsedObjects;

public UsageByEvent(UsageEvent event, int numUsedObjects) {
this.event = event;
this.numUsedObjects = numUsedObjects;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
package seatsio.reports.usage.detailsForMonth;

public class UsageChart {
import seatsio.util.ValueObject;

public String name;
public String key;
public class UsageChart extends ValueObject {

public final String name;
public final String key;

public UsageChart(String name, String key) {
this.name = name;
this.key = key;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
package seatsio.reports.usage.detailsForMonth;

import seatsio.util.ValueObject;

import java.util.List;

public class UsageDetails {
public class UsageDetails extends ValueObject {

public final Long workspace;
public final List<UsageByChart> usageByChart;

public Long workspace;
public List<UsageByChart> usageByChart;
public UsageDetails(Long workspace, List<UsageByChart> usageByChart) {
this.workspace = workspace;
this.usageByChart = usageByChart;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
package seatsio.reports.usage.detailsForMonth;

public class UsageEvent {
import seatsio.util.ValueObject;

public long id;
public String key;
public class UsageEvent extends ValueObject {

public final long id;
public final String key;
public final boolean deleted;

public UsageEvent(long id, String key, boolean deleted) {
this.id = id;
this.key = key;
this.deleted = deleted;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package seatsio.reports.usage.summaryForMonths;

import seatsio.util.ValueObject;

import java.time.Instant;
import java.util.List;

public class UsageSummaryForAllMonths extends ValueObject {

public final Instant usageCutoffDate;
public final List<UsageSummaryForMonth> usage;

public UsageSummaryForAllMonths(Instant usageCutoffDate, List<UsageSummaryForMonth> usage) {
this.usageCutoffDate = usageCutoffDate;
this.usage = usage;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package seatsio.reports.usage.summaryForMonths;

import seatsio.reports.usage.Month;
import seatsio.util.ValueObject;

public class UsageSummaryForMonth {
public class UsageSummaryForMonth extends ValueObject {

public Month month;
public int numUsedObjects;
public final Month month;
public final int numUsedObjects;

public UsageSummaryForMonth(Month month, int numUsedObjects) {
this.month = month;
this.numUsedObjects = numUsedObjects;
}
}
8 changes: 8 additions & 0 deletions src/test/java/seatsio/SeatsioClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ protected String createTestChart(String fileName) {
return chartKey;
}

protected String demoCompanySecretKey() {
return System.getenv("DEMO_COMPANY_SECRET_KEY");
}

protected boolean isDemoCompanySecretKeySet() {
return System.getenv().containsKey("DEMO_COMPANY_SECRET_KEY");
}

private String testChartJson(String fileName) {
try {
InputStream testChartJson = SeatsioClientTest.class.getResourceAsStream(fileName);
Expand Down
58 changes: 58 additions & 0 deletions src/test/java/seatsio/reports/usage/UsageReportTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package seatsio.reports.usage;

import org.junit.jupiter.api.Test;
import seatsio.SeatsioClient;
import seatsio.SeatsioClientTest;
import seatsio.reports.usage.detailsForEventInMonth.UsageForObjectV1;
import seatsio.reports.usage.detailsForMonth.UsageByEvent;
import seatsio.reports.usage.detailsForMonth.UsageDetails;
import seatsio.reports.usage.detailsForMonth.UsageEvent;
import seatsio.reports.usage.summaryForMonths.UsageSummaryForAllMonths;

import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assumptions.assumeTrue;

public class UsageReportTest extends SeatsioClientTest {

@Test
public void usageReportForAllMonths() {
assumeTrue(isDemoCompanySecretKeySet());

SeatsioClient client = seatsioClient(demoCompanySecretKey());

UsageSummaryForAllMonths report = client.usageReports.summaryForAllMonths();

assertThat(report.usageCutoffDate).isNotNull();
assertThat(report.usage.size()).isGreaterThan(0);
assertThat(report.usage.get(0).month).isEqualTo(new Month(2014, 2));
}

@Test
public void usageReportForMonth() {
assumeTrue(isDemoCompanySecretKeySet());

SeatsioClient client = seatsioClient(demoCompanySecretKey());

List<UsageDetails> report = client.usageReports.detailsForMonth(new Month(2021, 11));

assertThat(report.size()).isGreaterThan(0);
assertThat(report.get(0).usageByChart.size()).isGreaterThan(0);
assertThat(report.get(0).usageByChart.get(0).usageByEvent).containsExactly(new UsageByEvent(
new UsageEvent(580293, "largeStadiumEvent", false), 143
));
}

@Test
public void usageReportForEventInMonth() {
assumeTrue(isDemoCompanySecretKeySet());

SeatsioClient client = seatsioClient(demoCompanySecretKey());

List<?> report = client.usageReports.detailsForEventInMonth(580293, new Month(2021, 11));

assertThat(report.size()).isGreaterThan(0);
assertThat((UsageForObjectV1) report.get(0)).isEqualTo(new UsageForObjectV1("102-9-14", 0, null, 1, 1));
}
}

0 comments on commit f6123a7

Please sign in to comment.