Skip to content

Commit

Permalink
Backfill Unit Tests - SuggestedEventsIndexer 1/n
Browse files Browse the repository at this point in the history
Summary: $title

Reviewed By: jamestouri

Differential Revision: D27823171

fbshipit-source-id: ce420403b3fed35dfb842cb8b7d651894d65d1e8
  • Loading branch information
joesus authored and facebook-github-bot committed Apr 20, 2021
1 parent 7336aaa commit 91b2aa8
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, readonly) id<FBSDKEventLogging> eventLogger;
@property (nonatomic, readonly) Class<FBSDKFeatureExtracting> featureExtractor;
@property (nullable, nonatomic, weak) id<FBSDKEventProcessing> eventProcessor;
@property (nonatomic, readonly) NSSet<NSString *> *optInEvents;
@property (nonatomic, readonly) NSSet<NSString *> *unconfirmedEvents;

- (instancetype)initWithGraphRequestProvider:(id<FBSDKGraphRequestProviding>)requestProvider
serverConfigurationProvider:(Class<FBSDKServerConfigurationProviding>)serverConfigurationProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ class SuggestedEventsIndexerTests: XCTestCase {
var eventProcessor: EventProcessing? = TestEventProcessor()
var indexer: SuggestedEventsIndexer! // swiftlint:disable:this implicitly_unwrapped_optional

enum Keys {
static let productionEvents = "production_events"
static let predictionEvents = "eligible_for_prediction_events"
static let setting = "suggestedEventsSetting"
}

enum Values {
static let productionEvents = ["foo", "bar", "baz"]
static let predictionEvents = productionEvents.map { return $0 + "1" }
}

override func setUp() {
super.setUp()

Expand Down Expand Up @@ -129,4 +140,82 @@ class SuggestedEventsIndexerTests: XCTestCase {
"Enabling should load a server configuration"
)
}

func testCompletingEnablingWithErrorOnly() {
indexer.enable()

TestServerConfigurationProvider.capturedCompletionBlock?(nil, SampleError())

XCTAssertTrue(
indexer.optInEvents.isEmpty,
"Should not set events if there is an error fetching the server configuration"
)
XCTAssertTrue(
indexer.unconfirmedEvents.isEmpty,
"Should not set events if there is an error fetching the server configuration"
)
}

func testCompletingEnablingWithEmptySuggestedEventsSetting() {
indexer.enable()

TestServerConfigurationProvider.capturedCompletionBlock?(
ServerConfigurationFixtures.defaultConfig(),
nil
)

XCTAssertTrue(
indexer.optInEvents.isEmpty,
"Should not set events if there is no suggested events setting in the server configuration"
)
XCTAssertTrue(
indexer.unconfirmedEvents.isEmpty,
"Should not set events if there is no suggested events setting in the server configuration"
)
}

func testCompletingEnablingWithSuggestedEventsSettingAndError() {
indexer.enable()

TestServerConfigurationProvider.capturedCompletionBlock?(
ServerConfigurationFixtures.config(with: validSetting),
SampleError()
)

XCTAssertTrue(
indexer.optInEvents.isEmpty,
"Should not set events if there is an error fetching the server configuration"
)
XCTAssertTrue(
indexer.unconfirmedEvents.isEmpty,
"Should not set events if there is an error fetching the server configuration"
)
}

func testCompletingEnablingWithNonRepeatingSuggestedEventsSetting() {
indexer.enable()

TestServerConfigurationProvider.capturedCompletionBlock?(
ServerConfigurationFixtures.config(with: validSetting),
nil
)

XCTAssertEqual(
indexer.optInEvents,
Set(Values.productionEvents),
"Should set up suggested events successfully"
)
XCTAssertEqual(
indexer.unconfirmedEvents,
Set(Values.predictionEvents),
"Should set up suggested events successfully"
)
}

let validSetting: [String: Any] = [
Keys.setting: [
Keys.productionEvents: Values.productionEvents,
Keys.predictionEvents: Values.predictionEvents
]
]
}

0 comments on commit 91b2aa8

Please sign in to comment.