diff --git a/mindbox_android/android/src/main/kotlin/cloud/mindbox/mindbox_android/MindboxAndroidPlugin.kt b/mindbox_android/android/src/main/kotlin/cloud/mindbox/mindbox_android/MindboxAndroidPlugin.kt index be7d742..e587c8b 100644 --- a/mindbox_android/android/src/main/kotlin/cloud/mindbox/mindbox_android/MindboxAndroidPlugin.kt +++ b/mindbox_android/android/src/main/kotlin/cloud/mindbox/mindbox_android/MindboxAndroidPlugin.kt @@ -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") diff --git a/mindbox_ios/ios/Classes/SwiftMindboxIosPlugin.swift b/mindbox_ios/ios/Classes/SwiftMindboxIosPlugin.swift index 6fb7119..5d07fa9 100644 --- a/mindbox_ios/ios/Classes/SwiftMindboxIosPlugin.swift +++ b/mindbox_ios/ios/Classes/SwiftMindboxIosPlugin.swift @@ -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 { diff --git a/mindbox_platform_interface/lib/src/types/configuration.dart b/mindbox_platform_interface/lib/src/types/configuration.dart index bcd725d..00fbe35 100644 --- a/mindbox_platform_interface/lib/src/types/configuration.dart +++ b/mindbox_platform_interface/lib/src/types/configuration.dart @@ -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; @@ -42,5 +47,6 @@ class Configuration { 'previousInstallationId': previousInstallationId, 'subscribeCustomerIfCreated': subscribeCustomerIfCreated, 'shouldCreateCustomer': shouldCreateCustomer, + 'operationsDomain': operationsDomain, }; } diff --git a/mindbox_platform_interface/test/src/types/configuration_test.dart b/mindbox_platform_interface/test/src/types/configuration_test.dart index b5c6647..ee1576d 100644 --- a/mindbox_platform_interface/test/src/types/configuration_test.dart +++ b/mindbox_platform_interface/test/src/types/configuration_test.dart @@ -12,6 +12,7 @@ void main() { previousDeviceUUID: 'previousDeviceUUID', subscribeCustomerIfCreated: true, shouldCreateCustomer: true, + operationsDomain: 'operations.example.com', ); // Assert @@ -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'], ''); }); } diff --git a/mindbox_platform_interface/test/src/types/mindbox_method_handler_test.dart b/mindbox_platform_interface/test/src/types/mindbox_method_handler_test.dart index dd04d93..ed685e0 100644 --- a/mindbox_platform_interface/test/src/types/mindbox_method_handler_test.dart +++ b/mindbox_platform_interface/test/src/types/mindbox_method_handler_test.dart @@ -50,6 +50,56 @@ void main() { }, ); + test( + 'init() forwards operationsDomain to native channel', + () async { + final capturedArgs = {}; + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(channel, (call) async { + if (call.method == 'init') { + capturedArgs.addAll(Map.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 = {}; + TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger + .setMockMethodCallHandler(channel, (call) async { + if (call.method == 'init') { + capturedArgs.addAll(Map.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 {