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

Commit 8e16282

Browse files
committed
Add tests for mime_type setting behavior in media lib count API
1 parent 94ff212 commit 8e16282

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

WordPressKitTests/MediaServiceRemoteRESTTests.swift

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,39 @@ class MediaServiceRemoteRESTTests: RemoteTestCase, RESTTestable {
214214
XCTAssertEqual(mockRemoteApi.URLStringPassedIn, expectedPath, "Wrong path")
215215
}
216216

217-
func testGetMediaLibraryCount() {
218-
217+
func testGetMediaLibraryCountNoType() throws {
219218
let expectedCount = 3
220219
let response = ["found": expectedCount]
220+
221221
var remoteCount = 0
222222
mediaServiceRemote.getMediaLibraryCount(forType: nil, withSuccess: { (count) in
223223
remoteCount = count
224224
}, failure: nil)
225+
// Note: This needs to be called here, after triggerting the API request, or it won't take effect
226+
// The behavior seems odd and ought to be researched.
227+
mockRemoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse())
228+
229+
XCTAssertEqual(remoteCount, expectedCount)
230+
let params = try XCTUnwrap(mockRemoteApi.parametersPassedIn as? [String: Any])
231+
XCTAssertNil(params["mime_type"] as? String)
232+
}
233+
234+
func testGetMediaLibraryCountWithType() throws {
235+
let expectedCount = 3
236+
let response = ["found": expectedCount]
237+
238+
var remoteCount = 0
239+
mediaServiceRemote.getMediaLibraryCount(forType: "a_type", withSuccess: { (count) in
240+
remoteCount = count
241+
}, failure: nil)
242+
// Note: This needs to be called here, after triggerting the API request, or it won't take effect.
243+
// The behavior seems odd and ought to be researched.
225244
mockRemoteApi.successBlockPassedIn?(response as AnyObject, HTTPURLResponse())
245+
226246
XCTAssertEqual(remoteCount, expectedCount)
247+
let params = try XCTUnwrap(mockRemoteApi.parametersPassedIn as? [String: Any])
248+
let type = try XCTUnwrap(params["mime_type"] as? String)
249+
XCTAssertEqual(type, "a_type")
227250
}
228251

229252
func testRemoteMediaJSONParsing() {

0 commit comments

Comments
 (0)