Skip to content

Commit

Permalink
Add an unit test for path parameters that contain query (#732)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazytonyli authored Feb 21, 2024
2 parents 676fb99 + e3030fe commit d67877f
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions WordPressKitTests/WordPressOrgRestApiTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,30 @@ class WordPressOrgRestApiTests: XCTestCase {
let _ = await api.get(path: "/wp/v2/hello", type: AnyResponse.self)
XCTAssertEqual(request?.url?.absoluteString, "http://localhost:8000/wp/v2/sites/1001/hello")
}

// Gutenberg Editor in the WordPress app may call `WordPressOrgRestApi` with a 'path' parameter that contain path
// and query. This unit test ensures WordPressKit doesn't break that feature.
func testPathWithQuery() async {
var request: URLRequest?
stub(condition: { _ in true }, response: {
request = $0
return HTTPStubsResponse(error: URLError(.networkConnectionLost))
})

let api = WordPressOrgRestApi(site: .dotCom(siteID: 1001, bearerToken: "fakeToken"))

let _ = await api.get(path: "/wp/v2/get-decodable?context=mobile", type: AnyResponse.self)
XCTAssertEqual(request?.url?.absoluteString, "https://public-api.wordpress.com/wp/v2/sites/1001/get-decodable?context=mobile")

let _ = await api.post(path: "/wp/v2/post-decodable?context=mobile", type: AnyResponse.self)
XCTAssertEqual(request?.url?.absoluteString, "https://public-api.wordpress.com/wp/v2/sites/1001/post-decodable?context=mobile")

let _ = await api.get(path: "/wp/v2/get-any-json?context=mobile")
XCTAssertEqual(request?.url?.absoluteString, "https://public-api.wordpress.com/wp/v2/sites/1001/get-any-json?context=mobile")

let _ = await api.post(path: "/wp/v2/post-any-json?context=mobile")
XCTAssertEqual(request?.url?.absoluteString, "https://public-api.wordpress.com/wp/v2/sites/1001/post-any-json?context=mobile")
}
}

extension WordPressOrgRestApi {
Expand Down

0 comments on commit d67877f

Please sign in to comment.