|
37 | 37 | #import "UnitTestCommonMethods.h" |
38 | 38 | #import "OneSignalUserDefaults.h" |
39 | 39 | #import "OneSignalCommonDefines.h" |
| 40 | +#import "OSInAppMessagingDefines.h" |
| 41 | +#import "OneSignalUserDefaults.h" |
| 42 | +#import "OSInAppMessage.h" |
| 43 | +#import "OSInAppMessagingHelpers.h" |
40 | 44 | #import "CommonAsserts.h" |
41 | 45 |
|
42 | 46 | @interface MigrationTests : XCTestCase |
@@ -237,4 +241,55 @@ - (void)testCachedUniqueOutcomeToCachedUniqueOutcomeMigration { |
237 | 241 | XCTAssertEqual([[OneSignal sdk_version_raw] intValue], sdkVersionAfterMigration); |
238 | 242 | } |
239 | 243 |
|
| 244 | +- (void)testIAMCachedEmptyDictionaryToCachedCodeableMigration { |
| 245 | + NSDictionary<NSString *, OSInAppMessage *>*emptyDict = [NSMutableDictionary new]; |
| 246 | + [OneSignalUserDefaults.initStandard saveDictionaryForKey:OS_IAM_REDISPLAY_DICTIONARY withValue:emptyDict]; |
| 247 | + |
| 248 | + [migrationController migrate]; |
| 249 | +} |
| 250 | + |
| 251 | +- (void)testIAMCachedDictionaryToCachedCodeableMigration { |
| 252 | + NSMutableDictionary <NSString *, OSInAppMessage *> *emptyDict = [NSMutableDictionary new]; |
| 253 | + |
| 254 | + [OneSignalUserDefaults.initStandard saveDictionaryForKey:OS_IAM_REDISPLAY_DICTIONARY withValue:emptyDict]; |
| 255 | + |
| 256 | + [migrationController migrate]; |
| 257 | + |
| 258 | + NSDictionary<NSString *, OSInAppMessage *>*retrievedDict = [OneSignalUserDefaults.initStandard |
| 259 | + getSavedCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY defaultValue:nil]; |
| 260 | + XCTAssertEqualObjects(emptyDict, retrievedDict); |
| 261 | +} |
| 262 | + |
| 263 | +- (void)testIAMCachedCodeableMigration { |
| 264 | + let limit = 5; |
| 265 | + let delay = 60; |
| 266 | + let message = [OSInAppMessageTestHelper testMessageWithRedisplayLimit:limit delay:@(delay)]; |
| 267 | + message.isDisplayedInSession = true; |
| 268 | + NSMutableDictionary <NSString *, OSInAppMessage *> *redisplayedInAppMessages = [NSMutableDictionary new]; |
| 269 | + [redisplayedInAppMessages setObject:message forKey:message.messageId]; |
| 270 | + |
| 271 | + [OneSignalUserDefaults.initStandard saveCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY withValue:redisplayedInAppMessages]; |
| 272 | + |
| 273 | + [migrationController migrate]; |
| 274 | + |
| 275 | + NSDictionary<NSString *, OSInAppMessage *>*retrievedDict = [OneSignalUserDefaults.initStandard |
| 276 | + getSavedCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY defaultValue:nil]; |
| 277 | + XCTAssertEqualObjects(redisplayedInAppMessages, retrievedDict); |
| 278 | +} |
| 279 | + |
| 280 | +- (void)testIAMNilCacheToNilMigration { |
| 281 | + |
| 282 | + [OneSignalUserDefaults.initStandard saveDictionaryForKey:OS_IAM_REDISPLAY_DICTIONARY withValue:nil]; |
| 283 | + |
| 284 | + [migrationController migrate]; |
| 285 | + |
| 286 | + NSDictionary<NSString *, OSInAppMessage *>*retrievedDict = [OneSignalUserDefaults.initStandard |
| 287 | + getSavedCodeableDataForKey:OS_IAM_REDISPLAY_DICTIONARY defaultValue:nil]; |
| 288 | + XCTAssertNil(retrievedDict); |
| 289 | +} |
| 290 | + |
| 291 | + |
| 292 | + |
| 293 | + |
| 294 | + |
240 | 295 | @end |
0 commit comments