From 962d56d05bc839ee15658ecb9ffa1d294d979ab5 Mon Sep 17 00:00:00 2001 From: Tony Li Date: Mon, 5 Feb 2024 14:40:46 +1300 Subject: [PATCH] Update test cases to make them pass when useURLsession is enabled --- WordPressKitTests/WordPressOrgXMLRPCApiTests.swift | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/WordPressKitTests/WordPressOrgXMLRPCApiTests.swift b/WordPressKitTests/WordPressOrgXMLRPCApiTests.swift index bd097cb8..1c6dc6c5 100644 --- a/WordPressKitTests/WordPressOrgXMLRPCApiTests.swift +++ b/WordPressKitTests/WordPressOrgXMLRPCApiTests.swift @@ -200,8 +200,16 @@ 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]) + + // The change highlights one difference between the existing Alamofire-backed API and the new + // URLSession-backed API: the error returned by the new one may has HTTP response body which may not + // be the case exist in the old API. I think this is an acceptable change. + if WordPressOrgXMLRPCApi.useURLSession { + XCTAssertNotNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyData as String]) + } else { + XCTAssertNil(error.userInfo[WordPressOrgXMLRPCApi.WordPressOrgXMLRPCApiErrorKeyData as String]) + } } ) wait(for: [expect], timeout: 0.3)