in FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/AppEventsTests.swift [629:747]
func testUsingAppEventsWithUninitializedSDK() throws {
let foo = "foo"
appEvents = AppEvents(
flushBehavior: .explicitOnly,
flushPeriodInSeconds: 0
)
let exceptionRaisingClosures = [
{ self.appEvents.flushBehavior = .auto },
{ self.appEvents.loggingOverrideAppID = foo },
{ self.appEvents.logEvent(.searched) },
{ self.appEvents.logEvent(.searched, valueToSum: 2) },
{ self.appEvents.logEvent(.searched, parameters: [:]) },
{ self.appEvents.logEvent(.searched, valueToSum: 2, parameters: [:]) },
{
self.appEvents.logEvent(
.searched,
valueToSum: 2,
parameters: [:],
accessToken: SampleAccessTokens.validToken
)
},
{
self.appEvents.logPurchase(
amount: 2,
currency: foo,
parameters: [:]
)
},
{
self.appEvents.logPurchase(
amount: 2,
currency: foo,
parameters: [:],
accessToken: SampleAccessTokens.validToken
)
},
{ self.appEvents.logPushNotificationOpen(payload: [:]) },
{ self.appEvents.logPushNotificationOpen(payload: [:], action: foo) },
{
self.appEvents.logProductItem(
id: foo,
availability: .inStock,
condition: .new,
description: foo,
imageLink: foo,
link: foo,
title: foo,
priceAmount: 1,
currency: foo,
gtin: nil,
mpn: nil,
brand: nil,
parameters: [:]
)
},
{ self.appEvents.setPushNotificationsDeviceToken(Data()) },
{ self.appEvents.pushNotificationsDeviceTokenString = foo },
{ self.appEvents.flush() },
{ self.appEvents.requestForCustomAudienceThirdPartyID(accessToken: SampleAccessTokens.validToken) },
{ self.appEvents.augmentHybridWebView(WKWebView()) },
{ self.appEvents.sendEventBindingsToUnity() },
{ self.appEvents.activateApp() },
{ _ = self.appEvents.userID },
{ self.appEvents.userID = foo },
]
exceptionRaisingClosures.forEach { closure in
assertRaisesException(
message: "Interacting with AppEvents in some ways before initializing the SDK should raise an exception"
) {
closure()
}
}
let nonExceptionRaisingClosures = [
{ self.appEvents.setIsUnityInitialized(true) },
{ _ = self.appEvents.anonymousID },
{ self.appEvents.setUserData(foo, forType: .email) },
{
self.appEvents.setUser(
email: nil,
firstName: nil,
lastName: nil,
phone: nil,
dateOfBirth: nil,
gender: nil,
city: nil,
state: nil,
zip: nil,
country: nil
)
},
{ self.appEvents.getUserData() },
{ self.appEvents.clearUserData(forType: .email) },
]
// swiftlint:enable opening_brace
nonExceptionRaisingClosures.forEach { closure in
assertDoesNotRaiseException(
message: """
Interacting with AppEvents in certain ways before the SDK is initialized \
should not raise an exception
"""
) {
closure()
}
}
XCTAssertFalse(
timeSpentRecorder.restoreWasCalled,
"Activating App without initialized SDK cannot restore recording time spent data."
)
validateAEMReporterCalled(
eventName: nil,
currency: nil,
value: nil,
parameters: nil
)
}