Skip to content

Commit

Permalink
Add unit tests to test reading from server-side flags
Browse files Browse the repository at this point in the history
Summary: Since we already have a bunch of test cases covering this case, this diff simply added a few cases for checking server-side values.

Differential Revision: D51152076

fbshipit-source-id: be70fcab3f2bb5c11deb0146d743dcfa262533af
  • Loading branch information
Tao Xu authored and facebook-github-bot committed Nov 15, 2023
1 parent 324571d commit 4de7da5
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions FBSDKCoreKit/FBSDKCoreKitTests/SettingsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,82 @@ final class SettingsTests: XCTestCase {
)
}

func testAutoLogAppEventsEnabledFromServer_1() {
// set true for the server-side overriden value
let migratedAutoLogValues = ["auto_log_app_events_enabled": NSNumber(true)]
serverConfigurationProvider.configs = ["migratedAutoLogValues": migratedAutoLogValues]
// set false in info.plist
bundle = TestBundle(infoDictionary: ["FacebookAutoLogAppEventsEnabled": false])
configureSettings()
XCTAssertTrue(
settings.isAutoLogAppEventsEnabled,
"Should favor the server-side overriden value over others"
)
}

func testAutoLogAppEventsEnabledFromServer_2() {
// set true for the server-side overriden value
let migratedAutoLogValues = ["auto_log_app_events_enabled": String("Some_Value")]
serverConfigurationProvider.configs = ["migratedAutoLogValues": migratedAutoLogValues]
configureSettings()
settings.isAutoLogAppEventsEnabled = true
XCTAssertTrue(
settings.isAutoLogAppEventsEnabled,
"Should favor the client-side value when type casting fails"
)
}

func testAutoLogAppEventsEnabledFromServerDefault() {
// set false for the server-side default value
let migratedAutoLogValues = ["auto_log_app_events_default": NSNumber(false)]
serverConfigurationProvider.configs = ["migratedAutoLogValues": migratedAutoLogValues]
configureSettings()
XCTAssertFalse(
settings.isAutoLogAppEventsEnabled,
"Should favor the server-side default value if there are no other values set"
)
}

func testAutoLogAppEventsEnabledFromLocal_1() {
// set true for the server-side default value
let migratedAutoLogValues = ["auto_log_app_events_default": NSNumber(true)]
serverConfigurationProvider.configs = ["migratedAutoLogValues": migratedAutoLogValues]
// set false in info.plist
bundle = TestBundle(infoDictionary: ["FacebookAutoLogAppEventsEnabled": false])
configureSettings()
XCTAssertFalse(
settings.isAutoLogAppEventsEnabled,
"Should favor the value in info.plist over the server-side default value"
)
}

func testAutoLogAppEventsEnabledFromLocal_2() {
// set true for the server-side overriden value
let migratedAutoLogValues = ["auto_log_app_events_default": NSNumber(true)]
serverConfigurationProvider.configs = ["migratedAutoLogValues": migratedAutoLogValues]
// set false in memory store
configureSettings()
settings.isAutoLogAppEventsEnabled = false
configureSettings()
XCTAssertFalse(
settings.isAutoLogAppEventsEnabled,
"Should favor the value in memory over the server-side default value"
)
}

func testAutoLogAppEventsEnabledFromLocal_3() {
// Set an empty dictionary for the server-side value
// Technically, this should not happen in production environment
serverConfigurationProvider.configs = ["migratedAutoLogValues": [:]]
// set false in user default
configureSettings()
settings.dataStore?.fb_setObject(false, forKey: "FacebookAutoLogAppEventsEnabled")
XCTAssertFalse(
settings.isAutoLogAppEventsEnabled,
"Should favor the value in user default over the server-side default value"
)
}

// MARK: - Advertiser Identifier Collection Enabled

func testFacebookAdvertiserIDCollectionEnabled() {
Expand Down

0 comments on commit 4de7da5

Please sign in to comment.