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

Commit b4e53b6

Browse files
committed
Add a couple of unit tests for PluginDirectoryServiceRemote
1 parent a69bb60 commit b4e53b6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

WordPressKitTests/PluginDirectoryTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import XCTest
2+
import OHHTTPStubs
23
@testable import WordPressKit
34

45
class PluginDirectoryTests: XCTestCase {
@@ -51,6 +52,26 @@ class PluginDirectoryTests: XCTestCase {
5152
}
5253
}
5354

55+
func testGetPluginInformation() async throws {
56+
let data = try MockPluginDirectoryProvider.getPluginDirectoryMockData(with: "plugin-directory-rename-xml-rpc", sender: type(of: self))
57+
stub(condition: isHost("api.wordpress.org")) { _ in
58+
HTTPStubsResponse(data: data, statusCode: 200, headers: ["Content-Type": "application/json"])
59+
}
60+
61+
let plugin = try await PluginDirectoryServiceRemote().getPluginInformation(slug: "rename-xml-rpc")
62+
XCTAssertEqual(plugin.name, "Rename XMLRPC")
63+
}
64+
65+
func testGetDirectoryFeed() async throws {
66+
let data = try MockPluginDirectoryProvider.getPluginDirectoryMockData(with: "plugin-directory-popular", sender: type(of: self))
67+
stub(condition: isHost("api.wordpress.org")) { _ in
68+
HTTPStubsResponse(data: data, statusCode: 200, headers: ["Content-Type": "application/json"])
69+
}
70+
71+
let feed = try await PluginDirectoryServiceRemote().getPluginFeed(.popular)
72+
XCTAssertEqual(feed.plugins.first?.name, "Contact Form 7")
73+
}
74+
5475
func testValidateResponseFound() {
5576
let data = try! MockPluginDirectoryProvider.getPluginDirectoryMockData(with: "plugin-directory-rename-xml-rpc", sender: type(of: self))
5677
let endpoint = PluginDirectoryGetInformationEndpoint(slug: "jetpack")

0 commit comments

Comments
 (0)