Skip to content

Commit

Permalink
Update test cases to make them pass when useURLsession is enabled
Browse files Browse the repository at this point in the history
The changes highligh one difference between the existing
Alamofire-backed API and the new URLSession-backed API: the error
returned by the new one has HTTP status code which doesn't exist in
the old API.

I think this is an acceptable change.
  • Loading branch information
crazytonyli committed Feb 5, 2024
1 parent b106549 commit 8829f1a
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions WordPressKitTests/WordPressOrgXMLRPCApiTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@ class WordPressOrgXMLRPCApiTests: XCTestCase {
// 403 is the 'faultCode' in the HTTP response xml.
XCTAssertEqual(error.code, 403)
XCTAssertNotNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyData as String])
XCTAssertNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyStatusCode as String])

if WordPressOrgXMLRPCApi.useURLSession {
XCTAssertNotNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyStatusCode as String])
} else {
XCTAssertNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyStatusCode as String])
}
}
)
wait(for: [expect], timeout: 0.3)
Expand All @@ -200,8 +205,14 @@ class WordPressOrgXMLRPCApiTests: XCTestCase {
XCTAssertEqual(error.domain, WPXMLRPCFaultErrorDomain)
// 403 is the 'faultCode' in the HTTP response xml.
XCTAssertEqual(error.code, 403)
XCTAssertNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyData as String])
XCTAssertNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyStatusCode as String])

if WordPressOrgXMLRPCApi.useURLSession {
XCTAssertNotNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyData as String])
XCTAssertNotNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyStatusCode as String])
} else {
XCTAssertNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyData as String])
XCTAssertNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyStatusCode as String])
}
}
)
wait(for: [expect], timeout: 0.3)
Expand Down Expand Up @@ -230,7 +241,12 @@ class WordPressOrgXMLRPCApiTests: XCTestCase {

XCTAssertEqual(error.domain, XMLParser.errorDomain)
XCTAssertNotNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyData as String])
XCTAssertNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyStatusCode as String])

if WordPressOrgXMLRPCApi.useURLSession {
XCTAssertNotNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyStatusCode as String])
} else {
XCTAssertNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyStatusCode as String])
}
}
)
wait(for: [expect], timeout: 0.3)
Expand All @@ -257,7 +273,12 @@ class WordPressOrgXMLRPCApiTests: XCTestCase {
XCTAssertEqual(error.domain, WPXMLRPCErrorDomain)
XCTAssertEqual(error.code, WPXMLRPCError.invalidInputError.rawValue)
XCTAssertNotNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyData as String])
XCTAssertNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyStatusCode as String])

if WordPressOrgXMLRPCApi.useURLSession {
XCTAssertNotNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyStatusCode as String])
} else {
XCTAssertNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyStatusCode as String])
}
}
)
wait(for: [expect], timeout: 0.3)
Expand Down

0 comments on commit 8829f1a

Please sign in to comment.