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

Commit d67877f

Browse files
authored
Add an unit test for path parameters that contain query (#732)
2 parents 676fb99 + e3030fe commit d67877f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

WordPressKitTests/WordPressOrgRestApiTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,30 @@ class WordPressOrgRestApiTests: XCTestCase {
115115
let _ = await api.get(path: "/wp/v2/hello", type: AnyResponse.self)
116116
XCTAssertEqual(request?.url?.absoluteString, "http://localhost:8000/wp/v2/sites/1001/hello")
117117
}
118+
119+
// Gutenberg Editor in the WordPress app may call `WordPressOrgRestApi` with a 'path' parameter that contain path
120+
// and query. This unit test ensures WordPressKit doesn't break that feature.
121+
func testPathWithQuery() async {
122+
var request: URLRequest?
123+
stub(condition: { _ in true }, response: {
124+
request = $0
125+
return HTTPStubsResponse(error: URLError(.networkConnectionLost))
126+
})
127+
128+
let api = WordPressOrgRestApi(site: .dotCom(siteID: 1001, bearerToken: "fakeToken"))
129+
130+
let _ = await api.get(path: "/wp/v2/get-decodable?context=mobile", type: AnyResponse.self)
131+
XCTAssertEqual(request?.url?.absoluteString, "https://public-api.wordpress.com/wp/v2/sites/1001/get-decodable?context=mobile")
132+
133+
let _ = await api.post(path: "/wp/v2/post-decodable?context=mobile", type: AnyResponse.self)
134+
XCTAssertEqual(request?.url?.absoluteString, "https://public-api.wordpress.com/wp/v2/sites/1001/post-decodable?context=mobile")
135+
136+
let _ = await api.get(path: "/wp/v2/get-any-json?context=mobile")
137+
XCTAssertEqual(request?.url?.absoluteString, "https://public-api.wordpress.com/wp/v2/sites/1001/get-any-json?context=mobile")
138+
139+
let _ = await api.post(path: "/wp/v2/post-any-json?context=mobile")
140+
XCTAssertEqual(request?.url?.absoluteString, "https://public-api.wordpress.com/wp/v2/sites/1001/post-any-json?context=mobile")
141+
}
118142
}
119143

120144
extension WordPressOrgRestApi {

0 commit comments

Comments
 (0)