diff --git a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m index 164ea0b7f..8dcb94bd2 100644 --- a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m +++ b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/FBSDKAppEvents.m @@ -991,6 +991,7 @@ - (void)fetchServerConfiguration:(FBSDKCodeBlock)callback } }]; } else { + [self.iapTransactionCache setNewCandidatesDate:[NSDate date]]; [self.iapDedupeProcessor disable]; [self.paymentObserver stopObservingTransactions]; [self.transactionObserver stopObserving]; diff --git a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPTransactionCache.swift b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPTransactionCache.swift index e2410c19a..2cfccfa87 100644 --- a/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPTransactionCache.swift +++ b/FBSDKCoreKit/FBSDKCoreKit/AppEvents/Internal/IAP/IAPTransactionCache.swift @@ -130,6 +130,7 @@ extension IAPTransactionCache: _IAPTransactionCaching { return } guard let newValue else { + dependencies.dataStore.fb_removeObject(forKey: IAPConstants.newCandidatesDateCacheKey) return } dependencies.dataStore.fb_setObject(newValue, forKey: IAPConstants.newCandidatesDateCacheKey) diff --git a/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/AppEventsTests.swift b/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/AppEventsTests.swift index f24469d2e..bb310ebfa 100644 --- a/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/AppEventsTests.swift +++ b/FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/AppEventsTests.swift @@ -152,7 +152,7 @@ final class AppEventsTests: XCTestCase { iapDedupeProcessor = nil resetTestHelpers() - + IAPTransactionCache.shared.reset() super.tearDown() } @@ -1797,6 +1797,7 @@ final class AppEventsTests: XCTestCase { } func testFetchingConfigurationStopPaymentObservingIfAutoLogAppEventsDisabled() { + let now = Date() settings.isAutoLogAppEventsEnabled = false let serverConfiguration = ServerConfigurationFixtures.configuration( withDictionary: ["implicitPurchaseLoggingEnabled": true] @@ -1820,6 +1821,11 @@ final class AppEventsTests: XCTestCase { transactionObserver.didStopObserving, "Fetching a configuration should stop transaction observing if auto log app events is disabled" ) + guard let newCandidatesDate = IAPTransactionCache.shared.newCandidatesDate else { + XCTFail("newCandidatesDate should have been set") + return + } + XCTAssertTrue(newCandidatesDate > now) } func testEnablingIAPDedupeShouldEnableIAPDedupe() { @@ -1883,6 +1889,7 @@ final class AppEventsTests: XCTestCase { } func testEnablingIAPDedupeShouldNotEnableIAPDedupeWhenImplicitPurchaseIsDiabled() { + let now = Date() settings.isAutoLogAppEventsEnabled = true let serverConfiguration = ServerConfigurationFixtures.configuration( withDictionary: ["implicitPurchaseLoggingEnabled": 0] @@ -1895,6 +1902,11 @@ final class AppEventsTests: XCTestCase { XCTAssertFalse(iapDedupeProcessor.enableWasCalled) XCTAssertTrue(iapDedupeProcessor.disableWasCalled) + guard let newCandidatesDate = IAPTransactionCache.shared.newCandidatesDate else { + XCTFail("newCandidatesDate should have been set") + return + } + XCTAssertTrue(newCandidatesDate > now) } func testFetchingConfigurationIncludingSKAdNetworkIfSKAdNetworkReportEnabled() {