Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 7c01ab3

Browse files
committed
Add an unit test for changing API url
1 parent 31798ce commit 7c01ab3

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

WordPressKitTests/WordPressOrgRestApiTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,18 @@ class WordPressOrgRestApiTests: XCTestCase {
103103
let api = WordPressOrgRestApi(site: .dotCom(siteID: 1001, bearerToken: "fakeToken"))
104104
let _ = try await api.get(path: "/wp-block-editor/v1/settings", type: AnyResponse.self).get()
105105
}
106+
107+
func testSettingWPComAPIURL() async {
108+
var request: URLRequest?
109+
stub(condition: { _ in true }, response: {
110+
request = $0
111+
return HTTPStubsResponse(error: URLError(.networkConnectionLost))
112+
})
113+
114+
let api = WordPressOrgRestApi(dotComSiteID: 1001, bearerToken: "token", apiURL: URL(string: "http://localhost:8000")!)
115+
let _ = await api.get(path: "/wp/v2/hello", type: AnyResponse.self)
116+
XCTAssertEqual(request?.url?.absoluteString, "http://localhost:8000/wp/v2/sites/1001/hello")
117+
}
106118
}
107119

108120
extension WordPressOrgRestApi {

0 commit comments

Comments
 (0)