-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #383 from segmentio/ga-tests
GA tests
- Loading branch information
Showing
4 changed files
with
169 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
iOS Tests/Integrations/GoogleAnalytics/SEGGoogleAnalyticsIntegrationTests.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// | ||
// SEGGoogleAnalyticsIntegrationTests.m | ||
// Analytics | ||
// | ||
// Created by Prateek Srivastava on 2015-07-24. | ||
// Copyright (c) 2015 Segment.io. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import <XCTest/XCTest.h> | ||
#import "SEGGoogleAnalyticsIntegration.h" | ||
|
||
|
||
#define HC_SHORTHAND | ||
#import <OCHamcrest/OCHamcrest.h> | ||
|
||
#define MOCKITO_SHORTHAND | ||
#import <OCMockito/OCMockito.h> | ||
|
||
|
||
@interface SEGGoogleAnalyticsIntegrationTests : XCTestCase | ||
|
||
@property SEGGoogleAnalyticsIntegration *integration; | ||
@property GAI *gaiMock; | ||
@property id<GAITracker> trackerMock; | ||
|
||
@end | ||
|
||
|
||
@implementation SEGGoogleAnalyticsIntegrationTests | ||
|
||
- (void)setUp | ||
{ | ||
[super setUp]; | ||
|
||
_trackerMock = mockProtocol(@protocol(GAITracker)); | ||
_gaiMock = mock([GAI class]); | ||
[given([_gaiMock trackerWithTrackingId:anything()]) willReturn:_trackerMock]; | ||
|
||
_integration = [[SEGGoogleAnalyticsIntegration alloc] init]; | ||
[_integration setGai:_gaiMock]; | ||
[_integration setTracker:_trackerMock]; | ||
} | ||
|
||
- (void)testFlush | ||
{ | ||
[_integration flush]; | ||
|
||
[verifyCount(_gaiMock, times(1)) dispatch]; | ||
} | ||
|
||
- (void)testResetTraits | ||
{ | ||
[_integration setTraits:@{ | ||
@"foo" : @"bar", | ||
@"qaz" : @"qux" | ||
}]; | ||
[_integration resetTraits]; | ||
|
||
[verifyCount(_trackerMock, times(1)) set:@"foo" value:nil]; | ||
[verifyCount(_trackerMock, times(1)) set:@"qaz" value:nil]; | ||
} | ||
|
||
- (void)testReset | ||
{ | ||
[_integration setTraits:@{ | ||
@"foo" : @"bar", | ||
@"qaz" : @"qux" | ||
}]; | ||
[_integration reset]; | ||
|
||
[verifyCount(_trackerMock, times(1)) set:@"&uid" value:nil]; | ||
[verifyCount(_trackerMock, times(1)) set:@"foo" value:nil]; | ||
[verifyCount(_trackerMock, times(1)) set:@"qaz" value:nil]; | ||
} | ||
|
||
- (void)testScreen | ||
{ | ||
[_integration screen:@"foo" properties:nil options:nil]; | ||
|
||
[verifyCount(_trackerMock, times(1)) set:kGAIScreenName value:@"foo"]; | ||
[verifyCount(_trackerMock, times(1)) send:[[GAIDictionaryBuilder createScreenView] build]]; | ||
} | ||
|
||
- (void)testIdentify | ||
{ | ||
[_integration setSettings:@{ @"sendUserId" : @YES }]; | ||
[_integration setTraits:@{ | ||
@"foo" : @"bar", | ||
@"qaz" : @"qux" | ||
}]; | ||
|
||
[_integration identify:@"foo" traits:@{ @"foobar" : @"qazqux" } options:nil]; | ||
|
||
[verifyCount(_trackerMock, times(1)) set:@"foo" value:nil]; | ||
[verifyCount(_trackerMock, times(1)) set:@"qaz" value:nil]; | ||
[verifyCount(_trackerMock, times(1)) set:@"&uid" value:@"foo"]; | ||
[verifyCount(_trackerMock, times(1)) set:@"foobar" value:@"qazqux"]; | ||
} | ||
|
||
- (void)testTrack | ||
{ | ||
[_integration track:@"foo" | ||
properties:@{ @"label" : @"bar", | ||
@"revenue" : @10 } | ||
options:nil]; | ||
|
||
[verifyCount(_trackerMock, times(1)) send: | ||
[[GAIDictionaryBuilder createEventWithCategory:@"All" | ||
action:@"foo" | ||
label:@"bar" | ||
value:@10] build]]; | ||
} | ||
|
||
@end |