Skip to content

Commit 91b2aa8

Browse files
joesusfacebook-github-bot
authored andcommitted
Backfill Unit Tests - SuggestedEventsIndexer 1/n
Summary: $title Reviewed By: jamestouri Differential Revision: D27823171 fbshipit-source-id: ce420403b3fed35dfb842cb8b7d651894d65d1e8
1 parent 7336aaa commit 91b2aa8

2 files changed

Lines changed: 91 additions & 0 deletions

File tree

FBSDKCoreKit/FBSDKCoreKitTests/Interfaces/SuggestedEventsIndexer+Testing.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ NS_ASSUME_NONNULL_BEGIN
3333
@property (nonatomic, readonly) id<FBSDKEventLogging> eventLogger;
3434
@property (nonatomic, readonly) Class<FBSDKFeatureExtracting> featureExtractor;
3535
@property (nullable, nonatomic, weak) id<FBSDKEventProcessing> eventProcessor;
36+
@property (nonatomic, readonly) NSSet<NSString *> *optInEvents;
37+
@property (nonatomic, readonly) NSSet<NSString *> *unconfirmedEvents;
3638

3739
- (instancetype)initWithGraphRequestProvider:(id<FBSDKGraphRequestProviding>)requestProvider
3840
serverConfigurationProvider:(Class<FBSDKServerConfigurationProviding>)serverConfigurationProvider

FBSDKCoreKit/FBSDKCoreKitTests/Internal/AppEvents/SuggestedEventsIndexerTests.swift

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ class SuggestedEventsIndexerTests: XCTestCase {
2626
var eventProcessor: EventProcessing? = TestEventProcessor()
2727
var indexer: SuggestedEventsIndexer! // swiftlint:disable:this implicitly_unwrapped_optional
2828

29+
enum Keys {
30+
static let productionEvents = "production_events"
31+
static let predictionEvents = "eligible_for_prediction_events"
32+
static let setting = "suggestedEventsSetting"
33+
}
34+
35+
enum Values {
36+
static let productionEvents = ["foo", "bar", "baz"]
37+
static let predictionEvents = productionEvents.map { return $0 + "1" }
38+
}
39+
2940
override func setUp() {
3041
super.setUp()
3142

@@ -129,4 +140,82 @@ class SuggestedEventsIndexerTests: XCTestCase {
129140
"Enabling should load a server configuration"
130141
)
131142
}
143+
144+
func testCompletingEnablingWithErrorOnly() {
145+
indexer.enable()
146+
147+
TestServerConfigurationProvider.capturedCompletionBlock?(nil, SampleError())
148+
149+
XCTAssertTrue(
150+
indexer.optInEvents.isEmpty,
151+
"Should not set events if there is an error fetching the server configuration"
152+
)
153+
XCTAssertTrue(
154+
indexer.unconfirmedEvents.isEmpty,
155+
"Should not set events if there is an error fetching the server configuration"
156+
)
157+
}
158+
159+
func testCompletingEnablingWithEmptySuggestedEventsSetting() {
160+
indexer.enable()
161+
162+
TestServerConfigurationProvider.capturedCompletionBlock?(
163+
ServerConfigurationFixtures.defaultConfig(),
164+
nil
165+
)
166+
167+
XCTAssertTrue(
168+
indexer.optInEvents.isEmpty,
169+
"Should not set events if there is no suggested events setting in the server configuration"
170+
)
171+
XCTAssertTrue(
172+
indexer.unconfirmedEvents.isEmpty,
173+
"Should not set events if there is no suggested events setting in the server configuration"
174+
)
175+
}
176+
177+
func testCompletingEnablingWithSuggestedEventsSettingAndError() {
178+
indexer.enable()
179+
180+
TestServerConfigurationProvider.capturedCompletionBlock?(
181+
ServerConfigurationFixtures.config(with: validSetting),
182+
SampleError()
183+
)
184+
185+
XCTAssertTrue(
186+
indexer.optInEvents.isEmpty,
187+
"Should not set events if there is an error fetching the server configuration"
188+
)
189+
XCTAssertTrue(
190+
indexer.unconfirmedEvents.isEmpty,
191+
"Should not set events if there is an error fetching the server configuration"
192+
)
193+
}
194+
195+
func testCompletingEnablingWithNonRepeatingSuggestedEventsSetting() {
196+
indexer.enable()
197+
198+
TestServerConfigurationProvider.capturedCompletionBlock?(
199+
ServerConfigurationFixtures.config(with: validSetting),
200+
nil
201+
)
202+
203+
XCTAssertEqual(
204+
indexer.optInEvents,
205+
Set(Values.productionEvents),
206+
"Should set up suggested events successfully"
207+
)
208+
XCTAssertEqual(
209+
indexer.unconfirmedEvents,
210+
Set(Values.predictionEvents),
211+
"Should set up suggested events successfully"
212+
)
213+
}
214+
215+
let validSetting: [String: Any] = [
216+
Keys.setting: [
217+
Keys.productionEvents: Values.productionEvents,
218+
Keys.predictionEvents: Values.predictionEvents
219+
]
220+
]
132221
}

0 commit comments

Comments
 (0)