Skip to content

Commit 94eaf24

Browse files
authored
Merge pull request #191 from mindbox-cloud/feature/MOBILE-160
[WIP] Feature/mobile 160
2 parents c579af0 + 5cfafe6 commit 94eaf24

5 files changed

Lines changed: 94 additions & 1 deletion

File tree

mindbox_android/android/src/main/kotlin/cloud/mindbox/mindbox_android/MindboxAndroidPlugin.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ class MindboxAndroidPlugin : FlutterPlugin, MethodCallHandler, ActivityAware, Ne
7272
val previousInstallId: String = args["previousInstallationId"] as String
7373
val subscribeIfCreated: Boolean = args["subscribeCustomerIfCreated"] as Boolean
7474
val shouldCreateCustomer: Boolean = args["shouldCreateCustomer"] as Boolean
75+
val operationsDomainArg: String = args["operationsDomain"] as? String ?: ""
7576
val config = MindboxConfiguration.Builder(context.applicationContext, domain, endpointId)
7677
.setPreviousDeviceUuid(previousDeviceUuid)
7778
.setPreviousInstallationId(previousInstallId)
7879
.subscribeCustomerIfCreated(subscribeIfCreated)
7980
.shouldCreateCustomer(shouldCreateCustomer)
81+
.operationsDomain(operationsDomainArg)
8082
.build()
8183
Mindbox.init(activity = context, config, listOf())
8284
result.success("initialized")

mindbox_ios/ios/Classes/SwiftMindboxIosPlugin.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,10 @@ public class SwiftMindboxIosPlugin: NSObject, FlutterPlugin {
8484
let shouldCreateCustomer = args["shouldCreateCustomer"] as? Bool{
8585
let prevUuid = previousUuid.isEmpty ? nil : previousUuid
8686
let prevId = previousInstallId.isEmpty ? nil : previousInstallId
87+
let operationsDomainRaw = args["operationsDomain"] as? String ?? ""
88+
let operationsDomain = operationsDomainRaw.isEmpty ? nil : operationsDomainRaw
8789
do{
88-
let config = try MBConfiguration(endpoint: endpoint, domain: domain,previousInstallationId: prevId, previousDeviceUUID: prevUuid, subscribeCustomerIfCreated: subscribeIfCreated, shouldCreateCustomer: shouldCreateCustomer)
90+
let config = try MBConfiguration(endpoint: endpoint, domain: domain, operationsDomain: operationsDomain, previousInstallationId: prevId, previousDeviceUUID: prevUuid, subscribeCustomerIfCreated: subscribeIfCreated, shouldCreateCustomer: shouldCreateCustomer)
8991
Mindbox.shared.initialization(configuration: config)
9092
result("initialized")
9193
}catch let error {

mindbox_platform_interface/lib/src/types/configuration.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ class Configuration {
99
this.previousDeviceUUID = '',
1010
this.previousInstallationId = '',
1111
this.shouldCreateCustomer = true,
12+
this.operationsDomain = '',
1213
});
1314

1415
/// Used for generating baseurl for REST.
1516
final String domain;
1617

18+
/// Optional separate host for sending operations. When empty, [domain]
19+
/// is used. Default is an empty string.
20+
final String operationsDomain;
21+
1722
/// Used for app identification on iOS.
1823
final String endpointIos;
1924

@@ -42,5 +47,6 @@ class Configuration {
4247
'previousInstallationId': previousInstallationId,
4348
'subscribeCustomerIfCreated': subscribeCustomerIfCreated,
4449
'shouldCreateCustomer': shouldCreateCustomer,
50+
'operationsDomain': operationsDomain,
4551
};
4652
}

mindbox_platform_interface/test/src/types/configuration_test.dart

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ void main() {
1212
previousDeviceUUID: 'previousDeviceUUID',
1313
subscribeCustomerIfCreated: true,
1414
shouldCreateCustomer: true,
15+
operationsDomain: 'operations.example.com',
1516
);
1617

1718
// Assert
@@ -22,5 +23,37 @@ void main() {
2223
expect(configuration.previousDeviceUUID, 'previousDeviceUUID');
2324
expect(configuration.subscribeCustomerIfCreated, true);
2425
expect(configuration.shouldCreateCustomer, true);
26+
expect(configuration.operationsDomain, 'operations.example.com');
27+
});
28+
29+
test('operationsDomain defaults to empty string when not provided', () {
30+
final Configuration configuration = Configuration(
31+
domain: 'domain',
32+
endpointIos: 'iOSEndpoint',
33+
endpointAndroid: 'androidEndpoint',
34+
);
35+
36+
expect(configuration.operationsDomain, '');
37+
});
38+
39+
test('toMap includes operationsDomain when set', () {
40+
final Configuration configuration = Configuration(
41+
domain: 'domain',
42+
endpointIos: 'iOSEndpoint',
43+
endpointAndroid: 'androidEndpoint',
44+
operationsDomain: 'operations.example.com',
45+
);
46+
47+
expect(configuration.toMap()['operationsDomain'], 'operations.example.com');
48+
});
49+
50+
test('toMap returns empty operationsDomain when not provided', () {
51+
final Configuration configuration = Configuration(
52+
domain: 'domain',
53+
endpointIos: 'iOSEndpoint',
54+
endpointAndroid: 'androidEndpoint',
55+
);
56+
57+
expect(configuration.toMap()['operationsDomain'], '');
2558
});
2659
}

mindbox_platform_interface/test/src/types/mindbox_method_handler_test.dart

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,56 @@ void main() {
5050
},
5151
);
5252

53+
test(
54+
'init() forwards operationsDomain to native channel',
55+
() async {
56+
final capturedArgs = <String, dynamic>{};
57+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
58+
.setMockMethodCallHandler(channel, (call) async {
59+
if (call.method == 'init') {
60+
capturedArgs.addAll(Map<String, dynamic>.from(call.arguments));
61+
}
62+
return mindboxMockMethodCallHandler(call);
63+
});
64+
65+
await handler.init(
66+
configuration: Configuration(
67+
domain: 'domain',
68+
endpointIos: 'endpointIos',
69+
endpointAndroid: 'endpointAndroid',
70+
operationsDomain: 'operations.example.com',
71+
),
72+
);
73+
74+
expect(capturedArgs['operationsDomain'], 'operations.example.com');
75+
},
76+
);
77+
78+
test(
79+
'init() forwards empty operationsDomain by default',
80+
() async {
81+
final capturedArgs = <String, dynamic>{};
82+
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
83+
.setMockMethodCallHandler(channel, (call) async {
84+
if (call.method == 'init') {
85+
capturedArgs.addAll(Map<String, dynamic>.from(call.arguments));
86+
}
87+
return mindboxMockMethodCallHandler(call);
88+
});
89+
90+
await handler.init(
91+
configuration: Configuration(
92+
domain: 'domain',
93+
endpointIos: 'endpointIos',
94+
endpointAndroid: 'endpointAndroid',
95+
),
96+
);
97+
98+
expect(capturedArgs.containsKey('operationsDomain'), isTrue);
99+
expect(capturedArgs['operationsDomain'], '');
100+
},
101+
);
102+
53103
test(
54104
'When config is invalid, init() calling should throws MindboxException',
55105
() async {

0 commit comments

Comments
 (0)