Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ class MindboxAndroidPlugin : FlutterPlugin, MethodCallHandler, ActivityAware, Ne
val previousInstallId: String = args["previousInstallationId"] as String
val subscribeIfCreated: Boolean = args["subscribeCustomerIfCreated"] as Boolean
val shouldCreateCustomer: Boolean = args["shouldCreateCustomer"] as Boolean
val operationsDomainArg: String = args["operationsDomain"] as? String ?: ""
val config = MindboxConfiguration.Builder(context.applicationContext, domain, endpointId)
.setPreviousDeviceUuid(previousDeviceUuid)
.setPreviousInstallationId(previousInstallId)
.subscribeCustomerIfCreated(subscribeIfCreated)
.shouldCreateCustomer(shouldCreateCustomer)
.operationsDomain(operationsDomainArg)
.build()
Mindbox.init(activity = context, config, listOf())
result.success("initialized")
Expand Down
4 changes: 3 additions & 1 deletion mindbox_ios/ios/Classes/SwiftMindboxIosPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ public class SwiftMindboxIosPlugin: NSObject, FlutterPlugin {
let shouldCreateCustomer = args["shouldCreateCustomer"] as? Bool{
let prevUuid = previousUuid.isEmpty ? nil : previousUuid
let prevId = previousInstallId.isEmpty ? nil : previousInstallId
let operationsDomainRaw = args["operationsDomain"] as? String ?? ""
let operationsDomain = operationsDomainRaw.isEmpty ? nil : operationsDomainRaw
do{
let config = try MBConfiguration(endpoint: endpoint, domain: domain,previousInstallationId: prevId, previousDeviceUUID: prevUuid, subscribeCustomerIfCreated: subscribeIfCreated, shouldCreateCustomer: shouldCreateCustomer)
let config = try MBConfiguration(endpoint: endpoint, domain: domain, operationsDomain: operationsDomain, previousInstallationId: prevId, previousDeviceUUID: prevUuid, subscribeCustomerIfCreated: subscribeIfCreated, shouldCreateCustomer: shouldCreateCustomer)
Mindbox.shared.initialization(configuration: config)
result("initialized")
}catch let error {
Expand Down
6 changes: 6 additions & 0 deletions mindbox_platform_interface/lib/src/types/configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ class Configuration {
this.previousDeviceUUID = '',
this.previousInstallationId = '',
this.shouldCreateCustomer = true,
this.operationsDomain = '',
});

/// Used for generating baseurl for REST.
final String domain;

/// Optional separate host for sending operations. When empty, [domain]
/// is used. Default is an empty string.
final String operationsDomain;

/// Used for app identification on iOS.
final String endpointIos;

Expand Down Expand Up @@ -42,5 +47,6 @@ class Configuration {
'previousInstallationId': previousInstallationId,
'subscribeCustomerIfCreated': subscribeCustomerIfCreated,
'shouldCreateCustomer': shouldCreateCustomer,
'operationsDomain': operationsDomain,
};
}
33 changes: 33 additions & 0 deletions mindbox_platform_interface/test/src/types/configuration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void main() {
previousDeviceUUID: 'previousDeviceUUID',
subscribeCustomerIfCreated: true,
shouldCreateCustomer: true,
operationsDomain: 'operations.example.com',
);

// Assert
Expand All @@ -22,5 +23,37 @@ void main() {
expect(configuration.previousDeviceUUID, 'previousDeviceUUID');
expect(configuration.subscribeCustomerIfCreated, true);
expect(configuration.shouldCreateCustomer, true);
expect(configuration.operationsDomain, 'operations.example.com');
});

test('operationsDomain defaults to empty string when not provided', () {
final Configuration configuration = Configuration(
domain: 'domain',
endpointIos: 'iOSEndpoint',
endpointAndroid: 'androidEndpoint',
);

expect(configuration.operationsDomain, '');
});

test('toMap includes operationsDomain when set', () {
final Configuration configuration = Configuration(
domain: 'domain',
endpointIos: 'iOSEndpoint',
endpointAndroid: 'androidEndpoint',
operationsDomain: 'operations.example.com',
);

expect(configuration.toMap()['operationsDomain'], 'operations.example.com');
});

test('toMap returns empty operationsDomain when not provided', () {
final Configuration configuration = Configuration(
domain: 'domain',
endpointIos: 'iOSEndpoint',
endpointAndroid: 'androidEndpoint',
);

expect(configuration.toMap()['operationsDomain'], '');
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,56 @@ void main() {
},
);

test(
'init() forwards operationsDomain to native channel',
() async {
final capturedArgs = <String, dynamic>{};
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (call) async {
if (call.method == 'init') {
capturedArgs.addAll(Map<String, dynamic>.from(call.arguments));
}
return mindboxMockMethodCallHandler(call);
});

await handler.init(
configuration: Configuration(
domain: 'domain',
endpointIos: 'endpointIos',
endpointAndroid: 'endpointAndroid',
operationsDomain: 'operations.example.com',
),
);

expect(capturedArgs['operationsDomain'], 'operations.example.com');
},
);

test(
'init() forwards empty operationsDomain by default',
() async {
final capturedArgs = <String, dynamic>{};
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (call) async {
if (call.method == 'init') {
capturedArgs.addAll(Map<String, dynamic>.from(call.arguments));
}
return mindboxMockMethodCallHandler(call);
});

await handler.init(
configuration: Configuration(
domain: 'domain',
endpointIos: 'endpointIos',
endpointAndroid: 'endpointAndroid',
),
);

expect(capturedArgs.containsKey('operationsDomain'), isTrue);
expect(capturedArgs['operationsDomain'], '');
},
);

test(
'When config is invalid, init() calling should throws MindboxException',
() async {
Expand Down
Loading