Skip to content

Commit

Permalink
MBL-1316: Use isAvailable to filter visible add-ons (#2012)
Browse files Browse the repository at this point in the history
* MBL-1316: Show add-ons for late pledges

* MBL-1316: Add isAvailable to Reward (available from GraphQL)

* MBL-1316: Use isAvailable to filter visible add-ons

* update ksApi tests

* Fix RewardAddOnSelectionViewControllerTests

---------

Co-authored-by: Scott Clampet <110618242+scottkicks@users.noreply.github.com>
  • Loading branch information
amy-at-kickstarter and scottkicks committed Apr 2, 2024
1 parent 9cb264c commit 6fcf7ee
Show file tree
Hide file tree
Showing 13 changed files with 171 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ final class RewardAddOnSelectionViewControllerTests: TestCase {
let reward = Reward.template
|> Reward.lens.shipping.enabled .~ false
|> Reward.lens.localPickup .~ nil
|> Reward.lens.isAvailable .~ true

let noShippingAddOn = Reward.template
|> Reward.lens.shipping.enabled .~ false
|> Reward.lens.shipping.preference .~ Reward.Shipping.Preference.none
|> Reward.lens.localPickup .~ nil
|> Reward.lens.isAvailable .~ true

let project = Project.template
|> Project.lens.rewardData.rewards .~ [reward]
Expand Down Expand Up @@ -77,12 +79,14 @@ final class RewardAddOnSelectionViewControllerTests: TestCase {
|> Reward.lens.shipping.enabled .~ true
|> Reward.lens.shipping.preference .~ .unrestricted
|> Reward.lens.localPickup .~ nil
|> Reward.lens.isAvailable .~ true

let shippingAddOn = Reward.template
|> Reward.lens.shipping.enabled .~ true
|> Reward.lens.shipping.preference .~ .unrestricted
|> Reward.lens.shippingRulesExpanded .~ shippingRules
|> Reward.lens.localPickup .~ nil
|> Reward.lens.isAvailable .~ true

let project = Project.template
|> Project.lens.rewardData.rewards .~ [reward]
Expand Down Expand Up @@ -145,6 +149,7 @@ final class RewardAddOnSelectionViewControllerTests: TestCase {
|> Reward.lens.id .~ 99
|> Reward.lens.shippingRules .~ [shippingRule]
|> Reward.lens.localPickup .~ nil
|> Reward.lens.isAvailable .~ true

let shippingAddOn1 = Reward.template
|> Reward.lens.id .~ 2
Expand All @@ -153,6 +158,7 @@ final class RewardAddOnSelectionViewControllerTests: TestCase {
shippingRule |> ShippingRule.lens.location .~ (.template |> Location.lens.id .~ 99)
]
|> Reward.lens.localPickup .~ nil
|> Reward.lens.isAvailable .~ true

let shippingAddOn2 = Reward.template
|> Reward.lens.id .~ 3
Expand All @@ -161,6 +167,7 @@ final class RewardAddOnSelectionViewControllerTests: TestCase {
shippingRule |> ShippingRule.lens.location .~ (.template |> Location.lens.id .~ 99)
]
|> Reward.lens.localPickup .~ nil
|> Reward.lens.isAvailable .~ true

let shippingAddOn3 = Reward.template
|> Reward.lens.id .~ 4
Expand All @@ -169,6 +176,7 @@ final class RewardAddOnSelectionViewControllerTests: TestCase {
shippingRule |> ShippingRule.lens.location .~ (.template |> Location.lens.id .~ 3)
]
|> Reward.lens.localPickup .~ nil
|> Reward.lens.isAvailable .~ true

let shippingAddOn4 = Reward.template
|> Reward.lens.id .~ 5
Expand All @@ -177,6 +185,7 @@ final class RewardAddOnSelectionViewControllerTests: TestCase {
shippingRule |> ShippingRule.lens.location .~ (.template |> Location.lens.id .~ 3)
]
|> Reward.lens.localPickup .~ nil
|> Reward.lens.isAvailable .~ true

let project = Project.template
|> Project.lens.rewardData.rewards .~ [reward]
Expand Down Expand Up @@ -265,11 +274,13 @@ final class RewardAddOnSelectionViewControllerTests: TestCase {
|> Reward.lens.shipping.enabled .~ false
|> Reward.lens.localPickup .~ .australia
|> Reward.lens.shipping.preference .~ .local
|> Reward.lens.isAvailable .~ true

let noShippingAddOn = Reward.template
|> Reward.lens.shipping.enabled .~ false
|> Reward.lens.shipping.preference .~ .local
|> Reward.lens.localPickup .~ .australia
|> Reward.lens.isAvailable .~ true

let project = Project.template
|> Project.lens.rewardData.rewards .~ [reward]
Expand Down
16 changes: 14 additions & 2 deletions KsApi/GraphAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15520,6 +15520,7 @@ public enum GraphAPI {
estimatedDeliveryOn
id
isMaxPledge
available
items {
__typename
edges {
Expand Down Expand Up @@ -15570,6 +15571,7 @@ public enum GraphAPI {
GraphQLField("estimatedDeliveryOn", type: .scalar(String.self)),
GraphQLField("id", type: .nonNull(.scalar(GraphQLID.self))),
GraphQLField("isMaxPledge", type: .nonNull(.scalar(Bool.self))),
GraphQLField("available", type: .nonNull(.scalar(Bool.self))),
GraphQLField("items", type: .object(Item.selections)),
GraphQLField("limit", type: .scalar(Int.self)),
GraphQLField("limitPerBacker", type: .scalar(Int.self)),
Expand All @@ -15595,8 +15597,8 @@ public enum GraphAPI {
self.resultMap = unsafeResultMap
}

public init(amount: Amount, backersCount: Int? = nil, convertedAmount: ConvertedAmount, allowedAddons: AllowedAddon, description: String, displayName: String, endsAt: String? = nil, estimatedDeliveryOn: String? = nil, id: GraphQLID, isMaxPledge: Bool, items: Item? = nil, limit: Int? = nil, limitPerBacker: Int? = nil, localReceiptLocation: LocalReceiptLocation? = nil, name: String? = nil, postCampaignPledgingEnabled: Bool, project: Project? = nil, remainingQuantity: Int? = nil, shippingPreference: ShippingPreference? = nil, shippingSummary: String? = nil, shippingRules: [ShippingRule?]? = nil, startsAt: String? = nil) {
self.init(unsafeResultMap: ["__typename": "Reward", "amount": amount.resultMap, "backersCount": backersCount, "convertedAmount": convertedAmount.resultMap, "allowedAddons": allowedAddons.resultMap, "description": description, "displayName": displayName, "endsAt": endsAt, "estimatedDeliveryOn": estimatedDeliveryOn, "id": id, "isMaxPledge": isMaxPledge, "items": items.flatMap { (value: Item) -> ResultMap in value.resultMap }, "limit": limit, "limitPerBacker": limitPerBacker, "localReceiptLocation": localReceiptLocation.flatMap { (value: LocalReceiptLocation) -> ResultMap in value.resultMap }, "name": name, "postCampaignPledgingEnabled": postCampaignPledgingEnabled, "project": project.flatMap { (value: Project) -> ResultMap in value.resultMap }, "remainingQuantity": remainingQuantity, "shippingPreference": shippingPreference, "shippingSummary": shippingSummary, "shippingRules": shippingRules.flatMap { (value: [ShippingRule?]) -> [ResultMap?] in value.map { (value: ShippingRule?) -> ResultMap? in value.flatMap { (value: ShippingRule) -> ResultMap in value.resultMap } } }, "startsAt": startsAt])
public init(amount: Amount, backersCount: Int? = nil, convertedAmount: ConvertedAmount, allowedAddons: AllowedAddon, description: String, displayName: String, endsAt: String? = nil, estimatedDeliveryOn: String? = nil, id: GraphQLID, isMaxPledge: Bool, available: Bool, items: Item? = nil, limit: Int? = nil, limitPerBacker: Int? = nil, localReceiptLocation: LocalReceiptLocation? = nil, name: String? = nil, postCampaignPledgingEnabled: Bool, project: Project? = nil, remainingQuantity: Int? = nil, shippingPreference: ShippingPreference? = nil, shippingSummary: String? = nil, shippingRules: [ShippingRule?]? = nil, startsAt: String? = nil) {
self.init(unsafeResultMap: ["__typename": "Reward", "amount": amount.resultMap, "backersCount": backersCount, "convertedAmount": convertedAmount.resultMap, "allowedAddons": allowedAddons.resultMap, "description": description, "displayName": displayName, "endsAt": endsAt, "estimatedDeliveryOn": estimatedDeliveryOn, "id": id, "isMaxPledge": isMaxPledge, "available": available, "items": items.flatMap { (value: Item) -> ResultMap in value.resultMap }, "limit": limit, "limitPerBacker": limitPerBacker, "localReceiptLocation": localReceiptLocation.flatMap { (value: LocalReceiptLocation) -> ResultMap in value.resultMap }, "name": name, "postCampaignPledgingEnabled": postCampaignPledgingEnabled, "project": project.flatMap { (value: Project) -> ResultMap in value.resultMap }, "remainingQuantity": remainingQuantity, "shippingPreference": shippingPreference, "shippingSummary": shippingSummary, "shippingRules": shippingRules.flatMap { (value: [ShippingRule?]) -> [ResultMap?] in value.map { (value: ShippingRule?) -> ResultMap? in value.flatMap { (value: ShippingRule) -> ResultMap in value.resultMap } } }, "startsAt": startsAt])
}

public var __typename: String {
Expand Down Expand Up @@ -15709,6 +15711,16 @@ public enum GraphAPI {
}
}

/// Whether or not the reward is available for new pledges
public var available: Bool {
get {
return resultMap["available"]! as! Bool
}
set {
resultMap.updateValue(newValue, forKey: "available")
}
}

/// Items in the reward.
public var items: Item? {
get {
Expand Down
1 change: 1 addition & 0 deletions KsApi/fragments/RewardFragment.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ fragment RewardFragment on Reward {
estimatedDeliveryOn
id
isMaxPledge
available
items {
edges {
quantity
Expand Down
3 changes: 3 additions & 0 deletions KsApi/models/Reward.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public struct Reward {
public let startsAt: TimeInterval?
public let title: String?
public let localPickup: Location?
/// isAvailable is provided by GraphQL but not by API V1.
public let isAvailable: Bool?

/// Returns `true` is this is the "fake" "No reward" reward.
public var isNoReward: Bool {
Expand Down Expand Up @@ -147,6 +149,7 @@ extension Reward: Decodable {
self.title = try values.decodeIfPresent(String.self, forKey: .title)
// NOTE: `v1` is deprecated and doesn't contain any location pickup information.
self.localPickup = nil
self.isAvailable = nil
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ final class Backing_BackingFragmentTests: XCTestCase {
XCTAssertEqual(backing.projectId, 1_596_594_463)
XCTAssertNotNil(backing.reward)
XCTAssertEqual(backing.rewardId, decompose(id: "UmV3YXJkLTgxNzM5MDE="))
XCTAssertNotNil(backing.reward?.isAvailable)
XCTAssertEqual(backing.sequence, 148)
XCTAssertEqual(backing.shippingAmount, 10.0)
XCTAssertEqual(backing.status, .pledged)
Expand Down Expand Up @@ -793,6 +794,7 @@ private func backingDictionary() -> [String: Any] {
"estimatedDeliveryOn": "2021-12-01",
"id": "UmV3YXJkLTgxNzM5MDE=",
"isMaxPledge": false,
"available": false,
"items": {
"__typename": "RewardItemsConnection",
"edges": [
Expand Down
3 changes: 2 additions & 1 deletion KsApi/models/graphql/adapters/Reward+RewardFragment.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ extension Reward {
shippingRulesExpanded: expandedShippingRules,
startsAt: rewardFragment.startsAt.flatMap(TimeInterval.init),
title: rewardFragment.name,
localPickup: location
localPickup: location,
isAvailable: rewardFragment.available
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ final class Reward_RewardFragmentTests: XCTestCase {
XCTAssertEqual(v1Reward.rewardsItems[1].item.id, 1_170_813)
XCTAssertEqual(v1Reward.rewardsItems[1].item.name, "Custom Bookmark")
XCTAssertEqual(v1Reward.rewardsItems[1].quantity, 1)
XCTAssertNotNil(v1Reward.isAvailable)

XCTAssertEqual(v1Reward.shipping.enabled, true)
XCTAssertEqual(v1Reward.shipping.preference, .unrestricted)
Expand Down Expand Up @@ -98,6 +99,7 @@ private func rewardDictionary() -> [String: Any] {
"estimatedDeliveryOn": "2021-12-01",
"id": "UmV3YXJkLTgxNzM5MDE=",
"isMaxPledge": false,
"available": false,
"items": {
"__typename": "RewardItemsConnection",
"edges": [
Expand Down

0 comments on commit 6fcf7ee

Please sign in to comment.