Skip to content

Commit b9d1b0f

Browse files
committed
Update tests
1 parent ff02083 commit b9d1b0f

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

Modules/Tests/NetworkingTests/Remote/ProductsRemoteTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ final class ProductsRemoteTests: XCTestCase {
458458
// When
459459
let products = try await remote.searchProducts(for: sampleSiteID,
460460
keyword: "photo",
461+
searchFields: [],
461462
pageNumber: 0,
462463
pageSize: 100)
463464

@@ -475,6 +476,7 @@ final class ProductsRemoteTests: XCTestCase {
475476
do {
476477
_ = try await remote.searchProducts(for: sampleSiteID,
477478
keyword: String(),
479+
searchFields: [],
478480
pageNumber: 0,
479481
pageSize: 100)
480482
XCTFail("Expected error to be thrown")
@@ -483,6 +485,26 @@ final class ProductsRemoteTests: XCTestCase {
483485
}
484486
}
485487

488+
/// Verifies that searchProducts with name search field includes the search_fields param in network request.
489+
///
490+
func test_searchProducts_with_name_search_field_includes_search_fields_param_in_network_request() async throws {
491+
// Given
492+
let remote = ProductsRemote(network: network)
493+
network.simulateResponse(requestUrlSuffix: "products", filename: "products-search-photo")
494+
495+
// When
496+
_ = try await remote.searchProducts(for: sampleSiteID,
497+
keyword: "test",
498+
searchFields: [.name],
499+
pageNumber: 0,
500+
pageSize: 100)
501+
502+
// Then
503+
let queryParameters = try XCTUnwrap(network.queryParameters)
504+
let expectedParam = "search_fields=[\"name\"]"
505+
XCTAssertTrue(queryParameters.contains(expectedParam), "Expected to have param: \(expectedParam)")
506+
}
507+
486508
// MARK: - Search Products by SKU
487509

488510
func test_searchProductsBySKU_properly_returns_parsed_products() async throws {

Modules/Tests/YosemiteTests/Mocks/Networking/Remote/MockProductsRemote.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ extension MockProductsRemote: ProductsRemoteProtocol {
286286

287287
func searchProducts(for siteID: Int64,
288288
keyword: String,
289+
searchFields: [ProductSearchField],
289290
pageNumber: Int,
290291
pageSize: Int,
291292
stockStatus: ProductStockStatus?,

0 commit comments

Comments
 (0)