Permalink
Browse files

Add integration tests for weekly entry success.

  • Loading branch information...
1 parent cf182ef commit 5524bfbd3c213ef9bf898823cacd03b69a273c8e @robyoung robyoung committed Jan 2, 2013
@@ -0,0 +1 @@
+{"kind":"analytics#gaData","id":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:53872948&dimensions=ga:week,ga:eventCategory,ga:eventLabel&metrics=ga:totalEvents&filters=ga:eventCategory%3D~%5EMS_.*&start-date=2012-12-09&end-date=2012-12-15","query":{"start-date":"2012-12-09","end-date":"2012-12-15","ids":"ga:53872948","dimensions":"ga:week,ga:eventCategory,ga:eventLabel","metrics":["ga:totalEvents"],"filters":"ga:eventCategory=~^MS_.*","start-index":1,"max-results":1000},"itemsPerPage":1000,"totalResults":10,"selfLink":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:53872948&dimensions=ga:week,ga:eventCategory,ga:eventLabel&metrics=ga:totalEvents&filters=ga:eventCategory%3D~%5EMS_.*&start-date=2012-12-09&end-date=2012-12-15","profileInfo":{"profileId":"53872948","accountId":"26179049","webPropertyId":"UA-26179049-1","internalWebPropertyId":"50705554","profileName":"1. GOV.UK (Entire site - Filtered)","tableId":"ga:53872948"},"containsSampledData":false,"columnHeaders":[{"name":"ga:week","columnType":"DIMENSION","dataType":"STRING"},{"name":"ga:eventCategory","columnType":"DIMENSION","dataType":"STRING"},{"name":"ga:eventLabel","columnType":"DIMENSION","dataType":"STRING"},{"name":"ga:totalEvents","columnType":"METRIC","dataType":"INTEGER"}],"totalsForAllResults":{"ga:totalEvents":"11561760"},"rows":[["50","MS_answer","Entry","1458580"],["50","MS_answer","Success","1115508"],["50","MS_guide","Entry","1253538"],["50","MS_guide","Success","1018108"],["50","MS_programme","Entry","1141023"],["50","MS_programme","Success","878427"],["50","MS_smart_answer","Entry","273560"],["50","MS_smart_answer","Success","157970"],["50","MS_transaction","Entry","4136629"],["50","MS_transaction","Success","128417"]]}
@@ -0,0 +1 @@
+{"kind":"analytics#gaData","id":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:53872948&dimensions=ga:week,ga:eventCategory,ga:eventLabel&metrics=ga:totalEvents&filters=ga:eventCategory%3D~%5EMS_.*&start-date=2012-12-16&end-date=2012-12-22","query":{"start-date":"2012-12-16","end-date":"2012-12-22","ids":"ga:53872948","dimensions":"ga:week,ga:eventCategory,ga:eventLabel","metrics":["ga:totalEvents"],"filters":"ga:eventCategory=~^MS_.*","start-index":1,"max-results":1000},"itemsPerPage":1000,"totalResults":10,"selfLink":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:53872948&dimensions=ga:week,ga:eventCategory,ga:eventLabel&metrics=ga:totalEvents&filters=ga:eventCategory%3D~%5EMS_.*&start-date=2012-12-16&end-date=2012-12-22","profileInfo":{"profileId":"53872948","accountId":"26179049","webPropertyId":"UA-26179049-1","internalWebPropertyId":"50705554","profileName":"1. GOV.UK (Entire site - Filtered)","tableId":"ga:53872948"},"containsSampledData":false,"columnHeaders":[{"name":"ga:week","columnType":"DIMENSION","dataType":"STRING"},{"name":"ga:eventCategory","columnType":"DIMENSION","dataType":"STRING"},{"name":"ga:eventLabel","columnType":"DIMENSION","dataType":"STRING"},{"name":"ga:totalEvents","columnType":"METRIC","dataType":"INTEGER"}],"totalsForAllResults":{"ga:totalEvents":"10359793"},"rows":[["51","MS_answer","Entry","1410402"],["51","MS_answer","Success","1098895"],["51","MS_guide","Entry","1138807"],["51","MS_guide","Success","926399"],["51","MS_programme","Entry","975321"],["51","MS_programme","Success","771863"],["51","MS_smart_answer","Entry","265687"],["51","MS_smart_answer","Success","154180"],["51","MS_transaction","Entry","3503632"],["51","MS_transaction","Success","114607"]]}
@@ -0,0 +1 @@
+{"kind":"analytics#gaData","id":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:53872948&dimensions=ga:week,ga:eventCategory,ga:eventLabel&metrics=ga:totalEvents&filters=ga:eventCategory%3D~%5EMS_.*&start-date=2012-12-23&end-date=2012-12-29","query":{"start-date":"2012-12-23","end-date":"2012-12-29","ids":"ga:53872948","dimensions":"ga:week,ga:eventCategory,ga:eventLabel","metrics":["ga:totalEvents"],"filters":"ga:eventCategory=~^MS_.*","start-index":1,"max-results":1000},"itemsPerPage":1000,"totalResults":10,"selfLink":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:53872948&dimensions=ga:week,ga:eventCategory,ga:eventLabel&metrics=ga:totalEvents&filters=ga:eventCategory%3D~%5EMS_.*&start-date=2012-12-23&end-date=2012-12-29","profileInfo":{"profileId":"53872948","accountId":"26179049","webPropertyId":"UA-26179049-1","internalWebPropertyId":"50705554","profileName":"1. GOV.UK (Entire site - Filtered)","tableId":"ga:53872948"},"containsSampledData":false,"columnHeaders":[{"name":"ga:week","columnType":"DIMENSION","dataType":"STRING"},{"name":"ga:eventCategory","columnType":"DIMENSION","dataType":"STRING"},{"name":"ga:eventLabel","columnType":"DIMENSION","dataType":"STRING"},{"name":"ga:totalEvents","columnType":"METRIC","dataType":"INTEGER"}],"totalsForAllResults":{"ga:totalEvents":"6477549"},"rows":[["52","MS_answer","Entry","956935"],["52","MS_answer","Success","749668"],["52","MS_guide","Entry","744263"],["52","MS_guide","Success","604024"],["52","MS_programme","Entry","530724"],["52","MS_programme","Success","422019"],["52","MS_smart_answer","Entry","151671"],["52","MS_smart_answer","Success","87434"],["52","MS_transaction","Entry","2142435"],["52","MS_transaction","Success","88376"]]}
@@ -0,0 +1,158 @@
+require_relative "spec_helper"
+
+describe "Weekly entry success collector" do
+ before(:each) do
+ stub_credentials
+ register_oauth_refresh
+ register_api_discovery
+ end
+
+ it "should query google analytics for specific dates" do
+ register_ga_request(
+ {
+ :ids => "ga:53872948",
+ :"start-date" => "2012-12-23",
+ :"end-date" => "2012-12-29",
+ :metrics => "ga:totalEvents",
+ :dimensions => "ga:week,ga:eventCategory,ga:eventLabel",
+ :filters => "ga:eventCategory=~^MS_.*"
+ },
+ load_data("weekly-entry-success-from-2012-12-23.json")
+ )
+
+ collector = GoogleAnalytics::Collector.new(nil, [GoogleAnalytics::Config::WeeklyEntrySuccess.new(Date.new(2012, 12, 23), Date.new(2012, 12, 29))])
+
+ response = collector.collect_as_json
+ response.should have(5).item
+
+ response[0].should be_for_collector("Google Analytics")
+ response[0].should be_for_time_period(
+ DateTime.new(2012, 12, 23), DateTime.new(2012, 12, 30)
+ )
+ response[0].should have_payload_value(
+ "site" => "govuk",
+ "format" => "answer",
+ "entries" => 956935,
+ "successes" => 749668
+ )
+
+ response[1].should have_payload_value(
+ "format" => "guide",
+ "entries" => 744263,
+ "successes" => 604024
+ )
+
+ response[2].should have_payload_value(
+ "format" => "programme",
+ "entries" => 530724,
+ "successes" => 422019
+ )
+ end
+
+ it "should query google analytics for last week today" do
+ register_ga_request(
+ {
+ :ids => "ga:53872948",
+ :"start-date" => "2012-12-23",
+ :"end-date" => "2012-12-29",
+ :metrics => "ga:totalEvents",
+ :dimensions => "ga:week,ga:eventCategory,ga:eventLabel",
+ :filters => "ga:eventCategory=~^MS_.*"
+ },
+ load_data("weekly-entry-success-from-2012-12-23.json")
+ )
+
+ Timecop.travel(DateTime.parse("2012-12-31")) do
+ collector = GoogleAnalytics::Collector.new(nil, GoogleAnalytics::Config::WeeklyEntrySuccess.all_within(Date.today - 1, Date.today))
+
+ response = collector.collect_as_json
+ response.should have(5).item
+
+ response[0].should be_for_time_period(
+ DateTime.new(2012, 12, 23), DateTime.new(2012, 12, 30)
+ )
+ response[0].should have_payload_value(
+ "site" => "govuk",
+ "format" => "answer",
+ "entries" => 956935,
+ "successes" => 749668
+ )
+ end
+ end
+
+ it "should query google analytics for the previous three weeks" do
+ register_ga_request(
+ {
+ :ids => "ga:53872948",
+ :"start-date" => "2012-12-09",
+ :"end-date" => "2012-12-15",
+ :metrics => "ga:totalEvents",
+ :dimensions => "ga:week,ga:eventCategory,ga:eventLabel",
+ :filters => "ga:eventCategory=~^MS_.*"
+ },
+ load_data("weekly-entry-success-from-2012-12-09.json")
+ )
+ register_ga_request(
+ {
+ :ids => "ga:53872948",
+ :"start-date" => "2012-12-16",
+ :"end-date" => "2012-12-22",
+ :metrics => "ga:totalEvents",
+ :dimensions => "ga:week,ga:eventCategory,ga:eventLabel",
+ :filters => "ga:eventCategory=~^MS_.*"
+ },
+ load_data("weekly-entry-success-from-2012-12-16.json")
+ )
+ register_ga_request(
+ {
+ :ids => "ga:53872948",
+ :"start-date" => "2012-12-23",
+ :"end-date" => "2012-12-29",
+ :metrics => "ga:totalEvents",
+ :dimensions => "ga:week,ga:eventCategory,ga:eventLabel",
+ :filters => "ga:eventCategory=~^MS_.*"
+ },
+ load_data("weekly-entry-success-from-2012-12-23.json")
+ )
+ Timecop.travel(DateTime.parse("2012-12-31")) do
+ configs = GoogleAnalytics::Config::WeeklyEntrySuccess.all_within(
+ Date.new(2012, 12, 10),
+ Date.today
+ )
+ collector = GoogleAnalytics::Collector.new(nil, configs)
+
+ response = collector.collect_as_json
+ response.should have(15).items
+
+ response[0].should be_for_time_period(
+ Date.new(2012, 12, 9), Date.new(2012, 12, 16)
+ )
+ response[0].should have_payload_value(
+ "site" => "govuk",
+ "format" => "answer",
+ "entries" => 1458580,
+ "successes" => 1115508
+ )
+
+ response[1].should have_payload_value(
+ "format" => "guide",
+ "entries" => 1253538,
+ "successes" => 1018108
+ )
+
+ response[4].should be_for_time_period(
+ Date.new(2012, 12, 9), Date.new(2012, 12, 16)
+ )
+ response[5].should be_for_time_period(
+ Date.new(2012, 12, 16), Date.new(2012, 12, 23)
+ )
+ response[9].should be_for_time_period(
+ Date.new(2012, 12, 16), Date.new(2012, 12, 23)
+ )
+ response[10].should be_for_time_period(
+ Date.new(2012, 12, 23), Date.new(2012, 12, 30)
+ )
+ end
+ end
+
+end

0 comments on commit 5524bfb

Please sign in to comment.