diff --git a/CHANGELOG.md b/CHANGELOG.md index 2180443..6dc5cb2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ Change Log ========== +### Version 7.1.0 +* Updated to the 7.1.x versions of the Android and iOS Marketing Cloud SDK. + ### Version 7.0.0 * Updated to the 7.0.x versions of the Android and iOS Marketing Cloud SDK. diff --git a/README.md b/README.md index a5bb140..02d97df 100644 --- a/README.md +++ b/README.md @@ -95,7 +95,7 @@ Follow [these instructions](./ios_push.md) to enable push for iOS. The current state of the pushEnabled flag in the native Marketing Cloud SDK. -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **See** - [Android Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/6.0/reference/com/salesforce/marketingcloud/messages/push/PushMessageManager.html#isPushEnabled()) @@ -113,7 +113,7 @@ SDK. ### MCCordovaPlugin.enablePush([successCallback], [errorCallback]) Enables push messaging in the native Marketing Cloud SDK. -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **See** - [Android Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/6.0/reference/com/salesforce/marketingcloud/messages/push/PushMessageManager.html#enablePush()) @@ -130,7 +130,7 @@ Enables push messaging in the native Marketing Cloud SDK. ### MCCordovaPlugin.disablePush([successCallback], [errorCallback]) Disables push messaging in the native Marketing Cloud SDK. -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **See** - [Android Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/6.0/reference/com/salesforce/marketingcloud/messages/push/PushMessageManager.html#disablePush()) @@ -148,7 +148,7 @@ Disables push messaging in the native Marketing Cloud SDK. Returns the token used by the Marketing Cloud to send push messages to the device. -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **See** - [Android Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/6.0/reference/com/salesforce/marketingcloud/messages/push/PushMessageManager.html#getPushToken()) @@ -166,7 +166,7 @@ the device. ### MCCordovaPlugin.getAttributes(successCallback, [errorCallback]) Returns the maps of attributes set in the registration. -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **See** - [Android Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/6.0/reference/com/salesforce/marketingcloud/registration/RegistrationManager.html#getAttributes()) @@ -184,7 +184,7 @@ Returns the maps of attributes set in the registration. ### MCCordovaPlugin.setAttribute(key, value, [successCallback], [errorCallback]) Sets the value of an attribute in the registration. -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **See** - [Android Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/6.0/reference/com/salesforce/marketingcloud/registration/RegistrationManager.Editor.html#setAttribute(java.lang.String,%20java.lang.String)) @@ -204,7 +204,7 @@ Sets the value of an attribute in the registration. ### MCCordovaPlugin.clearAttribute(key, [successCallback], [errorCallback]) Clears the value of an attribute in the registration. -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **See** - [Android Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/6.0/reference/com/salesforce/marketingcloud/registration/RegistrationManager.Editor.html#clearAttribute(java.lang.String)) @@ -221,7 +221,7 @@ Clears the value of an attribute in the registration. ### MCCordovaPlugin.addTag(tag, [successCallback], [errorCallback]) -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **See** - [Android Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/6.0/reference/com/salesforce/marketingcloud/registration/RegistrationManager.Editor.html#addTag(java.lang.String)) @@ -238,7 +238,7 @@ Clears the value of an attribute in the registration. ### MCCordovaPlugin.removeTag(tag, [successCallback], [errorCallback]) -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **See** - [Android Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/6.0/reference/com/salesforce/marketingcloud/registration/RegistrationManager.Editor.html#removeTag(java.lang.String)) @@ -257,7 +257,7 @@ Clears the value of an attribute in the registration. ### MCCordovaPlugin.getTags(successCallback, [errorCallback]) Returns the tags currently set on the device. -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **See** - [Android Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/6.0/reference/com/salesforce/marketingcloud/registration/RegistrationManager.html#getTags()) @@ -275,7 +275,7 @@ Returns the tags currently set on the device. ### MCCordovaPlugin.setContactKey(contactKey, [successCallback], [errorCallback]) Sets the contact key for the device's user. -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **See** - [Android Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/6.0/reference/com/salesforce/marketingcloud/registration/RegistrationManager.Editor.html#setContactKey(java.lang.String)) @@ -294,7 +294,7 @@ Sets the contact key for the device's user. ### MCCordovaPlugin.getContactKey(successCallback, [errorCallback]) Returns the contact key currently set on the device. -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **See** - [Android Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/6.0/reference/com/salesforce/marketingcloud/registration/RegistrationManager.html#getContactKey()) @@ -312,7 +312,7 @@ Returns the contact key currently set on the device. ### MCCordovaPlugin.enableVerboseLogging([successCallback], [errorCallback]) Enables verbose logging within the native Marketing Cloud SDK. -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **See** - [Android Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/6.0/reference/com/salesforce/marketingcloud/MarketingCloudSdk.html#setLogLevel(int)) @@ -329,7 +329,7 @@ Enables verbose logging within the native Marketing Cloud SDK. ### MCCordovaPlugin.disableVerboseLogging([successCallback], [errorCallback]) Disables verbose logging within the native Marketing Cloud SDK. -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **See** - [Android Docs](https://salesforce-marketingcloud.github.io/MarketingCloudSDK-Android/javadocs/6.0/reference/com/salesforce/marketingcloud/MarketingCloudSdk.html#setLogLevel(int)) @@ -344,7 +344,7 @@ Disables verbose logging within the native Marketing Cloud SDK. ### MCCordovaPlugin.setOnNotificationOpenedListener(notificationOpenedListener) -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **Since**: 6.1.0 | Param | Type | @@ -355,7 +355,7 @@ Disables verbose logging within the native Marketing Cloud SDK. ### MCCordovaPlugin.setOnUrlActionListener(urlActionListener) -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **Since**: 6.3.0 | Param | Type | @@ -370,7 +370,7 @@ Instructs the native SDK to log the SDK state to the native logging system (Logc Android and Xcode/Console.app for iOS). This content can help diagnose most issues within the SDK and will be requested by the Marketing Cloud support team. -**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: static method of [MCCordovaPlugin](#module_MCCordovaPlugin) **Since**: 6.3.1 | Param | Type | @@ -381,7 +381,7 @@ the SDK and will be requested by the Marketing Cloud support team. ### MCCordovaPlugin~notificationOpenedCallback : function -**Kind**: inner typedef of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: inner typedef of [MCCordovaPlugin](#module_MCCordovaPlugin) | Param | Type | Description | | --- | --- | --- | @@ -395,7 +395,7 @@ the SDK and will be requested by the Marketing Cloud support team. ### MCCordovaPlugin~urlActionCallback : function -**Kind**: inner typedef of [MCCordovaPlugin](#module_MCCordovaPlugin) +**Kind**: inner typedef of [MCCordovaPlugin](#module_MCCordovaPlugin) | Param | Type | Description | | --- | --- | --- | diff --git a/package.json b/package.json index 87919d5..3921e0e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-marketingcloudsdk", - "version": "7.0.0", + "version": "7.1.0", "description": "A Cordova Plugin to access the native Salesforce Marketing Cloud MobilePush SDKs", "author": "Salesforce Marketing Cloud", "license": "BSD-3-Clause", @@ -29,10 +29,10 @@ "gen-docs": "jsdoc2md --template \"jsdoc2md/TEMPLATE.md\" \"www/**/*.js\" --plugin \"dmd-plugin-cordova-plugin\" > README.md", "test": "npm run eslint", "eslint": "node node_modules/eslint/bin/eslint www && node node_modules/eslint/bin/eslint src", - "format": "clang-format -i -style=file src/android/MCCordovaPlugin.java src/android/MCInitProvider.java src/android/MCSdkConfig.java src/ios/AppDelegate+MCCordovaPlugin.h src/ios/AppDelegate+MCCordovaPlugin.m src/ios/MCCordovaPlugin.h src/ios/MCCordovaPlugin.m tests/ios/MCCordovaPluginLib/MCCordovaPluginLibTests/MCCordovaPluginLibTests.m www/MCCordovaPlugin.js" + "format": "clang-format -i -style=file src/android/MCCordovaPlugin.java src/android/MCInitProvider.java src/android/MCSdkConfig.java src/ios/AppDelegate+MCCordovaPlugin.h src/ios/AppDelegate+MCCordovaPlugin.m src/ios/MCCordovaPlugin.h src/ios/MCCordovaPlugin.m tests/ios/MCCordovaPluginLib/Tests/Tests.m www/MCCordovaPlugin.js" }, "devDependencies": { - "clang-format": "^1.2.4", + "clang-format": "^1.4.0", "dmd-plugin-cordova-plugin": "^0.1.0", "eslint": "^4.3.0", "eslint-config-semistandard": "^11.0.0", @@ -42,6 +42,6 @@ "eslint-plugin-promise": "^3.5.0", "eslint-plugin-standard": "^3.0.1", "husky": "^0.10.1", - "jsdoc-to-markdown": "^1.2.0" + "jsdoc-to-markdown": "^5.0.3" } } diff --git a/plugin.xml b/plugin.xml index bdbb601..2feb303 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - @@ -64,7 +64,7 @@ - + diff --git a/src/android/MCCordovaPlugin.java b/src/android/MCCordovaPlugin.java index aaf8028..82f00bb 100644 --- a/src/android/MCCordovaPlugin.java +++ b/src/android/MCCordovaPlugin.java @@ -28,16 +28,16 @@ import android.app.PendingIntent; import android.content.Context; import android.content.Intent; -import androidx.annotation.Nullable; -import androidx.annotation.NonNull; import android.util.Log; - +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.salesforce.marketingcloud.MCLogListener; import com.salesforce.marketingcloud.MarketingCloudSdk; import com.salesforce.marketingcloud.UrlHandler; import com.salesforce.marketingcloud.notifications.NotificationManager; import com.salesforce.marketingcloud.notifications.NotificationMessage; - +import java.util.Collection; +import java.util.Map; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaPlugin; @@ -47,9 +47,6 @@ import org.json.JSONException; import org.json.JSONObject; -import java.util.Collection; -import java.util.Map; - public class MCCordovaPlugin extends CordovaPlugin implements UrlHandler { static final String TAG = "~!MCCordova"; diff --git a/src/android/MCInitProvider.java b/src/android/MCInitProvider.java index fc959db..6610d29 100644 --- a/src/android/MCInitProvider.java +++ b/src/android/MCInitProvider.java @@ -30,8 +30,8 @@ import android.content.Context; import android.database.Cursor; import android.net.Uri; -import androidx.annotation.Nullable; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; import com.salesforce.marketingcloud.InitializationStatus; import com.salesforce.marketingcloud.MCLogListener; import com.salesforce.marketingcloud.MarketingCloudConfig; diff --git a/src/android/MCSdkConfig.java b/src/android/MCSdkConfig.java index b9eea18..6c8ddd0 100644 --- a/src/android/MCSdkConfig.java +++ b/src/android/MCSdkConfig.java @@ -25,21 +25,20 @@ */ package com.salesforce.marketingcloud.cordova; +import static com.salesforce.marketingcloud.cordova.MCCordovaPlugin.TAG; + import android.content.Context; import android.content.res.Resources; import android.content.res.XmlResourceParser; -import androidx.annotation.Nullable; import android.util.Log; +import androidx.annotation.Nullable; import com.google.firebase.FirebaseApp; import com.salesforce.marketingcloud.MarketingCloudConfig; import com.salesforce.marketingcloud.notifications.NotificationCustomizationOptions; -import org.xmlpull.v1.XmlPullParser; -import org.xmlpull.v1.XmlPullParserException; - import java.io.IOException; import java.util.Locale; - -import static com.salesforce.marketingcloud.cordova.MCCordovaPlugin.TAG; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; public class MCSdkConfig { private static final String CONFIG_PREFIX = "com.salesforce.marketingcloud."; diff --git a/src/android/build/marketingcloudsdk.gradle b/src/android/build/marketingcloudsdk.gradle index 3061a20..0a98e53 100644 --- a/src/android/build/marketingcloudsdk.gradle +++ b/src/android/build/marketingcloudsdk.gradle @@ -17,7 +17,7 @@ repositories { } dependencies { - implementation("com.salesforce.marketingcloud:marketingcloudsdk:7.0.+") + implementation("com.salesforce.marketingcloud:marketingcloudsdk:7.1.+") } ext.cdvPluginPostBuildExtras += { diff --git a/tests/ios/MCCordovaPluginLib/Tests/Tests.m b/tests/ios/MCCordovaPluginLib/Tests/Tests.m index 7f2c1f9..abb8301 100644 --- a/tests/ios/MCCordovaPluginLib/Tests/Tests.m +++ b/tests/ios/MCCordovaPluginLib/Tests/Tests.m @@ -42,13 +42,13 @@ @implementation Tests - (void)setUp { [super setUp]; - + _sdk = OCMClassMock([MarketingCloudSDK class]); OCMStub(ClassMethod([_sdk sharedInstance])).andReturn(_sdk); - + _plugin = [MCCordovaPlugin alloc]; [_plugin pluginInitialize]; - + _commandDelegate = OCMProtocolMock(@protocol(CDVCommandDelegate)); _plugin.commandDelegate = _commandDelegate; } @@ -65,17 +65,17 @@ - (void)testEnableVerboseLogging { callbackId:@"testCallback" className:@"MCCordovaPlugin" methodName:@"enableVerboseLogging"]; - + // WHEN [_plugin enableVerboseLogging:command]; - + // THEN OCMVerify([_sdk sfmc_setDebugLoggingEnabled:YES]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK; + }] + callbackId:@"testCallback"]); } - (void)testDisableVerboseLogging { @@ -84,39 +84,38 @@ - (void)testDisableVerboseLogging { callbackId:@"testCallback" className:@"MCCordovaPlugin" methodName:@"disableVerboseLogging"]; - + // WHEN [_plugin disableVerboseLogging:command]; - + // THEN OCMVerify([_sdk sfmc_setDebugLoggingEnabled:NO]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK; + }] + callbackId:@"testCallback"]); } --(void)testLogSdkState { - //GIVEN +- (void)testLogSdkState { + // GIVEN id command = [[CDVInvokedUrlCommand alloc] initWithArguments:@[] callbackId:@"testCallback" className:@"MCCordovaPlugin" methodName:@"logSdkState"]; - + // WHEN [_plugin logSdkState:command]; - + // THEN OCMVerify([_sdk sfmc_getSDKState]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK; + }] + callbackId:@"testCallback"]); } - - (void)testGetSystemToken { // GIVEN id command = [[CDVInvokedUrlCommand alloc] initWithArguments:@[] @@ -124,18 +123,18 @@ - (void)testGetSystemToken { className:@"MCCordovaPlugin" methodName:@"getSystemToken"]; OCMStub([_sdk sfmc_deviceToken]).andReturn(@"testSystemToken"); - + // WHEN [_plugin getSystemToken:command]; - + // THEN OCMVerify([_sdk sfmc_deviceToken]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK && - [result.message isEqualToString:@"testSystemToken"]; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK && + [result.message isEqualToString:@"testSystemToken"]; + }] + callbackId:@"testCallback"]); } - (void)testIsPushEnabled_NO { @@ -145,17 +144,17 @@ - (void)testIsPushEnabled_NO { className:@"MCCordovaPlugin" methodName:@"isPushEnabled"]; OCMStub([_sdk sfmc_pushEnabled]).andReturn(NO); - + // WHEN [_plugin isPushEnabled:command]; - + // THEN OCMVerify([_sdk sfmc_pushEnabled]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 0; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 0; + }] + callbackId:@"testCallback"]); } - (void)testIsPushEnabled_YES { @@ -165,17 +164,17 @@ - (void)testIsPushEnabled_YES { className:@"MCCordovaPlugin" methodName:@"isPushEnabled"]; OCMStub([_sdk sfmc_pushEnabled]).andReturn(YES); - + // WHEN [_plugin isPushEnabled:command]; - + // THEN OCMVerify([_sdk sfmc_pushEnabled]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 1; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 1; + }] + callbackId:@"testCallback"]); } - (void)testEnablePush { @@ -184,17 +183,17 @@ - (void)testEnablePush { callbackId:@"testCallback" className:@"MCCordovaPlugin" methodName:@"enablePush"]; - + // WHEN [_plugin enablePush:command]; - + // THEN OCMVerify([_sdk sfmc_setPushEnabled:YES]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK; + }] + callbackId:@"testCallback"]); } - (void)testDisablePush { @@ -203,17 +202,17 @@ - (void)testDisablePush { callbackId:@"testCallback" className:@"MCCordovaPlugin" methodName:@"disablePush"]; - + // WHEN [_plugin disablePush:command]; - + // THEN OCMVerify([_sdk sfmc_setPushEnabled:NO]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK; + }] + callbackId:@"testCallback"]); } - (void)testSetAttribute_success { @@ -223,17 +222,17 @@ - (void)testSetAttribute_success { className:@"MCCordovaPlugin" methodName:@"setAttribute"]; OCMStub([_sdk sfmc_setAttributeNamed:[OCMArg any] value:[OCMArg any]]).andReturn(YES); - + // WHEN [_plugin setAttribute:command]; - + // THEN OCMVerify([_sdk sfmc_setAttributeNamed:@"TestKey" value:@"TestValue"]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 1; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 1; + }] + callbackId:@"testCallback"]); } - (void)testSetAttribute_failed { @@ -243,17 +242,17 @@ - (void)testSetAttribute_failed { className:@"MCCordovaPlugin" methodName:@"setAttribute"]; OCMStub([_sdk sfmc_setAttributeNamed:[OCMArg any] value:[OCMArg any]]).andReturn(NO); - + // WHEN [_plugin setAttribute:command]; - + // THEN OCMVerify([_sdk sfmc_setAttributeNamed:@"TestKey" value:@"TestValue"]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 0; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 0; + }] + callbackId:@"testCallback"]); } - (void)testClearAttribute_success { @@ -263,17 +262,17 @@ - (void)testClearAttribute_success { className:@"MCCordovaPlugin" methodName:@"clearAttribute"]; OCMStub([_sdk sfmc_clearAttributeNamed:[OCMArg any]]).andReturn(YES); - + // WHEN [_plugin clearAttribute:command]; - + // THEN OCMVerify([_sdk sfmc_clearAttributeNamed:@"TestKey"]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 1; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 1; + }] + callbackId:@"testCallback"]); } - (void)testClearAttribute_failed { @@ -283,17 +282,17 @@ - (void)testClearAttribute_failed { className:@"MCCordovaPlugin" methodName:@"clearAttribute"]; OCMStub([_sdk sfmc_clearAttributeNamed:[OCMArg any]]).andReturn(NO); - + // WHEN [_plugin clearAttribute:command]; - + // THEN OCMVerify([_sdk sfmc_clearAttributeNamed:@"TestKey"]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 0; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 0; + }] + callbackId:@"testCallback"]); } - (void)testGetAttributes { @@ -303,19 +302,19 @@ - (void)testGetAttributes { className:@"MCCordovaPlugin" methodName:@"getAttributes"]; OCMStub([_sdk sfmc_attributes]).andReturn(@{@"TestKey" : @"TestVal"}); - + // WHEN [_plugin getAttributes:command]; - + // THEN OCMVerify([_sdk sfmc_attributes]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return - [result.status intValue] == CDVCommandStatus_OK && - [[(NSDictionary *)result.message valueForKey:@"TestKey"] isEqualToString:@"TestVal"]; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return + [result.status intValue] == CDVCommandStatus_OK && + [[(NSDictionary *)result.message valueForKey:@"TestKey"] isEqualToString:@"TestVal"]; + }] + callbackId:@"testCallback"]); } - (void)testGetAttributes_nil { @@ -325,18 +324,18 @@ - (void)testGetAttributes_nil { className:@"MCCordovaPlugin" methodName:@"getAttributes"]; OCMStub([_sdk sfmc_attributes]).andReturn(nil); - + // WHEN [_plugin getAttributes:command]; - + // THEN OCMVerify([_sdk sfmc_attributes]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK && result.message != nil && - [(NSDictionary *)result.message count] == 0; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK && result.message != nil && + [(NSDictionary *)result.message count] == 0; + }] + callbackId:@"testCallback"]); } - (void)testGetContactKey { @@ -346,18 +345,18 @@ - (void)testGetContactKey { className:@"MCCordovaPlugin" methodName:@"getContactKey"]; OCMStub([_sdk sfmc_contactKey]).andReturn(@"testContactKey"); - + // WHEN [_plugin getContactKey:command]; - + // THEN OCMVerify([_sdk sfmc_contactKey]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK && - [result.message isEqualToString:@"testContactKey"]; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK && + [result.message isEqualToString:@"testContactKey"]; + }] + callbackId:@"testCallback"]); } - (void)testSetContactKey_success { @@ -367,17 +366,17 @@ - (void)testSetContactKey_success { className:@"MCCordovaPlugin" methodName:@"setContactKey"]; OCMStub([_sdk sfmc_setContactKey:[OCMArg any]]).andReturn(YES); - + // WHEN [_plugin setContactKey:command]; - + // THEN OCMVerify([_sdk sfmc_setContactKey:@"testContactKey"]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 1; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 1; + }] + callbackId:@"testCallback"]); } - (void)testSetContactKey_failed { @@ -387,17 +386,17 @@ - (void)testSetContactKey_failed { className:@"MCCordovaPlugin" methodName:@"setContactKey"]; OCMStub([_sdk sfmc_setContactKey:[OCMArg any]]).andReturn(NO); - + // WHEN [_plugin setContactKey:command]; - + // THEN OCMVerify([_sdk sfmc_setContactKey:@"testContactKey"]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 0; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 0; + }] + callbackId:@"testCallback"]); } - (void)testAddTag_success { @@ -407,17 +406,17 @@ - (void)testAddTag_success { className:@"MCCordovaPlugin" methodName:@"addTag"]; OCMStub([_sdk sfmc_addTag:[OCMArg any]]).andReturn(YES); - + // WHEN [_plugin addTag:command]; - + // THEN OCMVerify([_sdk sfmc_addTag:@"testTag"]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 1; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 1; + }] + callbackId:@"testCallback"]); } - (void)testAddTag_failed { @@ -427,17 +426,17 @@ - (void)testAddTag_failed { className:@"MCCordovaPlugin" methodName:@"addTag"]; OCMStub([_sdk sfmc_addTag:[OCMArg any]]).andReturn(NO); - + // WHEN [_plugin addTag:command]; - + // THEN OCMVerify([_sdk sfmc_addTag:@"testTag"]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 0; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 0; + }] + callbackId:@"testCallback"]); } - (void)testRemoveTag_success { @@ -447,17 +446,17 @@ - (void)testRemoveTag_success { className:@"MCCordovaPlugin" methodName:@"removeTag"]; OCMStub([_sdk sfmc_removeTag:[OCMArg any]]).andReturn(YES); - + // WHEN [_plugin removeTag:command]; - + // THEN OCMVerify([_sdk sfmc_removeTag:@"testTag"]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 1; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 1; + }] + callbackId:@"testCallback"]); } - (void)testRemoveTag_failed { @@ -467,17 +466,17 @@ - (void)testRemoveTag_failed { className:@"MCCordovaPlugin" methodName:@"removeTag"]; OCMStub([_sdk sfmc_removeTag:[OCMArg any]]).andReturn(NO); - + // WHEN [_plugin removeTag:command]; - + // THEN OCMVerify([_sdk sfmc_removeTag:@"testTag"]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 0; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK && [result.message intValue] == 0; + }] + callbackId:@"testCallback"]); } - (void)testGetTags { @@ -488,20 +487,20 @@ - (void)testGetTags { methodName:@"getTags"]; NSArray *tags = @[ @"Tag1", @"Tag2" ]; OCMStub([_sdk sfmc_tags]).andReturn(tags); - + // WHEN [_plugin getTags:command]; - + // THEN OCMVerify([_sdk sfmc_tags]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - NSArray *resultTags = (NSArray *)result.message; - return [result.status intValue] == CDVCommandStatus_OK && resultTags != nil && - [[resultTags objectAtIndex:0] isEqualToString:@"Tag1"] && - [[resultTags objectAtIndex:1] isEqualToString:@"Tag2"]; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + NSArray *resultTags = (NSArray *)result.message; + return [result.status intValue] == CDVCommandStatus_OK && resultTags != nil && + [[resultTags objectAtIndex:0] isEqualToString:@"Tag1"] && + [[resultTags objectAtIndex:1] isEqualToString:@"Tag2"]; + }] + callbackId:@"testCallback"]); } - (void)testGetTags_nil { @@ -511,55 +510,55 @@ - (void)testGetTags_nil { className:@"MCCordovaPlugin" methodName:@"getTags"]; OCMStub([_sdk sfmc_tags]).andReturn(nil); - + // WHEN [_plugin getTags:command]; - + // THEN OCMVerify([_sdk sfmc_tags]); OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [result.status intValue] == CDVCommandStatus_OK && result.message != nil && - [(NSArray *)result.message count] == 0; - }] - callbackId:@"testCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [result.status intValue] == CDVCommandStatus_OK && result.message != nil && + [(NSArray *)result.message count] == 0; + }] + callbackId:@"testCallback"]); } - (void) -testNotificationReceived_beforeEventCallbackCalled_beforeSubscribeCalled_shouldBeDeliveredWhenSubscribed { + testNotificationReceived_beforeEventCallbackCalled_beforeSubscribeCalled_shouldBeDeliveredWhenSubscribed { // GIVEN [self sendTestNotification:@{@"aps" : @{}}]; [_plugin registerEventsChannel:[Tests eventCallbackCommand]]; - + // WHEN [_plugin subscribe:[Tests notificationOpenedSubscribeCommand]]; - + // THEN OCMVerify([_commandDelegate sendPluginResult:[OCMArg any] callbackId:@"eventCallback"]); } - (void) -testNotificationReceived_afterEventCallbackCalled_beforeSubscribeCalled_shouldBeDeliveredWhenSubscribed { + testNotificationReceived_afterEventCallbackCalled_beforeSubscribeCalled_shouldBeDeliveredWhenSubscribed { // GIVEN [_plugin registerEventsChannel:[Tests eventCallbackCommand]]; [self sendTestNotification:@{@"aps" : @{}}]; - + // WHEN [_plugin subscribe:[Tests notificationOpenedSubscribeCommand]]; - + // THEN OCMVerify([_commandDelegate sendPluginResult:[OCMArg any] callbackId:@"eventCallback"]); } - (void) -testNotificationReceived_afterEventCallbackCalled_afterSubscribeCalled_shouldBeDeliveredImmediately { + testNotificationReceived_afterEventCallbackCalled_afterSubscribeCalled_shouldBeDeliveredImmediately { // GIVEN [_plugin registerEventsChannel:[Tests eventCallbackCommand]]; [_plugin subscribe:[Tests notificationOpenedSubscribeCommand]]; - + // WHEN [self sendTestNotification:@{@"aps" : @{}}]; - + // THEN OCMVerify([_commandDelegate sendPluginResult:[OCMArg any] callbackId:@"eventCallback"]); } @@ -568,91 +567,91 @@ - (void)testNotificationReceived_OD_withAlertTitleSubTitle { // GIVEN [_plugin registerEventsChannel:[Tests eventCallbackCommand]]; [_plugin subscribe:[Tests notificationOpenedSubscribeCommand]]; - + NSDictionary *payload = @{ - @"_sid" : @"SFMC", - @"_m" : @"messageId", - @"_od" : @"http://salesforce.com", - @"aps" : @{ - @"alert" : @{ - @"body" : @"Alert Body", - @"title" : @"Alert Title", - @"subtitle" : @"Alert Subtitle" - } - } - }; - + @"_sid" : @"SFMC", + @"_m" : @"messageId", + @"_od" : @"http://salesforce.com", + @"aps" : @{ + @"alert" : @{ + @"body" : @"Alert Body", + @"title" : @"Alert Title", + @"subtitle" : @"Alert Subtitle" + } + } + }; + // WHEN [self sendTestNotification:payload]; - + // THEN OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [self validateResult:result forOpenedNotification:payload]; - }] - callbackId:@"eventCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [self validateResult:result forOpenedNotification:payload]; + }] + callbackId:@"eventCallback"]); } - (void)testNotificationReceived_CP_withAlert_old { // GIVEN [_plugin registerEventsChannel:[Tests eventCallbackCommand]]; [_plugin subscribe:[Tests notificationOpenedSubscribeCommand]]; - + NSDictionary *payload = @{ - @"_sid" : @"SFMC", - @"_m" : @"messageId", - @"_x" : @"http://salesforce.com", - @"aps" : @{@"alert" : @"Alert Body"} - }; - + @"_sid" : @"SFMC", + @"_m" : @"messageId", + @"_x" : @"http://salesforce.com", + @"aps" : @{@"alert" : @"Alert Body"} + }; + // WHEN [self sendTestNotification:payload]; - + // THEN OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [self validateResult:result forOpenedNotification:payload]; - }] - callbackId:@"eventCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [self validateResult:result forOpenedNotification:payload]; + }] + callbackId:@"eventCallback"]); } - (void)testNotificationReceived_noUrl_withAlertTitle { // GIVEN [_plugin registerEventsChannel:[Tests eventCallbackCommand]]; [_plugin subscribe:[Tests notificationOpenedSubscribeCommand]]; - + NSDictionary *payload = @{ - @"_sid" : @"SFMC", - @"_m" : @"messageId", - @"aps" : @{@"alert" : @{@"body" : @"Alert Body", @"title" : @"Alert Title"}} - }; - + @"_sid" : @"SFMC", + @"_m" : @"messageId", + @"aps" : @{@"alert" : @{@"body" : @"Alert Body", @"title" : @"Alert Title"}} + }; + // WHEN [self sendTestNotification:payload]; - + // THEN OCMVerify([_commandDelegate - sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { - return [self validateResult:result forOpenedNotification:payload]; - }] - callbackId:@"eventCallback"]); + sendPluginResult:[OCMArg checkWithBlock:^BOOL(CDVPluginResult *result) { + return [self validateResult:result forOpenedNotification:payload]; + }] + callbackId:@"eventCallback"]); } - (void)testNotificationReceived_silentPush_notSentToCordova { // GIVEN [_plugin registerEventsChannel:[Tests eventCallbackCommand]]; [_plugin subscribe:[Tests notificationOpenedSubscribeCommand]]; - + NSDictionary *payload = - @{@"_sid" : @"SFMC", @"_m" : @"messageId", @"aps" : @{@"content-available" : @1}}; - + @{@"_sid" : @"SFMC", @"_m" : @"messageId", @"aps" : @{@"content-available" : @1}}; + // Hack in failure when sendPluginResult it called. Couldn't seem to get OCMock's `reject` to // work... OCMStub([_commandDelegate sendPluginResult:[OCMArg any] callbackId:[OCMArg any]]) - .andDo(^(NSInvocation *invocation) { - XCTFail("sendPluginResult should not be called"); - }); - + .andDo(^(NSInvocation *invocation) { + XCTFail("sendPluginResult should not be called"); + }); + // WHEN [self sendTestNotification:payload]; } @@ -663,28 +662,28 @@ - (void)sendTestNotification:(NSDictionary *)notification { UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"NDY5NjoxMTQ6MA" content:content trigger:nil]; - + [[NSNotificationCenter defaultCenter] - postNotificationName:SFMCFoundationUNNotificationReceivedNotification - object:self - userInfo:@{ - @"SFMCFoundationUNNotificationReceivedNotificationKeyUNNotificationReques" - @"t" : request - }]; + postNotificationName:SFMCFoundationUNNotificationReceivedNotification + object:self + userInfo:@{ + @"SFMCFoundationUNNotificationReceivedNotificationKeyUNNotificationReques" + @"t" : request + }]; } - (BOOL)validateResult:(CDVPluginResult *)result - forOpenedNotification:(NSDictionary *)notification { + forOpenedNotification:(NSDictionary *)notification { XCTAssertEqual([result.status intValue], CDVCommandStatus_OK); XCTAssertTrue([result.message isKindOfClass:[NSDictionary class]]); XCTAssertTrue(result.keepCallback); - + NSDictionary *message = result.message; XCTAssertTrue([[message objectForKey:@"timeStamp"] isKindOfClass:[NSNumber class]]); XCTAssertEqualObjects([message objectForKey:@"type"], @"notificationOpened"); XCTAssertTrue([[message objectForKey:@"values"] isKindOfClass:[NSDictionary class]]); NSDictionary *values = [message objectForKey:@"values"]; - + NSSet *notificationKeys = [NSSet setWithArray:notification.allKeys]; Boolean hadUrl = false; for (id key in notificationKeys) { @@ -701,7 +700,7 @@ - (BOOL)validateResult:(CDVPluginResult *)result } else { XCTAssertEqualObjects([values objectForKey:@"alert"], [aps objectForKey:@"alert"]); } - + } else if ([key isEqualToString:@"_od"]) { XCTAssertEqualObjects([values objectForKey:@"url"], [notification objectForKey:key]); XCTAssertEqualObjects([values objectForKey:@"type"], @"openDirect"); @@ -714,7 +713,7 @@ - (BOOL)validateResult:(CDVPluginResult *)result XCTAssertEqualObjects([values objectForKey:key], [notification objectForKey:key]); } } - + if (!hadUrl) { XCTAssertNil([values objectForKey:@"url"]); XCTAssertEqualObjects([values objectForKey:@"type"], @"other");