Skip to content

Commit

Permalink
Add an unit test for path parameters that contain query
Browse files Browse the repository at this point in the history
  • Loading branch information
crazytonyli committed Feb 20, 2024
1 parent 07d9070 commit ea9b951
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 @@ -103,6 +103,30 @@ class WordPressOrgRestApiTests: XCTestCase {
let api = WordPressOrgRestApi(site: .dotCom(siteID: 1001, bearerToken: "fakeToken"))
let _ = try await api.get(path: "/wp-block-editor/v1/settings", type: AnyResponse.self).get()
}

// 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 ea9b951

Please sign in to comment.