Skip to content

Commit

Permalink
Clean up and simplify testing use of graph requests and their creation
Browse files Browse the repository at this point in the history
Reviewed By: josueBrizuelaXD

Differential Revision: D39833084

fbshipit-source-id: d838b2ad032e97d11f55eed9001e2613a0edfa14
  • Loading branch information
samodom authored and facebook-github-bot committed Sep 28, 2022
1 parent 77ec522 commit d5d8c9a
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 195 deletions.
2 changes: 1 addition & 1 deletion FBSDKCoreKit/FBSDKCoreKitTests/AppLinkUtilityTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ final class AppLinkUtilityTests: XCTestCase {
appEventsConfigurationProvider.firstCapturedBlock?()

XCTAssertEqual(graphRequestFactory.capturedGraphPath, "(null)/activities")
XCTAssertEqual(graphRequestFactory.capturedHttpMethod, HTTPMethod(rawValue: "POST"))
XCTAssertEqual(graphRequestFactory.capturedHTTPMethod, .post)
}

func testValidatingConfiguration() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ final class GraphRequestConnectionTests: XCTestCase, GraphRequestConnectionDeleg
func testAddingRequestToBatchSetsMethod() {
let postRequest = TestGraphRequest(
graphPath: "me",
HTTPMethod: .post
httpMethod: .post
)
let metadata = GraphRequestMetadata(
request: postRequest,
Expand Down Expand Up @@ -1297,7 +1297,7 @@ final class GraphRequestConnectionTests: XCTestCase, GraphRequestConnectionDeleg
let parameters: [String: Any] = [
"first_key": "first_value",
]
let singleRequest = TestGraphRequest(graphPath: "activities", parameters: parameters, HTTPMethod: .post)
let singleRequest = TestGraphRequest(graphPath: "activities", parameters: parameters, httpMethod: .post)
connection.add(singleRequest) { _, _, _ in }
let requests = try XCTUnwrap(connection.requests as? [GraphRequestMetadata])
let request = connection.request(withBatch: requests, timeout: 0)
Expand Down Expand Up @@ -1325,7 +1325,7 @@ final class GraphRequestConnectionTests: XCTestCase, GraphRequestConnectionDeleg
graphPath: "me",
parameters: ["fields": ""],
tokenString: expectedToken,
HTTPMethod: .get,
httpMethod: .get,
flags: []
)
let token = connection.accessToken(with: request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ final class AppEventsConfigurationManagerTests: XCTestCase {
settings,
"Should be able to configure with custom settings"
)
XCTAssertEqual(
manager.graphRequestFactory as? TestGraphRequestFactory,
XCTAssertIdentical(
manager.graphRequestFactory as AnyObject,
graphRequestFactory,
"Should be able to configure with a custom graph request provider"
)
Expand Down Expand Up @@ -143,12 +143,11 @@ final class AppEventsConfigurationManagerTests: XCTestCase {
"Should not include a token string in the request"
)
XCTAssertNil(
graphRequestFactory.capturedHttpMethod,
graphRequestFactory.capturedHTTPMethod,
"Should not specify an http method when creating the request"
)
XCTAssertEqual(
XCTAssertNil(
graphRequestFactory.capturedFlags,
[],
"Should not specify flags when creating the request"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ final class AppEventsTests: XCTestCase {
"Should include the access token in the request when there is one available"
)
XCTAssertNil(
graphRequestFactory.capturedParameters["udid"],
graphRequestFactory.capturedParameters?["udid"],
"Should not include the udid in the request when there is none available"
)
}
Expand All @@ -994,7 +994,7 @@ final class AppEventsTests: XCTestCase {
"Should include the access token in the request when there is one available"
)
XCTAssertNil(
graphRequestFactory.capturedParameters["udid"],
graphRequestFactory.capturedParameters?["udid"],
"Should not include the udid in the request when there is an access token available"
)
XCTAssertEqual(
Expand All @@ -1003,7 +1003,7 @@ final class AppEventsTests: XCTestCase {
"Should use the expected graph path for the request"
)
XCTAssertEqual(
graphRequestFactory.capturedHttpMethod,
graphRequestFactory.capturedHTTPMethod,
.get,
"Should use the expected http method for the request"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ final class FBSDKAppEventsCAPIManagerTests: XCTestCase {
}

func testConfigure() {
XCTAssertEqual(
factory,
FBSDKAppEventsCAPIManager.shared.factory as? TestGraphRequestFactory,
XCTAssertIdentical(
factory as AnyObject,
FBSDKAppEventsCAPIManager.shared.factory,
"Should configure with the expected graph request factory"
)
XCTAssertEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ final class CodelessIndexerTests: XCTestCase {
}

func testConfiguringWithDependencies() {
XCTAssertEqual(
_CodelessIndexer.graphRequestFactory as? TestGraphRequestFactory,
XCTAssertIdentical(
_CodelessIndexer.graphRequestFactory as AnyObject,
graphRequestFactory,
"Should be able to configure with a request provider"
)
Expand Down Expand Up @@ -168,7 +168,7 @@ final class CodelessIndexerTests: XCTestCase {
"Should not include a token string in the request"
)
XCTAssertNil(
graphRequestFactory.capturedHttpMethod,
graphRequestFactory.capturedHTTPMethod,
"Should not specify an http method when creating the request"
)
XCTAssertEqual(
Expand Down Expand Up @@ -468,7 +468,7 @@ final class CodelessIndexerTests: XCTestCase {
"Should create a request with the expected graph path"
)
XCTAssertEqual(
graphRequestFactory.capturedHttpMethod,
graphRequestFactory.capturedHTTPMethod,
.post,
"Should create a request with the expected http method"
)
Expand All @@ -485,9 +485,8 @@ final class CodelessIndexerTests: XCTestCase {
],
"Should create a request with the expected parameters"
)
XCTAssertEqual(
XCTAssertNil(
graphRequestFactory.capturedFlags,
[],
"Should create a request with the expected flags"
)
}
Expand Down Expand Up @@ -595,7 +594,7 @@ final class CodelessIndexerTests: XCTestCase {
"Should request the session with the expected parameters"
)
XCTAssertEqual(
graphRequestFactory.capturedHttpMethod,
graphRequestFactory.capturedHTTPMethod,
.post,
"Should request the session with the expected http method"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ final class SuggestedEventsIndexerTests: XCTestCase, UITableViewDelegate, UIColl

let expectedMetadata = [Keys.dense: Values.denseFeature, Keys.buttonText: Values.buttonText]
guard
let parameter = graphRequestFactory.capturedParameters[Keys.metadata] as? String,
let parameter = graphRequestFactory.capturedParameters?[Keys.metadata] as? String,
let data = parameter.data(using: .utf8),
let decodedMetadata = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: String]
else {
Expand All @@ -301,7 +301,7 @@ final class SuggestedEventsIndexerTests: XCTestCase, UITableViewDelegate, UIColl
"Should use the app identifier from the settings"
)
XCTAssertEqual(
graphRequestFactory.capturedParameters[Keys.eventName] as? String,
graphRequestFactory.capturedParameters?[Keys.eventName] as? String,
name,
"Should capture the event name in the parameters"
)
Expand All @@ -315,12 +315,12 @@ final class SuggestedEventsIndexerTests: XCTestCase, UITableViewDelegate, UIColl
"The request should be tokenless"
)
XCTAssertEqual(
graphRequestFactory.capturedHttpMethod,
graphRequestFactory.capturedHTTPMethod,
.post,
"Should use the expected http method"
)
XCTAssertTrue(
graphRequestFactory.capturedFlags.isEmpty,
XCTAssertNil(
graphRequestFactory.capturedFlags,
"Should not create the request with explicit request flags"
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ final class ErrorReporterTests: XCTestCase {
reporter.uploadErrors()

guard
let reports = factory.capturedParameters["error_reports"] as? String,
let reports = factory.capturedParameters?["error_reports"] as? String,
let data = reports.data(using: .utf8)
else {
return XCTFail("Should upload reports as an array of strings")
Expand All @@ -242,7 +242,7 @@ final class ErrorReporterTests: XCTestCase {
"Should upload the expected reports"
)
XCTAssertEqual(
factory.capturedHttpMethod,
factory.capturedHTTPMethod,
.post,
"Should use the correct http method"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,14 +262,14 @@ final class GateKeeperManagerTests: XCTestCase {
"\(appIdentifier)/mobile_sdk_gk",
"Should use the app identifier from the settings"
)
XCTAssertEqual(graphRequestFactory.capturedParameters["platform"] as? String, "ios")
XCTAssertEqual(graphRequestFactory.capturedParameters?["platform"] as? String, "ios")
XCTAssertEqual(
graphRequestFactory.capturedParameters["sdk_version"] as? String,
graphRequestFactory.capturedParameters?["sdk_version"] as? String,
version,
"Should use the sdk version from the settings"
)
XCTAssertEqual(
graphRequestFactory.capturedParameters["fields"] as? String,
graphRequestFactory.capturedParameters?["fields"] as? String,
"gatekeepers",
"Should request the expected fields"
)
Expand All @@ -278,7 +278,7 @@ final class GateKeeperManagerTests: XCTestCase {
"The gate keepers request should be tokenless"
)
XCTAssertNil(
graphRequestFactory.capturedHttpMethod,
graphRequestFactory.capturedHTTPMethod,
"Should not provide an explicit http method"
)
XCTAssertEqual(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ final class CustomUpdateGraphRequestTests: XCTestCase {
}

func testCustomDependencies() {
XCTAssertEqual(
requester.graphRequestFactory as? TestGraphRequestFactory,
XCTAssertIdentical(
requester.graphRequestFactory as AnyObject,
factory,
"Should be able to create with a custom graph request factory"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ final class TournamentFetcherTests: XCTestCase {
}

func testCustomDependencies() {
XCTAssertEqual(
fetcher.graphRequestFactory as? TestGraphRequestFactory,
XCTAssertIdentical(
fetcher.graphRequestFactory as AnyObject,
factory,
"Should be able to create with a custom graph request factory"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ final class TournamentUpdaterTest: XCTestCase {
}

func testCustomDependencies() {
XCTAssertEqual(
updater.graphRequestFactory as? TestGraphRequestFactory,
XCTAssertIdentical(
updater.graphRequestFactory as AnyObject,
factory,
"Should be able to create with a custom graph request factory"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ final class VideoUploaderTests: XCTestCase, VideoUploaderDelegate {
graphRequestFactory.capturedGraphPath,
"me/videos"
)
XCTAssertNotNil(graphRequestFactory.capturedHttpMethod)
XCTAssertNotNil(graphRequestFactory.capturedHTTPMethod)
XCTAssertNil(
graphRequestFactory.capturedTokenString,
"Request Provider should not be initialized with a token string"
Expand Down
Loading

0 comments on commit d5d8c9a

Please sign in to comment.