Skip to content

Commit

Permalink
travis e2e tests: organic install, inapp, deeplink
Browse files Browse the repository at this point in the history
travis e2e tests: organic install, inapp, deeplink
  • Loading branch information
amit-kremer93 authored May 2, 2021
2 parents 75462d4 + 5b8ced1 commit f5c87de
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ matrix:
before_script:
- export WORK_BRANCH=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then echo $TRAVIS_BRANCH; else echo $TRAVIS_PULL_REQUEST_BRANCH; fi)
- PLUGIN_INSTALL_CMD='npm install git://github.com/AppsFlyerSDK/appsflyer-react-native-plugin.git#${WORK_BRANCH} --save'
- CONFIG_PLUGIN_INSTALL='npm install react-native-config --save --force'
before_install:
- gem install cocoapods
- gem update concurrent-ruby
Expand All @@ -17,8 +18,10 @@ matrix:
- npm install -g detox-cli
script:
- cd SampleApps/DetoxApp
- echo ‘DEV_KEY=$DEV_KEY’ >> .env
- npm install --force
- eval $PLUGIN_INSTALL_CMD
- eval $CONFIG_PLUGIN_INSTALL
- detox build --configuration ios
- detox test --configuration ios --cleanup

82 changes: 62 additions & 20 deletions SampleApps/DetoxApp/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* https://github.com/facebook/react-native
*/

import React, {useState} from 'react';
import React, {useEffect, useState} from 'react';
import type {Node} from 'react';
import appsFlyer from 'react-native-appsflyer';
import {
Expand All @@ -15,61 +15,93 @@ import {
Button,
View,
Platform,
Alert,
} from 'react-native';

import {
Colors,
} from 'react-native/Libraries/NewAppScreen';
import Config from 'react-native-config';

const App: () => Node = () => {
const [initResult, setInitResult] = useState('Not clicked yet');
const [noDevKeyResult, setNoDevKeyResult] = useState('Not clicked yet');
const successInit = () => {
const [testResult, setTestResult] = useState('No test results');

useEffect(() => {
let gcdListener = appsFlyer.onInstallConversionData(res => {
console.log(JSON.stringify(res));
setTestResult(JSON.stringify(res));
});
let oaoaListener = appsFlyer.onAppOpenAttribution(res => {
console.log(JSON.stringify(res));
Alert.alert('Alert', JSON.stringify(res));
});
return (() => {
gcdListener();
oaoaListener();
});
}, []);

const successOrganicGCD = () => {
appsFlyer.initSdk({
devKey: 'Us********ed',
appId: '123456789',
onInstallConversionDataListener: false,
devKey: Config.DEV_KEY,
appId: '741993991',
onInstallConversionDataListener: true,
}, result => {
setInitResult(result);
}, error => {
});
};
const noDevKeyInit = () => {
appsFlyer.initSdk({devKey: '', appId: '123456789', onInstallConversionDataListener: false}, result => {
}, error => {
if (Platform.OS == 'ios') {
setNoDevKeyResult(error['domain']);
setTestResult(error['domain']);
} else {
setNoDevKeyResult(error);
setTestResult(error);
}

});
};

const logEventSuccess = () => {
const eventName = 'test';
const eventValues = {af_revenue: '10'};
appsFlyer.logEvent(eventName, eventValues, result => {
console.log(JSON.stringify(result));
Alert.alert('Alert', result);
}, error => console.log(error));
};

return (
<SafeAreaView>
<StatusBar/>
<ScrollView
contentInsetAdjustmentBehavior="automatic">
<View style={styles.responseView}>
<Text testID='testResult' style={styles.welcome}>{testResult}</Text>
</View>
<ScrollView contentInsetAdjustmentBehavior="automatic">
<View style={styles.body}>
<Button
testID='successInitButton'
onPress={successInit}
testID='noDevKeyButton'
onPress={noDevKeyInit}
title="No devKey initSDK"
color="#009688"
/>
<Button
testID='successOrganicGCDButton'
onPress={successOrganicGCD}
title="Success initSDK"
color="#009688"
/>
<Text testID='successInitResult' style={styles.welcome}>{initResult}</Text>
<Button
testID='noDevKeyButton'
onPress={noDevKeyInit}
title="No devKey initSDK"
testID='logEventSuccessButton'
onPress={logEventSuccess}
title="Success logEvent"
color="#009688"
/>
<Text testID='noDevKeyInitResult' style={styles.welcome}>{noDevKeyResult}</Text>
</View>
</ScrollView>
</SafeAreaView>
);
)
;
};

const styles = StyleSheet.create({
Expand Down Expand Up @@ -97,6 +129,16 @@ const styles = StyleSheet.create({
textAlign: 'center',
margin: 10,
},
responseView: {
height: '40%',
padding: 20,
borderRadius: 50,
overflow: 'hidden',
borderWidth: 1,
borderColor: 'black',
margin: 20,

},
});

export default App;
44 changes: 36 additions & 8 deletions SampleApps/DetoxApp/e2e/firstTest.e2e.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,53 @@
describe('React-Native AppsFlyer Plugin', () => {
jestExpect = require('expect');
const deepLinkData = '{"status":"success","type":"onAppOpenAttribution","data":{"c":"firstCampign","campaign":"firstCampign","af_dp":"rnoaoaautomation://","link":"https://rnautomated.onelink.me/lraA/mySMScampign","deep_link_value":"OAOA","media_source":"SMS","af_sub1":"lala","pid":"SMS"}}';
describe('Organic install', () => {
beforeAll(async () => {
await device.launchApp();
});

beforeEach(async () => {
// await device.reloadReactNative();
// await device.launchApp();
});

afterAll(async () => {
afterEach(async () => {
// await device.terminateApp();
});

it('initSdk should return Success', async () => {
await expect(element(by.id('successInitButton'))).toBeVisible();
await element(by.id('successInitButton')).tap();
await expect(element(by.id('successInitResult'))).toHaveText('Success');
afterAll(async () => {
await device.terminateApp();
await device.uninstallApp();
});

it('initSdk should return \'No \'devKey\' found or its empty\'', async () => {
await expect(element(by.id('noDevKeyButton'))).toBeVisible();
await element(by.id('noDevKeyButton')).tap();
await expect(element(by.id('noDevKeyInitResult'))).toHaveText('No \'devKey\' found or its empty');
await expect(element(by.id('testResult'))).toHaveText('No \'devKey\' found or its empty');
});

it('initSdk should return Success organic GCD', async () => {
await expect(element(by.id('successOrganicGCDButton'))).toBeVisible();
await element(by.id('successOrganicGCDButton')).tap();
const gcdAttr = await element(by.id('testResult')).getAttributes();
jestExpect(gcdAttr.text).toContain('\"status\":\"success\"');
jestExpect(gcdAttr.text).toContain('\"type\":\"onInstallConversionDataLoaded\"');
jestExpect(gcdAttr.text).toContain('\"data\"');
jestExpect(gcdAttr.text).toContain('\"is_first_launch\":true');
jestExpect(gcdAttr.text).toContain('\"af_status\":\"Organic\"');
});

it('logEvent should return Success', async () => {
await expect(element(by.id('logEventSuccessButton'))).toBeVisible();
await element(by.id('logEventSuccessButton')).tap();
await waitFor(element(by.text('Alert'))).toBeVisible().withTimeout(3000);
await expect(element(by.text('Success'))).toHaveText('Success');
await element(by.text('OK')).tap();
});

it('App goes to background and opens via deep link', async () => {
await device.sendToHome();
await device.launchApp({newInstance: false, url: 'https://rnautomated.onelink.me/lraA/mySMScampign'});
await waitFor(element(by.text('Alert'))).toBeVisible().withTimeout(3000);
await waitFor(element(by.text(`${deepLinkData}`))).toBeVisible().withTimeout(3000);
await expect(element(by.text(`${deepLinkData}`))).toHaveText(deepLinkData);
});
});
8 changes: 6 additions & 2 deletions SampleApps/DetoxApp/ios/detoxTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
97C7E46E98792B8C167A2875 /* Pods-detoxTest.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-detoxTest.debug.xcconfig"; path = "Target Support Files/Pods-detoxTest/Pods-detoxTest.debug.xcconfig"; sourceTree = "<group>"; };
DB15EBE857E98A6AAA7022F7 /* Pods-detoxTest-detoxTestTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-detoxTest-detoxTestTests.debug.xcconfig"; path = "Target Support Files/Pods-detoxTest-detoxTestTests/Pods-detoxTest-detoxTestTests.debug.xcconfig"; sourceTree = "<group>"; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
EDF9007F263AD6940078D932 /* detoxTest.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; name = detoxTest.entitlements; path = detoxTest/detoxTest.entitlements; sourceTree = "<group>"; };
F360F9D27C7A1BD5F23751CA /* Pods-detoxTest-detoxTestTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-detoxTest-detoxTestTests.release.xcconfig"; path = "Target Support Files/Pods-detoxTest-detoxTestTests/Pods-detoxTest-detoxTestTests.release.xcconfig"; sourceTree = "<group>"; };
F39F3D212856AFA023B56A83 /* libPods-detoxTest.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-detoxTest.a"; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -86,6 +87,7 @@
13B07FAE1A68108700A75B9A /* detoxTest */ = {
isa = PBXGroup;
children = (
EDF9007F263AD6940078D932 /* detoxTest.entitlements */,
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
13B07FB01A68108700A75B9A /* AppDelegate.m */,
13B07FB51A68108700A75B9A /* Images.xcassets */,
Expand Down Expand Up @@ -449,6 +451,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = detoxTest/detoxTest.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
Expand All @@ -466,7 +469,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = com.appsflyer.detoxTest;
PRODUCT_BUNDLE_IDENTIFIER = com.appsflyer.reactconversions;
PRODUCT_NAME = detoxTest;
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
Expand All @@ -481,6 +484,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = detoxTest/detoxTest.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
Expand All @@ -496,7 +500,7 @@
"-ObjC",
"-lc++",
);
PRODUCT_BUNDLE_IDENTIFIER = com.appsflyer.detoxTest;
PRODUCT_BUNDLE_IDENTIFIER = com.appsflyer.reactconversions;
PRODUCT_NAME = detoxTest;
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 5.0;
Expand Down
15 changes: 15 additions & 0 deletions SampleApps/DetoxApp/ios/detoxTest/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <RNAppsFlyer.h>

#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
Expand Down Expand Up @@ -49,6 +50,20 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[self.window makeKeyAndVisible];
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString*)sourceApplication annotation:(id)annotation {
[[AppsFlyerAttribution shared] handleOpenUrl:url sourceApplication:sourceApplication annotation:annotation];
return YES;
}

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
options:(NSDictionary *) options {
[[AppsFlyerAttribution shared] handleOpenUrl:url options:options];
return YES;
}
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
[[AppsFlyerAttribution shared] continueUserActivity:userActivity restorationHandler:nil];
return YES;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
Expand Down
11 changes: 11 additions & 0 deletions SampleApps/DetoxApp/ios/detoxTest/detoxTest.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.associated-domains</key>
<array>
<string>applinks:rnautomated.onelink.me</string>
<string>applinks:rntestamit.onelink.me</string>
</array>
</dict>
</plist>

0 comments on commit f5c87de

Please sign in to comment.