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

[MBL-1712] No Reward Option Not Shown in Edit Reward Flow #2150

Merged
merged 4 commits into from
Sep 9, 2024
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
2 changes: 1 addition & 1 deletion Library/SharedFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public func rewardsCarouselCanNavigateToReward(_ reward: Reward, in project: Pro

let isBacking = userIsBacking(reward: reward, inProject: project)
let isAvailableForNewBacker = rewardIsAvailable(reward) && !isBacking
let isAvailableForExistingBackerToEdit = (isBacking && reward.hasAddOns)
let isAvailableForExistingBackerToEdit = (isBacking && (reward.hasAddOns || featureNoShippingAtCheckout()))

if featurePostCampaignPledgeEnabled(), project.isInPostCampaignPledgingPhase {
return [
Expand Down
28 changes: 27 additions & 1 deletion Library/SharedFunctionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ final class SharedFunctionsTests: TestCase {
XCTAssertTrue(rewardsCarouselCanNavigateToReward(reward, in: project))
}

func testRewardsCarouselCanNavigateToReward_RegularReward_Available_Backed() {
func testRewardsCarouselCanNavigateToReward_RegularReward_Available_Backed_FeatureNoShippingAtCheckout_False(
) {
let reward = Reward.template
|> Reward.lens.limit .~ 5
|> Reward.lens.remaining .~ 5
Expand All @@ -166,6 +167,31 @@ final class SharedFunctionsTests: TestCase {
XCTAssertFalse(rewardsCarouselCanNavigateToReward(reward, in: project))
}

func testRewardsCarouselCanNavigateToReward_RegularReward_Available_Backed_FeatureNoShippingAtCheckout_True(
) {
let mockConfigClient = MockRemoteConfigClient()
mockConfigClient.features = [
RemoteConfigFeature.noShippingAtCheckout.rawValue: true
]

let reward = Reward.template
|> Reward.lens.limit .~ 5
|> Reward.lens.remaining .~ 5
|> Reward.lens.endsAt .~ (MockDate().timeIntervalSince1970 + 60)

let project = Project.cosmicSurgery
|> Project.lens.rewardData.rewards .~ [reward]
|> Project.lens.personalization.backing .~ (
.template
|> Backing.lens.reward .~ reward
|> Backing.lens.rewardId .~ reward.id
)

withEnvironment(remoteConfigClient: mockConfigClient) {
XCTAssertTrue(rewardsCarouselCanNavigateToReward(reward, in: project))
}
}

func testRewardsCarouselCanNavigateToReward_RegularReward_Unavailable_Backed() {
let reward = Reward.template
|> Reward.lens.limit .~ 5
Expand Down
3 changes: 2 additions & 1 deletion Library/ViewModels/NoShippingPledgeViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,8 @@ private func amountValid(
that is, in `RewardAddOnSelectionViewController` we don't navigate further unless the selection changes.
*/
return [
pledgeAmountData.amount != initialAdditionalPledgeAmount || reward.hasAddOns,
pledgeAmountData
.amount != initialAdditionalPledgeAmount || (reward.hasAddOns || featureNoShippingAtCheckout()),
pledgeAmountData.isValid
]
.allSatisfy(isTrue)
Expand Down
4 changes: 2 additions & 2 deletions Library/ViewModels/RewardCardContainerViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private func pledgeButtonTitle(project: Project, reward: Reward) -> String? {
case (.backed(.live), false, true):
return Strings.Select()
case (.backed(.live), true, _), (.backed(.nonLive), true, _):
if reward.hasAddOns, project.state == .live {
if reward.hasAddOns || featureNoShippingAtCheckout(), project.state == .live {
return Strings.Continue()
}
return Strings.Selected()
Expand Down Expand Up @@ -135,7 +135,7 @@ private func buttonStyleType(project: Project, reward: Reward) -> ButtonStyleTyp
}
case .backed(.live):
if isBackingThisReward {
if reward.hasAddOns {
if reward.hasAddOns || featureNoShippingAtCheckout() {
return .green
}
return .black
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ private func filteredRewardsByLocation(
let isUnrestrictedShippingReward = reward.isUnRestrictedShippingPreference
let isRestrictedShippingReward = reward.isRestrictedShippingPreference

// return all rewards that are digital or ship anywhere in the world.
if isRewardLocalOrDigital || isUnrestrictedShippingReward {
// return all rewards that are no reward, digital, or ship anywhere in the world.
if rewards.first?.id == reward.id || isRewardLocalOrDigital || isUnrestrictedShippingReward {
shouldDisplayReward = true

// if add on is local pickup, ensure locations are equal.
Expand Down