From 265b9733e5fc4a7e0c96378b5e219359996794f9 Mon Sep 17 00:00:00 2001 From: Roland Misica Date: Wed, 6 Mar 2024 16:27:55 +0100 Subject: [PATCH] Tests and Documentation update for In-app message delegate --- documentation/IN_APP_MESSAGES.md | 16 + lib/src/data/encoder/in_app_message.dart | 6 +- lib/src/data/encoder/main.dart | 3 + lib/src/data/model/in_app_message.dart | 22 +- .../unit/data/in_app_message_action_test.dart | 95 ++++ .../unit/data/in_app_message_button_test.dart | 61 +++ test/unit/data/in_app_message_test.dart | 476 ++++++++++++++++++ test/values/in_app_message.json | 153 ++++++ test/values/in_app_message_action.json | 49 ++ test/values/in_app_message_button.json | 5 + 10 files changed, 872 insertions(+), 14 deletions(-) create mode 100644 test/unit/data/in_app_message_action_test.dart create mode 100644 test/unit/data/in_app_message_button_test.dart create mode 100644 test/unit/data/in_app_message_test.dart create mode 100644 test/values/in_app_message.json create mode 100644 test/values/in_app_message_action.json create mode 100644 test/values/in_app_message_button.json diff --git a/documentation/IN_APP_MESSAGES.md b/documentation/IN_APP_MESSAGES.md index c134246..d458b6a 100644 --- a/documentation/IN_APP_MESSAGES.md +++ b/documentation/IN_APP_MESSAGES.md @@ -20,3 +20,19 @@ In-app messages are triggered when an event is tracked based on conditions setup If your application decides to present another UIViewController/start a new Activity right at the same time a race condition is created and the message might be displayed and immediately dismissed. Keep this in mind if the logs tell you your message was displayed but you don't see it. > Show on `App load` displays in-app message when a `session_start` event is tracked. If you close and quickly reopen the app, it's possible that the session did not timeout and message won't be displayed. If you use manual session tracking, the message won't be displayed unless you track `session_start` event yourself. + +### Custom in-app message actions +If you want to override default SDK behavior, when in-app message action is performed (button is clicked, a message is closed), or you want to add your code to be performed along with code executed by the SDK, you can set up a listener for `inAppMessageAction` using `ExponeaPlugin.inAppMessageActionStream({bool overrideDefaultBehavior = false, bool trackActions = true})`. You can override default behavior of SDK with `overrideDefaultBehavior` and `trackActions` parameters. If overrideDefaultBehavior is set to true, default in-app action will not be performed ( e.g. deep link ). If trackActions is set to false, click and close in-app events will not be tracked automatically. +The SDK will hold last inAppMessageAction and call the listener once it's set, but it's still recommended to set the listener as soon as possible. + +```dart +// If overrideDefaultBehavior is set to true, default in-app action will not be performed ( e.g. deep link ) +const overrideDefaultBehavior = false; +// If trackActions is set to false, click and close in-app events will not be tracked automatically +const trackActions = true; +final subscription = _plugin.inAppMessageActionStream(overrideDefaultBehavior: overrideDefaultBehavior, trackActions: trackActions).listen((inAppMessageAction) { + print(inAppMessageAction); +}); +``` + +Don't forget to call `subscription.cancel()` when no longer needed. If you cancel subscription from stream, SDK returns back to default behavior (default in-app action will be performed and click and close in-app events will be tracked). diff --git a/lib/src/data/encoder/in_app_message.dart b/lib/src/data/encoder/in_app_message.dart index 395ff0e..8c7643e 100644 --- a/lib/src/data/encoder/in_app_message.dart +++ b/lib/src/data/encoder/in_app_message.dart @@ -34,11 +34,11 @@ class InAppMessageEncoder { 'name': message.name, 'messageType': message.messageType, 'frequency': message.frequency, - 'payload': message.payload, + 'payload': message.payload?.let(jsonEncode), 'variantId': message.variantId, 'variantName': message.variantName, - 'trigger': message.trigger, - 'dateFilter': message.dateFilter, + 'trigger': message.trigger?.let(jsonEncode), + 'dateFilter': message.dateFilter?.let(jsonEncode), 'loadPriority': message.loadPriority, 'loadDelay': message.loadDelay, 'closeTimeout': message.closeTimeout, diff --git a/lib/src/data/encoder/main.dart b/lib/src/data/encoder/main.dart index bee891b..11acb93 100644 --- a/lib/src/data/encoder/main.dart +++ b/lib/src/data/encoder/main.dart @@ -17,3 +17,6 @@ export 'push_type.dart'; export 'recommendation.dart'; export 'token_frequency.dart'; export 'app_inbox.dart'; +export 'in_app_message.dart'; +export 'in_app_message_action.dart'; +export 'in_app_message_button.dart'; diff --git a/lib/src/data/model/in_app_message.dart b/lib/src/data/model/in_app_message.dart index 810b25a..9ef13b8 100644 --- a/lib/src/data/model/in_app_message.dart +++ b/lib/src/data/model/in_app_message.dart @@ -22,20 +22,20 @@ class InAppMessage { const InAppMessage({ required this.id, required this.name, - required this.messageType, + this.messageType, required this.frequency, - required this.payload, + this.payload, required this.variantId, required this.variantName, - required this.trigger, - required this.dateFilter, - required this.loadPriority, - required this.loadDelay, - required this.closeTimeout, - required this.payloadHtml, - required this.isHtml, - required this.hasTrackingConsent, - required this.consentCategoryTracking, + this.trigger, + this.dateFilter, + this.loadPriority, + this.loadDelay, + this.closeTimeout, + this.payloadHtml, + this.isHtml, + this.hasTrackingConsent, + this.consentCategoryTracking, }); @override diff --git a/test/unit/data/in_app_message_action_test.dart b/test/unit/data/in_app_message_action_test.dart new file mode 100644 index 0000000..865f3eb --- /dev/null +++ b/test/unit/data/in_app_message_action_test.dart @@ -0,0 +1,95 @@ +import 'package:exponea/exponea.dart'; +import 'package:exponea/src/data/encoder/main.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'base.dart'; + +void main() { + group('InAppMessageAction', () { + const encode = InAppMessageActionEncoder.encode; + const decode = InAppMessageActionEncoder.decode; + + final data = readMapData('in_app_message_action'); + test('check data', () async { + expect(data.length, 3); + }); + final noData = data[0]; + final minData = data[1]; + final fullData = data[2]; + + group('encode', () { + test('minimal', () async { + const inAppMessageAction = InAppMessageAction( + message: InAppMessage( + id: 'mock-id', + name: 'mock-name', + frequency: 'mock-frequency', + variantId: 1, + variantName: 'mock-variantName', + messageType: 'mock-messageType', + payload: {'mock-payload-param': 'mock-payload-content'}, + trigger: {'mock-trigger-param': 'mock-trigger-content'}, + dateFilter: {'mock-dateFilter-param': 'mock-dateFilter-content'}, + loadPriority: 1, + loadDelay: 1000, + closeTimeout: 2000, + payloadHtml: 'mock-payloadHtml', + isHtml: true, + hasTrackingConsent: true, + consentCategoryTracking: 'mock-consentCategoryTracking', + ), + interaction: true, + ); + expect(encode(inAppMessageAction), minData); + }); + + test('full', () async { + const inAppMessageAction = InAppMessageAction( + message: InAppMessage( + id: 'mock-id', + name: 'mock-name', + frequency: 'mock-frequency', + variantId: 1, + variantName: 'mock-variantName', + messageType: 'mock-messageType', + payload: {'mock-payload-param': 'mock-payload-content'}, + trigger: {'mock-trigger-param': 'mock-trigger-content'}, + dateFilter: {'mock-dateFilter-param': 'mock-dateFilter-content'}, + loadPriority: 1, + loadDelay: 1000, + closeTimeout: 2000, + payloadHtml: 'mock-payloadHtml', + isHtml: true, + hasTrackingConsent: true, + consentCategoryTracking: 'mock-consentCategoryTracking', + ), + interaction: true, + button: InAppMessageButton( + text: 'button', + url: "https://a.b.c", + )); + expect(encode(inAppMessageAction), fullData); + }); + }); + + group('decode', () { + test('no data', () async { + expect(() => decode(noData), throwsStateError); + }); + + test('minimal', () async { + final decoded = decode(minData); + expect(decoded.message, isA()); + expect(decoded.interaction, true); + expect(decoded.button, null); + }); + + test('full data', () async { + final decoded = decode(fullData); + expect(decoded.message, isA()); + expect(decoded.interaction, true); + expect(decoded.button, isA()); + }); + }); + }); +} diff --git a/test/unit/data/in_app_message_button_test.dart b/test/unit/data/in_app_message_button_test.dart new file mode 100644 index 0000000..fe14c51 --- /dev/null +++ b/test/unit/data/in_app_message_button_test.dart @@ -0,0 +1,61 @@ +import 'package:exponea/exponea.dart'; +import 'package:exponea/src/data/encoder/main.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'base.dart'; + +void main() { + group('InAppMessageButton', () { + const encode = InAppMessageButtonEncoder.encode; + const decode = InAppMessageButtonEncoder.decode; + + final data = readMapData('in_app_message_button'); + test('check data', () async { + expect(data.length, 3); + }); + final noData = data[0]; + final textOnlyData = data[1]; + final fullData = data[2]; + + group('encode', () { + test('no data', () { + const inAppMessageButton = InAppMessageButton(); + expect(encode(inAppMessageButton), noData); + }); + + test('text only', () async { + const inAppMessageButton = InAppMessageButton(text: 'button'); + expect(encode(inAppMessageButton), textOnlyData); + }); + + test('full data', () async { + const inAppMessageButton = InAppMessageButton(text: 'button', url: 'https://a.b.c'); + expect(encode(inAppMessageButton), fullData); + }); + }); + + group('decode', () { + test('no data', () async { + const expected = InAppMessageButton(); + final decoded = decode(noData); + + expect(decoded.text, null); + expect(decoded.url, null); + }); + + test('text only', () async { + final decoded = decode(textOnlyData); + + expect(decoded.text, 'button'); + expect(decoded.url, null); + }); + + test('full data', () async { + final decoded = decode(fullData); + + expect(decoded.text, 'button'); + expect(decoded.url, 'https://a.b.c'); + }); + }); + }); +} diff --git a/test/unit/data/in_app_message_test.dart b/test/unit/data/in_app_message_test.dart new file mode 100644 index 0000000..ffc8a98 --- /dev/null +++ b/test/unit/data/in_app_message_test.dart @@ -0,0 +1,476 @@ +import 'package:exponea/exponea.dart'; +import 'package:exponea/src/data/encoder/main.dart'; +import 'package:flutter_test/flutter_test.dart'; + +import 'base.dart'; + +void main() { + group('InAppMessage', () { + const encode = InAppMessageEncoder.encode; + const decode = InAppMessageEncoder.decode; + + final data = readMapData('in_app_message'); + test('check data', () async { + expect(data.length, 13); + }); + final noData = data[0]; + final minData = data[1]; + final withMessageTypeData = data[2]; + final withPayloadData = data[3]; + final withTriggerData = data[4]; + final withDateFilterData = data[5]; + final withLoadPriorityData = data[6]; + final withLoadDelayData = data[7]; + final withCloseTimeoutData = data[8]; + final withPayloadHtmlData = data[9]; + final withIsHtmlData = data[10]; + final withHasTrackingConsentData = data[11]; + final fullData = data[12]; + + group('encode', () { + test('minimal', () async { + const inAppMessage = InAppMessage( + id: 'mock-id', + name: 'mock-name', + frequency: 'mock-frequency', + variantId: 1, + variantName: 'mock-variantName', + ); + expect(encode(inAppMessage), minData); + }); + + test('with messageType value', () async { + const inAppMessage = InAppMessage( + id: 'mock-id', + name: 'mock-name', + frequency: 'mock-frequency', + variantId: 1, + variantName: 'mock-variantName', + messageType: 'mock-messageType', + ); + expect(encode(inAppMessage), withMessageTypeData); + }); + + test('with payload value', () async { + const inAppMessage = InAppMessage( + id: 'mock-id', + name: 'mock-name', + frequency: 'mock-frequency', + variantId: 1, + variantName: 'mock-variantName', + messageType: 'mock-messageType', + payload: {'mock-payload-param': 'mock-payload-content'}, + ); + expect(encode(inAppMessage), withPayloadData); + }); + + test('with trigger value', () async { + const inAppMessage = InAppMessage( + id: 'mock-id', + name: 'mock-name', + frequency: 'mock-frequency', + variantId: 1, + variantName: 'mock-variantName', + messageType: 'mock-messageType', + payload: {'mock-payload-param': 'mock-payload-content'}, + trigger: {'mock-trigger-param': 'mock-trigger-content'}, + ); + expect(encode(inAppMessage), withTriggerData); + }); + + test('with dateFilter value', () async { + const inAppMessage = InAppMessage( + id: 'mock-id', + name: 'mock-name', + frequency: 'mock-frequency', + variantId: 1, + variantName: 'mock-variantName', + messageType: 'mock-messageType', + payload: {'mock-payload-param': 'mock-payload-content'}, + trigger: {'mock-trigger-param': 'mock-trigger-content'}, + dateFilter: {'mock-dateFilter-param': 'mock-dateFilter-content'}, + ); + expect(encode(inAppMessage), withDateFilterData); + }); + + test('with loadPriority value', () async { + const inAppMessage = InAppMessage( + id: 'mock-id', + name: 'mock-name', + frequency: 'mock-frequency', + variantId: 1, + variantName: 'mock-variantName', + messageType: 'mock-messageType', + payload: {'mock-payload-param': 'mock-payload-content'}, + trigger: {'mock-trigger-param': 'mock-trigger-content'}, + dateFilter: {'mock-dateFilter-param': 'mock-dateFilter-content'}, + loadPriority: 1, + ); + expect(encode(inAppMessage), withLoadPriorityData); + }); + + test('with LoadDelay value', () async { + const inAppMessage = InAppMessage( + id: 'mock-id', + name: 'mock-name', + frequency: 'mock-frequency', + variantId: 1, + variantName: 'mock-variantName', + messageType: 'mock-messageType', + payload: {'mock-payload-param': 'mock-payload-content'}, + trigger: {'mock-trigger-param': 'mock-trigger-content'}, + dateFilter: {'mock-dateFilter-param': 'mock-dateFilter-content'}, + loadPriority: 1, + loadDelay: 1000, + ); + expect(encode(inAppMessage), withLoadDelayData); + }); + + test('with closeTimeout value', () async { + const inAppMessage = InAppMessage( + id: 'mock-id', + name: 'mock-name', + frequency: 'mock-frequency', + variantId: 1, + variantName: 'mock-variantName', + messageType: 'mock-messageType', + payload: {'mock-payload-param': 'mock-payload-content'}, + trigger: {'mock-trigger-param': 'mock-trigger-content'}, + dateFilter: {'mock-dateFilter-param': 'mock-dateFilter-content'}, + loadPriority: 1, + loadDelay: 1000, + closeTimeout: 2000, + ); + expect(encode(inAppMessage), withCloseTimeoutData); + }); + + test('with payloadHtml value', () async { + const inAppMessage = InAppMessage( + id: 'mock-id', + name: 'mock-name', + frequency: 'mock-frequency', + variantId: 1, + variantName: 'mock-variantName', + messageType: 'mock-messageType', + payload: {'mock-payload-param': 'mock-payload-content'}, + trigger: {'mock-trigger-param': 'mock-trigger-content'}, + dateFilter: {'mock-dateFilter-param': 'mock-dateFilter-content'}, + loadPriority: 1, + loadDelay: 1000, + closeTimeout: 2000, + payloadHtml: 'mock-payloadHtml', + ); + expect(encode(inAppMessage), withPayloadHtmlData); + }); + + test('with isHtml value', () async { + const inAppMessage = InAppMessage( + id: 'mock-id', + name: 'mock-name', + frequency: 'mock-frequency', + variantId: 1, + variantName: 'mock-variantName', + messageType: 'mock-messageType', + payload: {'mock-payload-param': 'mock-payload-content'}, + trigger: {'mock-trigger-param': 'mock-trigger-content'}, + dateFilter: {'mock-dateFilter-param': 'mock-dateFilter-content'}, + loadPriority: 1, + loadDelay: 1000, + closeTimeout: 2000, + payloadHtml: 'mock-payloadHtml', + isHtml: true, + ); + expect(encode(inAppMessage), withIsHtmlData); + }); + + test('with hasTrackingConsent value', () async { + const inAppMessage = InAppMessage( + id: 'mock-id', + name: 'mock-name', + frequency: 'mock-frequency', + variantId: 1, + variantName: 'mock-variantName', + messageType: 'mock-messageType', + payload: {'mock-payload-param': 'mock-payload-content'}, + trigger: {'mock-trigger-param': 'mock-trigger-content'}, + dateFilter: {'mock-dateFilter-param': 'mock-dateFilter-content'}, + loadPriority: 1, + loadDelay: 1000, + closeTimeout: 2000, + payloadHtml: 'mock-payloadHtml', + isHtml: true, + hasTrackingConsent: true, + ); + expect(encode(inAppMessage), withHasTrackingConsentData); + }); + + test('full data', () async { + const inAppMessage = InAppMessage( + id: 'mock-id', + name: 'mock-name', + frequency: 'mock-frequency', + variantId: 1, + variantName: 'mock-variantName', + messageType: 'mock-messageType', + payload: {'mock-payload-param': 'mock-payload-content'}, + trigger: {'mock-trigger-param': 'mock-trigger-content'}, + dateFilter: {'mock-dateFilter-param': 'mock-dateFilter-content'}, + loadPriority: 1, + loadDelay: 1000, + closeTimeout: 2000, + payloadHtml: 'mock-payloadHtml', + isHtml: true, + hasTrackingConsent: true, + consentCategoryTracking: 'mock-consentCategoryTracking', + ); + expect(encode(inAppMessage), fullData); + }); + }); + + group('decode', () { + test('no data', () async { + expect(() => decode(noData), throwsStateError); + }); + + test('minimal', () async { + final decoded = decode(minData); + expect(decoded.id, 'mock-id'); + expect(decoded.name, 'mock-name'); + expect(decoded.frequency, 'mock-frequency'); + expect(decoded.variantId, 1); + expect(decoded.variantName, 'mock-variantName'); + expect(decoded.messageType, null); + expect(decoded.payload, null); + expect(decoded.trigger, null); + expect(decoded.dateFilter, null); + expect(decoded.loadPriority, null); + expect(decoded.loadDelay, null); + expect(decoded.closeTimeout, null); + expect(decoded.payloadHtml, null); + expect(decoded.isHtml, null); + expect(decoded.hasTrackingConsent, null); + expect(decoded.consentCategoryTracking, null); + }); + + test('with messageType value', () async { + final decoded = decode(withMessageTypeData); + expect(decoded.id, 'mock-id'); + expect(decoded.name, 'mock-name'); + expect(decoded.frequency, 'mock-frequency'); + expect(decoded.variantId, 1); + expect(decoded.variantName, 'mock-variantName'); + expect(decoded.messageType, 'mock-messageType'); + expect(decoded.payload, null); + expect(decoded.trigger, null); + expect(decoded.dateFilter, null); + expect(decoded.loadPriority, null); + expect(decoded.loadDelay, null); + expect(decoded.closeTimeout, null); + expect(decoded.payloadHtml, null); + expect(decoded.isHtml, null); + expect(decoded.hasTrackingConsent, null); + expect(decoded.consentCategoryTracking, null); + }); + + test('with payload value', () async { + final decoded = decode(withPayloadData); + expect(decoded.id, 'mock-id'); + expect(decoded.name, 'mock-name'); + expect(decoded.frequency, 'mock-frequency'); + expect(decoded.variantId, 1); + expect(decoded.variantName, 'mock-variantName'); + expect(decoded.messageType, 'mock-messageType'); + expect(decoded.payload, {"mock-payload-param": "mock-payload-content"}); + expect(decoded.trigger, null); + expect(decoded.dateFilter, null); + expect(decoded.loadPriority, null); + expect(decoded.loadDelay, null); + expect(decoded.closeTimeout, null); + expect(decoded.payloadHtml, null); + expect(decoded.isHtml, null); + expect(decoded.hasTrackingConsent, null); + expect(decoded.consentCategoryTracking, null); + }); + + test('with trigger value', () async { + final decoded = decode(withTriggerData); + expect(decoded.id, 'mock-id'); + expect(decoded.name, 'mock-name'); + expect(decoded.frequency, 'mock-frequency'); + expect(decoded.variantId, 1); + expect(decoded.variantName, 'mock-variantName'); + expect(decoded.messageType, 'mock-messageType'); + expect(decoded.payload, {"mock-payload-param": "mock-payload-content"}); + expect(decoded.trigger, {"mock-trigger-param": "mock-trigger-content"}); + expect(decoded.dateFilter, null); + expect(decoded.loadPriority, null); + expect(decoded.loadDelay, null); + expect(decoded.closeTimeout, null); + expect(decoded.payloadHtml, null); + expect(decoded.isHtml, null); + expect(decoded.hasTrackingConsent, null); + expect(decoded.consentCategoryTracking, null); + }); + + test('with dateFilter value', () async { + final decoded = decode(withDateFilterData); + expect(decoded.id, 'mock-id'); + expect(decoded.name, 'mock-name'); + expect(decoded.frequency, 'mock-frequency'); + expect(decoded.variantId, 1); + expect(decoded.variantName, 'mock-variantName'); + expect(decoded.messageType, 'mock-messageType'); + expect(decoded.payload, {"mock-payload-param": "mock-payload-content"}); + expect(decoded.trigger, {"mock-trigger-param": "mock-trigger-content"}); + expect(decoded.dateFilter, {"mock-dateFilter-param": "mock-dateFilter-content"}); + expect(decoded.loadPriority, null); + expect(decoded.loadDelay, null); + expect(decoded.closeTimeout, null); + expect(decoded.payloadHtml, null); + expect(decoded.isHtml, null); + expect(decoded.hasTrackingConsent, null); + expect(decoded.consentCategoryTracking, null); + }); + + test('with loadPriority value', () async { + final decoded = decode(withLoadPriorityData); + expect(decoded.id, 'mock-id'); + expect(decoded.name, 'mock-name'); + expect(decoded.frequency, 'mock-frequency'); + expect(decoded.variantId, 1); + expect(decoded.variantName, 'mock-variantName'); + expect(decoded.messageType, 'mock-messageType'); + expect(decoded.payload, {"mock-payload-param": "mock-payload-content"}); + expect(decoded.trigger, {"mock-trigger-param": "mock-trigger-content"}); + expect(decoded.dateFilter, {"mock-dateFilter-param": "mock-dateFilter-content"}); + expect(decoded.loadPriority, 1); + expect(decoded.loadDelay, null); + expect(decoded.closeTimeout, null); + expect(decoded.payloadHtml, null); + expect(decoded.isHtml, null); + expect(decoded.hasTrackingConsent, null); + expect(decoded.consentCategoryTracking, null); + }); + + test('with loadDelay value', () async { + final decoded = decode(withLoadDelayData); + expect(decoded.id, 'mock-id'); + expect(decoded.name, 'mock-name'); + expect(decoded.frequency, 'mock-frequency'); + expect(decoded.variantId, 1); + expect(decoded.variantName, 'mock-variantName'); + expect(decoded.messageType, 'mock-messageType'); + expect(decoded.payload, {"mock-payload-param": "mock-payload-content"}); + expect(decoded.trigger, {"mock-trigger-param": "mock-trigger-content"}); + expect(decoded.dateFilter, {"mock-dateFilter-param": "mock-dateFilter-content"}); + expect(decoded.loadPriority, 1); + expect(decoded.loadDelay, 1000); + expect(decoded.closeTimeout, null); + expect(decoded.payloadHtml, null); + expect(decoded.isHtml, null); + expect(decoded.hasTrackingConsent, null); + expect(decoded.consentCategoryTracking, null); + }); + + test('with closeTimeout value', () async { + final decoded = decode(withCloseTimeoutData); + expect(decoded.id, 'mock-id'); + expect(decoded.name, 'mock-name'); + expect(decoded.frequency, 'mock-frequency'); + expect(decoded.variantId, 1); + expect(decoded.variantName, 'mock-variantName'); + expect(decoded.messageType, 'mock-messageType'); + expect(decoded.payload, {"mock-payload-param": "mock-payload-content"}); + expect(decoded.trigger, {"mock-trigger-param": "mock-trigger-content"}); + expect(decoded.dateFilter, {"mock-dateFilter-param": "mock-dateFilter-content"}); + expect(decoded.loadPriority, 1); + expect(decoded.loadDelay, 1000); + expect(decoded.closeTimeout, 2000); + expect(decoded.payloadHtml, null); + expect(decoded.isHtml, null); + expect(decoded.hasTrackingConsent, null); + expect(decoded.consentCategoryTracking, null); + }); + + test('with payloadHtml value', () async { + final decoded = decode(withPayloadHtmlData); + expect(decoded.id, 'mock-id'); + expect(decoded.name, 'mock-name'); + expect(decoded.frequency, 'mock-frequency'); + expect(decoded.variantId, 1); + expect(decoded.variantName, 'mock-variantName'); + expect(decoded.messageType, 'mock-messageType'); + expect(decoded.payload, {"mock-payload-param": "mock-payload-content"}); + expect(decoded.trigger, {"mock-trigger-param": "mock-trigger-content"}); + expect(decoded.dateFilter, {"mock-dateFilter-param": "mock-dateFilter-content"}); + expect(decoded.loadPriority, 1); + expect(decoded.loadDelay, 1000); + expect(decoded.closeTimeout, 2000); + expect(decoded.payloadHtml, 'mock-payloadHtml'); + expect(decoded.isHtml, null); + expect(decoded.hasTrackingConsent, null); + expect(decoded.consentCategoryTracking, null); + }); + + test('with isHtml value', () async { + final decoded = decode(withIsHtmlData); + expect(decoded.id, 'mock-id'); + expect(decoded.name, 'mock-name'); + expect(decoded.frequency, 'mock-frequency'); + expect(decoded.variantId, 1); + expect(decoded.variantName, 'mock-variantName'); + expect(decoded.messageType, 'mock-messageType'); + expect(decoded.payload, {"mock-payload-param": "mock-payload-content"}); + expect(decoded.trigger, {"mock-trigger-param": "mock-trigger-content"}); + expect(decoded.dateFilter, {"mock-dateFilter-param": "mock-dateFilter-content"}); + expect(decoded.loadPriority, 1); + expect(decoded.loadDelay, 1000); + expect(decoded.closeTimeout, 2000); + expect(decoded.payloadHtml, 'mock-payloadHtml'); + expect(decoded.isHtml, true); + expect(decoded.hasTrackingConsent, null); + expect(decoded.consentCategoryTracking, null); + }); + + test('with hasTrackingConsent value', () async { + final decoded = decode(withHasTrackingConsentData); + expect(decoded.id, 'mock-id'); + expect(decoded.name, 'mock-name'); + expect(decoded.frequency, 'mock-frequency'); + expect(decoded.variantId, 1); + expect(decoded.variantName, 'mock-variantName'); + expect(decoded.messageType, 'mock-messageType'); + expect(decoded.payload, {"mock-payload-param": "mock-payload-content"}); + expect(decoded.trigger, {"mock-trigger-param": "mock-trigger-content"}); + expect(decoded.dateFilter, {"mock-dateFilter-param": "mock-dateFilter-content"}); + expect(decoded.loadPriority, 1); + expect(decoded.loadDelay, 1000); + expect(decoded.closeTimeout, 2000); + expect(decoded.payloadHtml, 'mock-payloadHtml'); + expect(decoded.isHtml, true); + expect(decoded.hasTrackingConsent, true); + expect(decoded.consentCategoryTracking, null); + }); + + test('full data', () async { + final decoded = decode(fullData); + expect(decoded.id, 'mock-id'); + expect(decoded.name, 'mock-name'); + expect(decoded.frequency, 'mock-frequency'); + expect(decoded.variantId, 1); + expect(decoded.variantName, 'mock-variantName'); + expect(decoded.messageType, 'mock-messageType'); + expect(decoded.payload, {"mock-payload-param": "mock-payload-content"}); + expect(decoded.trigger, {"mock-trigger-param": "mock-trigger-content"}); + expect(decoded.dateFilter, {"mock-dateFilter-param": "mock-dateFilter-content"}); + expect(decoded.loadPriority, 1); + expect(decoded.loadDelay, 1000); + expect(decoded.closeTimeout, 2000); + expect(decoded.payloadHtml, 'mock-payloadHtml'); + expect(decoded.isHtml, true); + expect(decoded.hasTrackingConsent, true); + expect(decoded.consentCategoryTracking, 'mock-consentCategoryTracking'); + }); + }); + }); +} diff --git a/test/values/in_app_message.json b/test/values/in_app_message.json new file mode 100644 index 0000000..7216f8d --- /dev/null +++ b/test/values/in_app_message.json @@ -0,0 +1,153 @@ +[ + {}, + { + "id": "mock-id", + "name": "mock-name", + "frequency": "mock-frequency", + "variantId": 1, + "variantName": "mock-variantName" + }, + { + "id": "mock-id", + "name": "mock-name", + "frequency": "mock-frequency", + "variantId": 1, + "variantName": "mock-variantName", + "messageType": "mock-messageType" + }, + { + "id": "mock-id", + "name": "mock-name", + "frequency": "mock-frequency", + "variantId": 1, + "variantName": "mock-variantName", + "messageType": "mock-messageType", + "payload": "{\"mock-payload-param\":\"mock-payload-content\"}" + }, + { + "id": "mock-id", + "name": "mock-name", + "frequency": "mock-frequency", + "variantId": 1, + "variantName": "mock-variantName", + "messageType": "mock-messageType", + "payload": "{\"mock-payload-param\":\"mock-payload-content\"}", + "trigger": "{\"mock-trigger-param\":\"mock-trigger-content\"}" + }, + { + "id": "mock-id", + "name": "mock-name", + "frequency": "mock-frequency", + "variantId": 1, + "variantName": "mock-variantName", + "messageType": "mock-messageType", + "payload": "{\"mock-payload-param\":\"mock-payload-content\"}", + "trigger": "{\"mock-trigger-param\":\"mock-trigger-content\"}", + "dateFilter": "{\"mock-dateFilter-param\":\"mock-dateFilter-content\"}" + }, + { + "id": "mock-id", + "name": "mock-name", + "frequency": "mock-frequency", + "variantId": 1, + "variantName": "mock-variantName", + "messageType": "mock-messageType", + "payload": "{\"mock-payload-param\":\"mock-payload-content\"}", + "trigger": "{\"mock-trigger-param\":\"mock-trigger-content\"}", + "dateFilter": "{\"mock-dateFilter-param\":\"mock-dateFilter-content\"}", + "loadPriority": 1 + }, + { + "id": "mock-id", + "name": "mock-name", + "frequency": "mock-frequency", + "variantId": 1, + "variantName": "mock-variantName", + "messageType": "mock-messageType", + "payload": "{\"mock-payload-param\":\"mock-payload-content\"}", + "trigger": "{\"mock-trigger-param\":\"mock-trigger-content\"}", + "dateFilter": "{\"mock-dateFilter-param\":\"mock-dateFilter-content\"}", + "loadPriority": 1, + "loadDelay": 1000 + }, + { + "id": "mock-id", + "name": "mock-name", + "frequency": "mock-frequency", + "variantId": 1, + "variantName": "mock-variantName", + "messageType": "mock-messageType", + "payload": "{\"mock-payload-param\":\"mock-payload-content\"}", + "trigger": "{\"mock-trigger-param\":\"mock-trigger-content\"}", + "dateFilter": "{\"mock-dateFilter-param\":\"mock-dateFilter-content\"}", + "loadPriority": 1, + "loadDelay": 1000, + "closeTimeout": 2000 + }, + { + "id": "mock-id", + "name": "mock-name", + "frequency": "mock-frequency", + "variantId": 1, + "variantName": "mock-variantName", + "messageType": "mock-messageType", + "payload": "{\"mock-payload-param\":\"mock-payload-content\"}", + "trigger": "{\"mock-trigger-param\":\"mock-trigger-content\"}", + "dateFilter": "{\"mock-dateFilter-param\":\"mock-dateFilter-content\"}", + "loadPriority": 1, + "loadDelay": 1000, + "closeTimeout": 2000, + "payloadHtml": "mock-payloadHtml" + }, + { + "id": "mock-id", + "name": "mock-name", + "frequency": "mock-frequency", + "variantId": 1, + "variantName": "mock-variantName", + "messageType": "mock-messageType", + "payload": "{\"mock-payload-param\":\"mock-payload-content\"}", + "trigger": "{\"mock-trigger-param\":\"mock-trigger-content\"}", + "dateFilter": "{\"mock-dateFilter-param\":\"mock-dateFilter-content\"}", + "loadPriority": 1, + "loadDelay": 1000, + "closeTimeout": 2000, + "payloadHtml": "mock-payloadHtml", + "isHtml": true + }, + { + "id": "mock-id", + "name": "mock-name", + "frequency": "mock-frequency", + "variantId": 1, + "variantName": "mock-variantName", + "messageType": "mock-messageType", + "payload": "{\"mock-payload-param\":\"mock-payload-content\"}", + "trigger": "{\"mock-trigger-param\":\"mock-trigger-content\"}", + "dateFilter": "{\"mock-dateFilter-param\":\"mock-dateFilter-content\"}", + "loadPriority": 1, + "loadDelay": 1000, + "closeTimeout": 2000, + "payloadHtml": "mock-payloadHtml", + "isHtml": true, + "hasTrackingConsent": true + }, + { + "id": "mock-id", + "name": "mock-name", + "frequency": "mock-frequency", + "variantId": 1, + "variantName": "mock-variantName", + "messageType": "mock-messageType", + "payload": "{\"mock-payload-param\":\"mock-payload-content\"}", + "trigger": "{\"mock-trigger-param\":\"mock-trigger-content\"}", + "dateFilter": "{\"mock-dateFilter-param\":\"mock-dateFilter-content\"}", + "loadPriority": 1, + "loadDelay": 1000, + "closeTimeout": 2000, + "payloadHtml": "mock-payloadHtml", + "isHtml": true, + "hasTrackingConsent": true, + "consentCategoryTracking": "mock-consentCategoryTracking" + } +] \ No newline at end of file diff --git a/test/values/in_app_message_action.json b/test/values/in_app_message_action.json new file mode 100644 index 0000000..5ae20e4 --- /dev/null +++ b/test/values/in_app_message_action.json @@ -0,0 +1,49 @@ +[ + {}, + { + "message": { + "id": "mock-id", + "name": "mock-name", + "frequency": "mock-frequency", + "variantId": 1, + "variantName": "mock-variantName", + "messageType": "mock-messageType", + "payload": "{\"mock-payload-param\":\"mock-payload-content\"}", + "trigger": "{\"mock-trigger-param\":\"mock-trigger-content\"}", + "dateFilter": "{\"mock-dateFilter-param\":\"mock-dateFilter-content\"}", + "loadPriority": 1, + "loadDelay": 1000, + "closeTimeout": 2000, + "payloadHtml": "mock-payloadHtml", + "isHtml": true, + "hasTrackingConsent": true, + "consentCategoryTracking": "mock-consentCategoryTracking" + }, + "interaction": true + }, + { + "message": { + "id": "mock-id", + "name": "mock-name", + "frequency": "mock-frequency", + "variantId": 1, + "variantName": "mock-variantName", + "messageType": "mock-messageType", + "payload": "{\"mock-payload-param\":\"mock-payload-content\"}", + "trigger": "{\"mock-trigger-param\":\"mock-trigger-content\"}", + "dateFilter": "{\"mock-dateFilter-param\":\"mock-dateFilter-content\"}", + "loadPriority": 1, + "loadDelay": 1000, + "closeTimeout": 2000, + "payloadHtml": "mock-payloadHtml", + "isHtml": true, + "hasTrackingConsent": true, + "consentCategoryTracking": "mock-consentCategoryTracking" + }, + "interaction": true, + "button": { + "text": "button", + "url": "https://a.b.c" + } + } +] \ No newline at end of file diff --git a/test/values/in_app_message_button.json b/test/values/in_app_message_button.json new file mode 100644 index 0000000..61b3207 --- /dev/null +++ b/test/values/in_app_message_button.json @@ -0,0 +1,5 @@ +[ + {}, + {"text":"button"}, + {"text":"button","url":"https://a.b.c"} +] \ No newline at end of file