Skip to end of metadata
Go to start of metadata

Introduction

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.

Approach

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.

Sample API

Here is a sample test that can run any moment, because everything is projected in past weeks:

	def 'New style test'()
	{
		given:
		def richardAndBob = addRichardAndBobAsBuddies()
		def richard = richardAndBob.richard
		def bob = richardAndBob.bob
		setGoalCreationTime(richard, NEWS_ACT_CAT_URL, "W-2 Mon 02:18")
		reportAppActivity(richard, "NU.nl", "W-2 Mon 01:18", "W-2 Mon 02:28")
		reportAppActivities(richard, [createAppActivity("NU.nl", "W-2 Mon 08:45", "W-2 Mon 09:05"), createAppActivity("Facebook", "W-2 Mon 09:05", "W-2 Mon 09:28")])
		addTimeZoneGoal(richard, SOCIAL_ACT_CAT_URL, ["11:00-12:00"], "W-1 Wed 13:54")
		reportNetworkActivity(richard, ["social"], "http://www.facebook.com", "W-1 Wed 11:02")
		
		when:
		def response = appService.getWeekActivityOverviews(richard)
		
		then:
		response.status == 200
		response.responseData?._embedded?."yona:weekActivityOverviews"?.size() == 3
	}

The new methods can be created in AbstractAppServiceIntegrationTest.

 

  • No labels