Skip to content

Commit

Permalink
test: update testing flow
Browse files Browse the repository at this point in the history
  • Loading branch information
uerceg committed Mar 28, 2024
1 parent 8788e1d commit c39c113
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 55 deletions.
26 changes: 11 additions & 15 deletions ios/Classes/AdjustSdk.m
Original file line number Diff line number Diff line change
Expand Up @@ -829,10 +829,7 @@ - (void)processDeeplink:(FlutterMethodCall *)call withResult:(FlutterResult)resu

- (void)setTestOptions:(FlutterMethodCall *)call withResult:(FlutterResult)result {
AdjustTestOptions *testOptions = [[AdjustTestOptions alloc] init];
NSString *baseUrl = call.arguments[@"baseUrl"];
NSString *gdprUrl = call.arguments[@"gdprUrl"];
NSString *subscriptionUrl = call.arguments[@"subscriptionUrl"];
NSString *purchaseVerificationUrl = call.arguments[@"purchaseVerificationUrl"];
NSString *overwriteUrl = call.arguments[@"urlOverwrite"];
NSString *extraPath = call.arguments[@"extraPath"];
NSString *timerIntervalInMilliseconds = call.arguments[@"timerIntervalInMilliseconds"];
NSString *timerStartInMilliseconds = call.arguments[@"timerStartInMilliseconds"];
Expand All @@ -842,18 +839,11 @@ - (void)setTestOptions:(FlutterMethodCall *)call withResult:(FlutterResult)resul
NSString *deleteState = call.arguments[@"deleteState"];
NSString *noBackoffWait = call.arguments[@"noBackoffWait"];
NSString *adServicesFrameworkEnabled = call.arguments[@"adServicesFrameworkEnabled"];
NSString *attStatus = call.arguments[@"attStatus"];
NSString *idfa = call.arguments[@"idfa"];

if ([self isFieldValid:baseUrl]) {
testOptions.baseUrl = baseUrl;
}
if ([self isFieldValid:gdprUrl]) {
testOptions.gdprUrl = gdprUrl;
}
if ([self isFieldValid:subscriptionUrl]) {
testOptions.subscriptionUrl = subscriptionUrl;
}
if ([self isFieldValid:purchaseVerificationUrl]) {
testOptions.purchaseVerificationUrl = purchaseVerificationUrl;
if ([self isFieldValid:overwriteUrl]) {
testOptions.urlOverwrite = overwriteUrl;
}
if ([self isFieldValid:extraPath]) {
testOptions.extraPath = extraPath;
Expand Down Expand Up @@ -885,6 +875,12 @@ - (void)setTestOptions:(FlutterMethodCall *)call withResult:(FlutterResult)resul
if ([self isFieldValid:adServicesFrameworkEnabled]) {
testOptions.adServicesFrameworkEnabled = [adServicesFrameworkEnabled boolValue];
}
if ([self isFieldValid:attStatus]) {
testOptions.attStatusInt = [NSNumber numberWithInt:[attStatus intValue]];
}
if ([self isFieldValid:idfa]) {
testOptions.idfa = idfa;
}

[Adjust setTestOptions:testOptions];
}
Expand Down
2 changes: 1 addition & 1 deletion test/app/lib/command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Adjust SDK
//
// Created by Srdjan Tubin (@2beens) on 25th April 2018.
// Copyright (c) 2018-2021 Adjust GmbH. All rights reserved.
// Copyright (c) 2018-Present Adjust GmbH. All rights reserved.
//

import 'dart:convert';
Expand Down
60 changes: 36 additions & 24 deletions test/app/lib/command_executor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Adjust SDK
//
// Created by Srdjan Tubin (@2beens) on 25th April 2018.
// Copyright (c) 2018-2021 Adjust GmbH. All rights reserved.
// Copyright (c) 2018-Present Adjust GmbH. All rights reserved.
//

import 'dart:io' show Platform;
Expand Down Expand Up @@ -35,20 +35,18 @@ class CommandExecutor {
String? _subscriptionPath;
String? _purchaseVerificationUrl;
String? _purchaseVerificationPath;
String? _overwriteUrl;
String? _extraPath;
late Command _command;
Map<int, AdjustEvent?> _savedEvents = new Map<int, AdjustEvent?>();
Map<int, AdjustConfig?> _savedConfigs = new Map<int, AdjustConfig?>();

CommandExecutor(
String? baseUrl,
String? gdprUrl,
String? subscriptionUrl,
String? purchaseVerificationUrl) {
_baseUrl = baseUrl;
_gdprUrl = gdprUrl;
_subscriptionUrl = subscriptionUrl;
_purchaseVerificationUrl = purchaseVerificationUrl;
CommandExecutor(String? overwriteUrl) {
_baseUrl = overwriteUrl;
_gdprUrl = overwriteUrl;
_subscriptionUrl = overwriteUrl;
_purchaseVerificationUrl = overwriteUrl;
_overwriteUrl = overwriteUrl;
}

void executeCommand(Command command) {
Expand Down Expand Up @@ -149,10 +147,11 @@ class CommandExecutor {

void _testOptions() {
final dynamic testOptions = {};
testOptions['baseUrl'] = _baseUrl;
testOptions['gdprUrl'] = _gdprUrl;
testOptions['subscriptionUrl'] = _subscriptionUrl;
testOptions['purchaseVerificationUrl'] = _purchaseVerificationUrl;
testOptions['baseUrl'] = _overwriteUrl;
testOptions['gdprUrl'] = _overwriteUrl;
testOptions['subscriptionUrl'] = _overwriteUrl;
testOptions['purchaseVerificationUrl'] = _overwriteUrl;
testOptions['urlOverwrite'] = _overwriteUrl;
if (_command.containsParameter('basePath')) {
_basePath = _command.getFirstParameterValue('basePath');
_gdprPath = _command.getFirstParameterValue('basePath');
Expand Down Expand Up @@ -188,16 +187,24 @@ class CommandExecutor {
testOptions['adServicesFrameworkEnabled'] =
_command.getFirstParameterValue('adServicesFrameworkEnabled');
}
if (_command.containsParameter('attStatus')) {
testOptions['attStatus'] =
_command.getFirstParameterValue('attStatus');
}
if (_command.containsParameter('idfa')) {
testOptions['idfa'] =
_command.getFirstParameterValue('idfa');
}
bool useTestConnectionOptions = false;
if (_command.containsParameter('teardown')) {
List<dynamic> teardownOptions = _command.getParamteters('teardown')!;
for (String teardownOption in teardownOptions) {
if (teardownOption == 'resetSdk') {
testOptions['teardown'] = 'true';
testOptions['basePath'] = _basePath;
testOptions['gdprPath'] = _gdprPath;
testOptions['subscriptionPath'] = _subscriptionPath;
testOptions['purchaseVerificationPath'] = _purchaseVerificationPath;
testOptions['basePath'] = _extraPath;
testOptions['gdprPath'] = _extraPath;
testOptions['subscriptionPath'] = _extraPath;
testOptions['purchaseVerificationPath'] = _extraPath;
testOptions['extraPath'] = _extraPath;
// Android specific
testOptions['useTestConnectionOptions'] = 'true';
Expand Down Expand Up @@ -376,6 +383,11 @@ class CommandExecutor {
adjustConfig!.userAgent = _command.getFirstParameterValue('userAgent');
}

if (_command.containsParameter('attConsentWaitingSeconds')) {
adjustConfig!.attConsentWaitingInterval =
double.parse(_command.getFirstParameterValue('attConsentWaitingSeconds')!);
}

// First clear all previous callback handlers.
adjustConfig!.attributionCallback = null;
adjustConfig.sessionSuccessCallback = null;
Expand All @@ -387,7 +399,7 @@ class CommandExecutor {
// TODO: Deeplinking in Flutter example.
// https://github.com/flutter/flutter/issues/8711#issuecomment-304681212
if (_command.containsParameter('deferredDeeplinkCallback')) {
String? localBasePath = _basePath;
String? localBasePath = _extraPath;
adjustConfig.launchDeferredDeeplink =
_command.getFirstParameterValue('deferredDeeplinkCallback') == 'true';
print(
Expand All @@ -400,7 +412,7 @@ class CommandExecutor {
}

if (_command.containsParameter('attributionCallbackSendAll')) {
String? localBasePath = _basePath;
String? localBasePath = _extraPath;
adjustConfig.attributionCallback = (AdjustAttribution attribution) {
print('[CommandExecutor]: Attribution Callback: $attribution');
TestLib.addInfoToSend('trackerToken', attribution.trackerToken);
Expand All @@ -420,7 +432,7 @@ class CommandExecutor {
}

if (_command.containsParameter('sessionCallbackSendSuccess')) {
String? localBasePath = _basePath;
String? localBasePath = _extraPath;
adjustConfig.sessionSuccessCallback =
(AdjustSessionSuccess sessionSuccessResponseData) {
print(
Expand All @@ -438,7 +450,7 @@ class CommandExecutor {
}

if (_command.containsParameter('sessionCallbackSendFailure')) {
String? localBasePath = _basePath;
String? localBasePath = _extraPath;
adjustConfig.sessionFailureCallback =
(AdjustSessionFailure sessionFailureResponseData) {
print(
Expand All @@ -458,7 +470,7 @@ class CommandExecutor {
}

if (_command.containsParameter('eventCallbackSendSuccess')) {
String? localBasePath = _basePath;
String? localBasePath = _extraPath;
adjustConfig.eventSuccessCallback =
(AdjustEventSuccess eventSuccessResponseData) {
print(
Expand All @@ -479,7 +491,7 @@ class CommandExecutor {
}

if (_command.containsParameter('eventCallbackSendFailure')) {
String? localBasePath = _basePath;
String? localBasePath = _extraPath;
adjustConfig.eventFailureCallback =
(AdjustEventFailure eventFailureResponseData) {
print(
Expand Down
21 changes: 6 additions & 15 deletions test/app/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,30 @@ class MyApp extends StatefulWidget {
}

class _MyAppState extends State<MyApp> {
String? _baseUrl;
String? _gdprUrl;
String? _subscriptionUrl;
String? _purchaseVerificationUrl;
String? _overwriteUrl;
late String _controlUrl;
late CommandExecutor _commandExecutor;

@override
void initState() {
super.initState();

String _address = '192.168.86.21';
String _address = '192.168.86.53';
if (Platform.isAndroid) {
String _protocol = 'https';
String _port = '8443';
_baseUrl = _protocol + '://' + _address + ':' + _port;
_gdprUrl = _protocol + '://' + _address + ':' + _port;
_subscriptionUrl = _protocol + '://' + _address + ':' + _port;
_purchaseVerificationUrl = _protocol + '://' + _address + ':' + _port;
_overwriteUrl = _protocol + '://' + _address + ':' + _port;
_controlUrl = 'ws://' + _address + ':1987';
} else {
String _protocol = 'http';
String _port = '8080';
_baseUrl = _protocol + '://' + _address + ':' + _port;
_gdprUrl = _protocol + '://' + _address + ':' + _port;
_subscriptionUrl = _protocol + '://' + _address + ':' + _port;
_purchaseVerificationUrl = _protocol + '://' + _address + ':' + _port;
_overwriteUrl = _protocol + '://' + _address + ':' + _port;
_controlUrl = 'ws://' + _address + ':1987';
}

// Initialise command executor.
_commandExecutor =
new CommandExecutor(_baseUrl, _gdprUrl, _subscriptionUrl, _purchaseVerificationUrl);
new CommandExecutor(_overwriteUrl);

// Initialise test library.
TestLib.setExecuteCommandHalder((final dynamic callArgs) {
Expand All @@ -59,7 +50,7 @@ class _MyAppState extends State<MyApp> {
'[AdjustTestApp]: Executing command ${command.className}.${command.methodName}');
_commandExecutor.executeCommand(command);
});
TestLib.init(_baseUrl!, _controlUrl);
TestLib.init(_overwriteUrl!, _controlUrl);
}

@override
Expand Down

0 comments on commit c39c113

Please sign in to comment.