To test the activity reporting APIs, historical data is required. To test whether we correctly report on events that happened three weeks ago, we would require a test running for a month. As that's not practical, we need to be able to inject data as if it happened in the past. For app activity reporting, we already have that option, but network activity is reported as it happens now and the same applies to the creation of goals. This page describes an approach, with a sample API and an overview of the implications for the server.
We create an API that allows injecting data as if it happened in the past. WIth that, we can create a test that reports on information that happened last week. Reporting on the current week can only happen if the week is old enough. At 3:00 AM on the first day of the week, it's not possible to run a test that verifies events that happened throughout the day, or to verify what happened on earlier days in that same week. This calls for conditional execution of tests (only on Wednesday or later, or only after 7:00 AM). The conditional execution can be done through the @Requires annotatation of Spock.
Here is a sample test that can run any moment, because everything is projected in past weeks:
The new methods can be created in