Skip to content
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
5 changes: 5 additions & 0 deletions Modules/Sources/NetworkingCore/Model/Order.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public struct Order: Decodable, Sendable, GeneratedCopiable, GeneratedFakeable {
///
public let createdVia: String?

public var salesChannel: SalesChannel? {
guard let createdVia else { return nil }
return SalesChannel(rawValue: createdVia)
}

/// Order struct initializer.
///
public init(siteID: Int64,
Expand Down
32 changes: 32 additions & 0 deletions Modules/Sources/NetworkingCore/Model/SalesChannel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Foundation

public enum SalesChannel {
case pointOfSale
}

extension SalesChannel: RawRepresentable {
public init?(rawValue: String) {
switch rawValue {
case "pos-rest-api":
self = .pointOfSale
default:
return nil
}
}

public var rawValue: String {
switch self {
case .pointOfSale:
return description
}
}

public var description: String {
switch self {
case .pointOfSale:
return NSLocalizedString("salesChannel.pos.description",
value: "POS",
comment: "The acronym for 'Point of Sale'.")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,7 @@ struct OrderListCellViewModel {
/// Textual representation of the sales channel
///
var salesChannel: String? {
guard let createdVia = order.createdVia else {
return nil
}

switch createdVia {
case "pos-rest-api":
return Localization.salesChannelPOSText
default:
return nil
}
order.salesChannel?.description
}

/// The localized unabbreviated total for a given order item, which includes the currency.
Expand Down Expand Up @@ -128,9 +119,5 @@ extension OrderListCellViewModel {
"orderlistcellviewmodel.customerName.guestName",
value: "Guest",
comment: "In Order List, the name of the billed person when there are no first and last name.")
static let salesChannelPOSText = NSLocalizedString(
"orderlistcellviewmodel.salesChannel.salesChannelPOSText",
value: "POS",
comment: "In Order List, the acronym for 'Point of Sale' that is shown as a badge for certain orders.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ final class SummaryTableViewCell: UITableViewCell {
func configure(_ viewModel: SummaryTableViewCellViewModel) {
titleLabel.text = viewModel.billedPersonName
subtitleLabel.text = viewModel.subtitle
salesChannelLabel.text = viewModel.formattedSalesChannel
salesChannelLabel.text = viewModel.salesChannel
salesChannelLabel.isHidden = (salesChannelLabel.text == nil)
display(presentation: viewModel.presentation)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ struct SummaryTableViewCellViewModel {

private let billingAddress: Address?
private let dateCreated: Date
private let salesChannel: String?
private(set) var salesChannel: String?

let presentation: OrderStatusPresentation

Expand All @@ -21,7 +21,7 @@ struct SummaryTableViewCellViewModel {

billingAddress = order.billingAddress
dateCreated = order.dateCreated
salesChannel = order.createdVia
salesChannel = order.salesChannel?.description

presentation = OrderStatusPresentation(
style: status?.status ?? order.status,
Expand All @@ -48,20 +48,6 @@ struct SummaryTableViewCellViewModel {
formatter.timeZone = .siteTimezone
return formatter.string(from: dateCreated)
}

/// Textual representation of the sales channel
///
var formattedSalesChannel: String? {
guard let salesChannel = salesChannel else {
return nil
}
switch salesChannel {
case "pos-rest-api":
return "POS"
default:
return nil
}
}
}

private extension SummaryTableViewCellViewModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ final class OrderListCellViewModelTests: XCTestCase {
let viewModel = OrderListCellViewModel(order: order, currencySettings: ServiceLocator.currencySettings)

// Then
XCTAssertEqual(viewModel.salesChannel, OrderListCellViewModel.Localization.salesChannelPOSText)
XCTAssertEqual(viewModel.salesChannel, "POS")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had to revert the localization here as now the localized string sits in Networking 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine, a bunch of unit tests are already based on the English locale assumption.

}

func test_salesChannel_when_createdVia_is_nil_then_returns_nil() {
Expand Down