Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Woo POS] [Variable Products] Add WC 9.7+ downloadable parameter to variations request #14893

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading