Skip to content

Commit

Permalink
Merge pull request #365 from segmentio/appsflyer-tests
Browse files Browse the repository at this point in the history
Add appsflyer tests
  • Loading branch information
f2prateek committed Jul 16, 2015
2 parents 0d18009 + bf1a7cd commit f2e88e8
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 8 deletions.
12 changes: 12 additions & 0 deletions Analytics.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
6EB809541AFC135E00959050 /* Amplitude+SSLPinning.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EB809531AFC135E00959050 /* Amplitude+SSLPinning.h */; settings = {ATTRIBUTES = (Public, ); }; };
6EB809561AFC136D00959050 /* AMPURLConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EB809551AFC136D00959050 /* AMPURLConnection.h */; settings = {ATTRIBUTES = (Public, ); }; };
6ED462261B42D6020042BFE4 /* SEGMixpanelIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6ED462251B42D6020042BFE4 /* SEGMixpanelIntegrationTests.m */; };
6EF665321B5860D400DC7EA1 /* SEGAppsFlyerIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EF665311B5860D400DC7EA1 /* SEGAppsFlyerIntegrationTests.m */; };
6EFAD9AE1B41A97C000664C1 /* SEGTaplyticsIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EFAD9AD1B41A97C000664C1 /* SEGTaplyticsIntegrationTests.m */; };
6EFF0CE51B3B63FB005190A2 /* SEGCountlyIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 6EFF0CE41B3B63FB005190A2 /* SEGCountlyIntegrationTests.m */; };
79D247EA1B4AF3C9002D8F90 /* SEGUXCamIntegration.h in Headers */ = {isa = PBXBuildFile; fileRef = 79D247E81B4AF3C9002D8F90 /* SEGUXCamIntegration.h */; };
Expand Down Expand Up @@ -545,6 +546,7 @@
6EB809531AFC135E00959050 /* Amplitude+SSLPinning.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "Amplitude+SSLPinning.h"; path = "Pods/Amplitude-iOS/Amplitude/Amplitude+SSLPinning.h"; sourceTree = "<group>"; };
6EB809551AFC136D00959050 /* AMPURLConnection.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = AMPURLConnection.h; path = "Pods/Amplitude-iOS/Amplitude/AMPURLConnection.h"; sourceTree = "<group>"; };
6ED462251B42D6020042BFE4 /* SEGMixpanelIntegrationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SEGMixpanelIntegrationTests.m; path = Integrations/Mixpanel/SEGMixpanelIntegrationTests.m; sourceTree = "<group>"; };
6EF665311B5860D400DC7EA1 /* SEGAppsFlyerIntegrationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SEGAppsFlyerIntegrationTests.m; path = AppsFlyer/SEGAppsFlyerIntegrationTests.m; sourceTree = "<group>"; };
6EFAD9AD1B41A97C000664C1 /* SEGTaplyticsIntegrationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SEGTaplyticsIntegrationTests.m; path = Integrations/Taplytics/SEGTaplyticsIntegrationTests.m; sourceTree = "<group>"; };
6EFF0CE41B3B63FB005190A2 /* SEGCountlyIntegrationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SEGCountlyIntegrationTests.m; path = Integrations/Countly/SEGCountlyIntegrationTests.m; sourceTree = "<group>"; };
70B38155D048462482A91850 /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -778,6 +780,7 @@
isa = PBXGroup;
children = (
6EB4681F1B39CDBD00A0E4B9 /* Amplitude */,
6EF6652D1B585DC900DC7EA1 /* AppsFlyer */,
6E5146981B3B571D00F8F87C /* Bugsnag */,
6EFF0CE31B3B63E6005190A2 /* Countly */,
6E12DD811B3CA285005E35D0 /* Crittercism */,
Expand Down Expand Up @@ -857,6 +860,14 @@
name = Mixpanel;
sourceTree = "<group>";
};
6EF6652D1B585DC900DC7EA1 /* AppsFlyer */ = {
isa = PBXGroup;
children = (
6EF665311B5860D400DC7EA1 /* SEGAppsFlyerIntegrationTests.m */,
);
name = AppsFlyer;
sourceTree = "<group>";
};
6EFAD9AC1B41A965000664C1 /* Taplytics */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1813,6 +1824,7 @@
3242C9BE1946AFF200FBE441 /* SEGTaplyticsIntegration.m in Sources */,
3242C9AF1946AD9B00FBE441 /* SEGAnalyticsUtils.m in Sources */,
3242C9AE1946AD9900FBE441 /* SEGAnalyticsRequest.m in Sources */,
6EF665321B5860D400DC7EA1 /* SEGAppsFlyerIntegrationTests.m in Sources */,
6EB468211B39CE0B00A0E4B9 /* SEGAmplitudeIntegrationTests.m in Sources */,
3242C9B81946AFD100FBE441 /* SEGCrittercismIntegration.m in Sources */,
3242C9A31946A3E100FBE441 /* iOS_Tests.m in Sources */,
Expand Down
3 changes: 3 additions & 0 deletions Analytics/Integrations/AppsFlyer/SEGAppsFlyerIntegration.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
//

#import "SEGAnalyticsIntegration.h"
#import <AppsFlyerTracker.h>


@interface SEGAppsFlyerIntegration : SEGAnalyticsIntegration

@property AppsFlyerTracker *appsFlyer;

@end
17 changes: 10 additions & 7 deletions Analytics/Integrations/AppsFlyer/SEGAppsFlyerIntegration.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#import "SEGAppsFlyerIntegration.h"
#import "SEGAnalytics.h"
#import "SEGAnalyticsUtils.h"
#import <AppsFlyerTracker.h>


@implementation SEGAppsFlyerIntegration
Expand All @@ -25,6 +24,7 @@ - (instancetype)init
self.name = [self.class identifier];
self.valid = NO;
self.initialized = NO;
self.appsFlyer = [AppsFlyerTracker sharedTracker];
}
return self;
}
Expand All @@ -36,8 +36,8 @@ - (void)validate

- (void)start
{
[[AppsFlyerTracker sharedTracker] setAppleAppID:[self appId]];
[[AppsFlyerTracker sharedTracker] setAppsFlyerDevKey:[self devKey]];
[self.appsFlyer setAppleAppID:[self appId]];
[self.appsFlyer setAppsFlyerDevKey:[self devKey]];

SEGLog(@"AppsFlyer: setup with appleAppId: %@, appsFlyerDevKey: %@", [self appId], [self devKey]);
[super start];
Expand All @@ -46,7 +46,7 @@ - (void)start
- (void)identify:(NSString *)userId traits:(NSDictionary *)traits options:(NSDictionary *)options
{
if (userId) {
[[AppsFlyerTracker sharedTracker] setCustomerUserID:userId];
[self.appsFlyer setCustomerUserID:userId];

SEGLog(@"AppsFlyer: set customer id: %@", userId);
}
Expand All @@ -56,14 +56,17 @@ - (void)track:(NSString *)event properties:(NSDictionary *)properties options:(N
{
NSNumber *revenue = [self.class extractRevenue:properties];
NSString *currency = properties[@"currency"];
if (currency) [[AppsFlyerTracker sharedTracker] setCurrencyCode:currency];
[[AppsFlyerTracker sharedTracker] trackEvent:event withValue:[revenue stringValue]];
if (currency) {
[self.appsFlyer setCurrencyCode:currency];
}
[self.appsFlyer trackEvent:event
withValue:[revenue stringValue]];
SEGLog(@"AppsFlyer: trackingEvent: %@, withValue: %@", event, revenue);
}

- (void)applicationDidBecomeActive
{
[[AppsFlyerTracker sharedTracker] trackAppLaunch];
[self.appsFlyer trackAppLaunch];
SEGLog(@"AppsFlyer: tracked app launch");
}

Expand Down
84 changes: 84 additions & 0 deletions iOS Tests/AppsFlyer/SEGAppsFlyerIntegrationTests.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
//
// SEGAppsFlyerIntegrationTests.m
// Analytics
//
// Created by Prateek Srivastava on 2015-07-16.
// Copyright (c) 2015 Segment.io. All rights reserved.
//

#import <XCTest/XCTest.h>
#import "SEGAppsFlyerIntegration.h"

#define HC_SHORTHAND
#import <OCHamcrest/OCHamcrest.h>

#define MOCKITO_SHORTHAND
#import <OCMockito/OCMockito.h>


@interface SEGAppsFlyerIntegrationTests : XCTestCase

@property SEGAppsFlyerIntegration *integration;
@property AppsFlyerTracker *appsFlyerMock;

@end


@implementation SEGAppsFlyerIntegrationTests

- (void)setUp
{
[super setUp];

_appsFlyerMock = mock([AppsFlyerTracker class]);
_integration = [[SEGAppsFlyerIntegration alloc] init];

[_integration setAppsFlyer:_appsFlyerMock];
[_integration updateSettings:@{
@"appsFlyerDevKey" : @"foo",
@"appleAppID" : @"bar"
}];
}

- (void)testIdentify
{
[_integration identify:@"foo" traits:nil options:nil];

[verifyCount(_appsFlyerMock, times(1)) setCustomerUserID:@"foo"];
}

- (void)testIdentifyWithoutUserId
{
[_integration identify:nil traits:nil options:nil];

[verifyCount(_appsFlyerMock, never()) setCustomerUserID:anything()];
}

- (void)testTrack
{
[_integration track:@"foo" properties:nil options:nil];

[verifyCount(_appsFlyerMock, times(1)) trackEvent:@"foo" withValue:anything()];
[verifyCount(_appsFlyerMock, never()) setCurrencyCode:anything()];
}

- (void)testTrackWithProperties
{
[_integration track:@"foo"
properties:@{
@"revenue" : @3.142,
@"currency" : @"bar"
}
options:nil];

[verifyCount(_appsFlyerMock, times(1)) trackEvent:@"foo" withValue:@"3.142"];
[verifyCount(_appsFlyerMock, times(1)) setCurrencyCode:@"bar"];
}

- (void)testStart
{
[verifyCount(_appsFlyerMock, times(1)) setAppleAppID:@"bar"];
[verifyCount(_appsFlyerMock, times(1)) setAppsFlyerDevKey:@"foo"];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
@interface SEGAmplitudeIntegrationTests : XCTestCase

@property SEGAmplitudeIntegration *integration;

@property Amplitude *amplitudeMock;

@end
Expand Down

0 comments on commit f2e88e8

Please sign in to comment.