-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NT-209, NT-156] Pledge Button Interaction (Create Backing) (#855)
* Create Backing * Create Backing Tests * Formatting * Fix formatting issues * Use paymentType instead of string
- Loading branch information
Isabel Barrera
authored
Sep 27, 2019
1 parent
08995ab
commit 57ddae9
Showing
12 changed files
with
267 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
import Foundation | ||
|
||
// This type should be removed once the createBacking mutation is updated to automatically set this type | ||
public enum PaymentType: String, Encodable { | ||
case creditCard = "CREDIT_CARD" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import Foundation | ||
@testable import KsApi | ||
@testable import Library | ||
import Prelude | ||
import XCTest | ||
|
||
final class CreateBackingInputConstructorTests: XCTestCase { | ||
func testCreateBackingInput_NoShipping() { | ||
let project = Project.template | ||
let reward = Reward.noReward | ||
|
||
let input = CreateBackingInput.input( | ||
from: project, | ||
reward: reward, | ||
pledgeAmount: 10, | ||
selectedShippingRule: nil, | ||
refTag: RefTag.projectPage, | ||
paymentSourceId: "123" | ||
) | ||
|
||
XCTAssertEqual(input.amount, "10.00") | ||
XCTAssertNil(input.locationId) | ||
XCTAssertEqual(input.projectId, project.graphID) | ||
XCTAssertNil(input.rewardId) | ||
XCTAssertEqual(input.refParam, "project_page") | ||
XCTAssertEqual(input.paymentSourceId, "123") | ||
} | ||
|
||
func testCreateBackingInput_WithShipping_RefTagNil() { | ||
let project = Project.template | ||
let reward = Reward.template | ||
let shippingRule = ShippingRule.template | ||
|> ShippingRule.lens.location .. Location.lens.id .~ 1 | ||
|> ShippingRule.lens.cost .~ 5 | ||
|
||
let input = CreateBackingInput.input( | ||
from: project, | ||
reward: reward, | ||
pledgeAmount: 10, | ||
selectedShippingRule: shippingRule, | ||
refTag: nil, | ||
paymentSourceId: "123" | ||
) | ||
|
||
XCTAssertEqual(input.amount, "15.00") | ||
XCTAssertEqual(input.locationId, "1") | ||
XCTAssertEqual(input.projectId, project.graphID) | ||
XCTAssertEqual(input.rewardId, reward.graphID) | ||
XCTAssertEqual(input.paymentSourceId, "123") | ||
XCTAssertNil(input.refParam) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Foundation | ||
import KsApi | ||
|
||
extension CreateBackingInput { | ||
internal static func input( | ||
from project: Project, | ||
reward: Reward, | ||
pledgeAmount: Double, | ||
selectedShippingRule: ShippingRule?, | ||
refTag: RefTag?, | ||
paymentSourceId: String | ||
) -> CreateBackingInput { | ||
let pledgeAmountDecimal = Decimal(pledgeAmount) | ||
var shippingAmountDecimal: Decimal = Decimal() | ||
var shippingLocationId: String? | ||
|
||
if let shippingRule = selectedShippingRule, shippingRule.cost > 0 { | ||
shippingAmountDecimal = Decimal(shippingRule.cost) | ||
shippingLocationId = String(shippingRule.location.id) | ||
} | ||
|
||
let pledgeTotal = NSDecimalNumber(decimal: pledgeAmountDecimal + shippingAmountDecimal) | ||
let formattedPledgeTotal = Format.decimalCurrency(for: pledgeTotal.doubleValue) | ||
|
||
let rewardId = reward == Reward.noReward ? nil : reward.graphID | ||
|
||
return CreateBackingInput( | ||
amount: formattedPledgeTotal, | ||
locationId: shippingLocationId, | ||
paymentSourceId: paymentSourceId, | ||
projectId: project.graphID, | ||
rewardId: rewardId, | ||
refParam: refTag?.description | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.