Skip to content

Commit

Permalink
[Woo POS] [Variable Products] Add WC 9.7+ downloadable parameter to v…
Browse files Browse the repository at this point in the history
…ariations request (#14893)
  • Loading branch information
jaclync authored Jan 17, 2025
2 parents 54cb588 + 3969b45 commit 88e0a18
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Networking/Networking/Remote/ProductVariationsRemote.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public class ProductVariationsRemote: Remote, ProductVariationsRemoteProtocol {
let request = productVariationsRequest(for: siteID,
productID: parentProductID,
variationIDs: [],
downloadable: false,
context: nil,
pageNumber: pageNumber,
pageSize: POSConstants.variationsPerPage)
Expand All @@ -101,6 +102,7 @@ public class ProductVariationsRemote: Remote, ProductVariationsRemoteProtocol {
private func productVariationsRequest(for siteID: Int64,
productID: Int64,
variationIDs: [Int64],
downloadable: Bool? = nil,
context: String?,
pageNumber: Int,
pageSize: Int) -> JetpackRequest {
Expand All @@ -109,6 +111,7 @@ public class ProductVariationsRemote: Remote, ProductVariationsRemoteProtocol {
let parameters = [
ParameterKey.page: String(pageNumber),
ParameterKey.perPage: String(pageSize),
ParameterKey.downloadable: downloadable.map { String($0) },
ParameterKey.contextKey: context ?? Default.context,
ParameterKey.include: variationIDs.isEmpty ? nil: stringOfVariationIDs
]
Expand Down Expand Up @@ -332,6 +335,7 @@ public extension ProductVariationsRemote {
static let contextKey: String = "context"
static let image: String = "image"
static let include: String = "include"
static let downloadable: String = "downloadable"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,36 @@ final class ProductVariationsRemoteTests: XCTestCase {
// Then
XCTAssertTrue(result.isFailure)
}

// MARK: Parameter Tests

func test_loadVariationsForPointOfSale_sets_correct_parameters() async throws {
// Given
let remote = ProductVariationsRemote(network: network)

// When
_ = try? await remote.loadVariationsForPointOfSale(for: sampleSiteID, parentProductID: sampleProductID, pageNumber: 2)

// Then
let queryParametersDictionary = try XCTUnwrap(network.queryParametersDictionary)
XCTAssertEqual(queryParametersDictionary["downloadable"] as? String, String(false))
XCTAssertEqual(queryParametersDictionary["page"] as? String, "2")
XCTAssertEqual(queryParametersDictionary["per_page"] as? String, "25")
}

func test_loadAllProductVariations_sets_correct_parameters() async throws {
// Given
let remote = ProductVariationsRemote(network: network)

// When
remote.loadAllProductVariations(for: sampleSiteID, productID: sampleProductID, variationIDs: [], completion: { _, _ in })

// Then
let queryParametersDictionary = try XCTUnwrap(network.queryParametersDictionary)
XCTAssertNil(queryParametersDictionary["downloadable"] as? String)
XCTAssertEqual(queryParametersDictionary["page"] as? String, "1")
XCTAssertEqual(queryParametersDictionary["per_page"] as? String, "25")
}
}

private extension ProductVariationsRemoteTests {
Expand Down

0 comments on commit 88e0a18

Please sign in to comment.