Skip to content

Commit

Permalink
[NT-521] Fix No Reward minimum conversion bug (#924)
Browse files Browse the repository at this point in the history
* Fix No Reward conversion bug

* Cleanup

* Removing redundant test
  • Loading branch information
Isabel Barrera authored Nov 4, 2019
1 parent 4fc6d69 commit 25bf7b2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
29 changes: 27 additions & 2 deletions Kickstarter-iOS/Library/SharedFunctionsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,24 @@ internal final class SharedFunctionsTests: XCTestCase {
XCTAssertEqual(backedReward, reward(from: backing, inProject: project))
}

func testRewardFromBackingWithProject_WhenRewardNotPresent() {
func testRewardFromBackingWithProject_WhenRewardNotPresent_NoRewardPresent() {
let backing = Backing.template
|> Backing.lens.reward .~ nil
|> Backing.lens.rewardId .~ 123
let noReward = Reward.noReward
|> Reward.lens.minimum .~ 10
let project = Project.template
|> Project.lens.personalization.backing .~ backing
|> Project.lens.rewards .~ [
noReward, // No Reward "reward" is available
Reward.template
|> Reward.lens.id .~ 456
]

XCTAssertEqual(noReward, reward(from: backing, inProject: project))
}

func testRewardFromBackingWithProject_WhenRewardNotPresent_NoRewardNotPresent() {
let backing = Backing.template
|> Backing.lens.reward .~ nil
|> Backing.lens.rewardId .~ 123
Expand All @@ -135,9 +152,17 @@ internal final class SharedFunctionsTests: XCTestCase {
|> Backing.lens.rewardId .~ nil

let project = Project.template
|> Project.lens.rewards .~ []
|> Project.lens.personalization.backing .~ backing

XCTAssertEqual(Reward.noReward, reward(from: backing, inProject: project))
XCTAssertEqual(
Reward.noReward,
reward(
from: backing,
inProject: project
),
"Worst case when there are no rewards in the project, default to our local Reward.noReward"
)
}

func testIsCurrentUserCreatorOfProject_IsCreator() {
Expand Down
3 changes: 3 additions & 0 deletions Library/SharedFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ internal func currentUserIsCreator(of project: Project) -> Bool {
*/

internal func reward(from backing: Backing, inProject project: Project) -> Reward {
let noRewardFromProject = project.rewards.filter { $0.id == Reward.noReward.id }.first

return backing.reward
?? project.rewards.filter { $0.id == backing.rewardId }.first
?? noRewardFromProject
?? Reward.noReward
}

Expand Down

0 comments on commit 25bf7b2

Please sign in to comment.