Skip to content

Commit

Permalink
Fixes incorrect price for a lot sold to the user.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashfurrow committed Jan 20, 2017
1 parent ca261ca commit a56235c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
Expand Up @@ -22,6 +22,7 @@ protocol LiveAuctionsSalesPersonType: class {
func lotViewModelRelativeToShowingIndex(_ offset: Int) -> LiveAuctionLotViewModelType
func currentLotValue(_ lot: LiveAuctionLotViewModelType) -> UInt64
func currentLotValueString(_ lot: LiveAuctionLotViewModelType) -> String
func winningLotValueString(_ lot: LiveAuctionLotViewModelType) -> String?

func bidOnLot(_ lot: LiveAuctionLotViewModelType, amountCents: UInt64, biddingViewModel: LiveAuctionBiddingViewModelType)
func leaveMaxBidOnLot(_ lot: LiveAuctionLotViewModelType, amountCents: UInt64, biddingViewModel: LiveAuctionBiddingViewModelType)
Expand Down Expand Up @@ -90,6 +91,12 @@ class LiveAuctionsSalesPerson: NSObject, LiveAuctionsSalesPersonType {
func currentLotValueString(_ lot: LiveAuctionLotViewModelType) -> String {
return currentLotValue(lot).convertToDollarString(lot.currencySymbol)
}

func winningLotValueString(_ lot: LiveAuctionLotViewModelType) -> String? {
guard let winningBidPrice = lot.winningBidPrice else { return nil }

return winningBidPrice.convertToDollarString(lot.currencySymbol)
}
}

private typealias ComputedProperties = LiveAuctionsSalesPerson
Expand Down
Expand Up @@ -41,6 +41,7 @@ protocol LiveAuctionLotViewModelType: class {
var urlForThumbnail: URL { get }
var urlForProfile: URL { get }
var askingPrice: UInt64 { get }
var winningBidPrice: UInt64? { get }
var currencySymbol: String { get }
var numberOfBids: Int { get }
var imageAspectRatio: CGFloat { get }
Expand Down Expand Up @@ -152,6 +153,10 @@ class LiveAuctionLotViewModel: NSObject, LiveAuctionLotViewModelType {
return String(model.lotNumber)
}

var winningBidPrice: UInt64? {
return self.winningBidEvent?.bidAmountCents
}

var askingPrice: UInt64 {
return model.askingPriceCents
}
Expand Down
Expand Up @@ -92,8 +92,9 @@ class AuctionLotMetadataStackScrollView: ORStackScrollView {
currentBid.text = newCurrentBid.bid
}
case .closedLot:
if viewModel.isBeingSold && viewModel.userIsBeingSoldTo {
currentBid.text = "Sold for: \(salesPerson.currentLotValueString(viewModel))"
if viewModel.isBeingSold && viewModel.userIsBeingSoldTo,
let winningLotValueString = salesPerson.winningLotValueString(viewModel) {
currentBid.text = "Sold for: \(winningLotValueString)"
} else {
currentBid.text = ""
}
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Expand Up @@ -48,6 +48,14 @@ class LiveAuctionLotViewControllerTests: QuickSpec {
expect(subject) == snapshot()
}

it("looks good for won lots") {
lotViewModel.isBeingSold = true
lotViewModel.userIsBeingSoldTo = true
lotViewModel.winningBidPrice = 6000_00
lotViewModel.lotStateSignal.update(.closedLot(wasPassed: false))
expect(subject) == snapshot()
}

it("looks good for passed lots") {
lotViewModel.lotStateSignal.update(.closedLot(wasPassed: true))
expect(subject) == snapshot()
Expand Down Expand Up @@ -154,6 +162,7 @@ class Test_LiveAuctionLotViewModel: LiveAuctionLotViewModelType {
var userIsBeingSoldTo: Bool = false
var userIsWinning: Bool = false
var isBeingSold: Bool = false
var winningBidPrice: UInt64? = nil
// Whether or not (all) events returned from this test VM should be cancelled.
var cancelEvents = false

Expand Down

0 comments on commit a56235c

Please sign in to comment.