Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 8 additions & 0 deletions Modules/Tests/NetworkingTests/Remote/OrdersRemoteTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,14 @@ final class OrdersRemoteTests: XCTestCase {
XCTAssertFalse(fieldValues.contains(" "))
}

func test_order_fields_parameter_includes_created_via_field() throws {
// When
let fieldValues = OrdersRemote.ParameterValues.fieldValues

// Then
XCTAssertTrue(fieldValues.contains("created_via"), "fieldValues should include 'created_via' field")
}

// MARK: - Load All Orders Tests

/// Verifies that loadAllOrders properly parses the `orders-load-all` sample response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,36 @@ final class OrdersUpsertUseCaseTests: XCTestCase {
XCTAssertEqual(storageTaxLine.toReadOnly(), taxLine)
}

func test_order_with_createdVia_field_when_upsert_to_storage_then_field_is_persisted_correctly() throws {
// Given
let order = makeOrder().copy(siteID: defaultSiteID, orderID: 123, createdVia: "pos-rest-api")
let useCase = OrdersUpsertUseCase(storage: viewStorage)

// When
useCase.upsert([order])

// Then
let persistedOrder = try XCTUnwrap(viewStorage.loadOrder(siteID: defaultSiteID, orderID: 123))
XCTAssertEqual(persistedOrder.createdVia, "pos-rest-api")
XCTAssertEqual(persistedOrder.toReadOnly().createdVia, "pos-rest-api")
}

func test_order_with_createdVia_field_when_updated_then_field_is_updated_correctly() throws {
// Given
let originalOrder = makeOrder().copy(siteID: defaultSiteID, orderID: 123, createdVia: nil)
let useCase = OrdersUpsertUseCase(storage: viewStorage)
useCase.upsert([originalOrder])

// When
let updatedOrder = originalOrder.copy(createdVia: "pos-rest-api")
useCase.upsert([updatedOrder])

// Then
let persistedOrder = try XCTUnwrap(viewStorage.loadOrder(siteID: defaultSiteID, orderID: 123))
XCTAssertEqual(persistedOrder.createdVia, "pos-rest-api")
XCTAssertEqual(persistedOrder.toReadOnly().createdVia, "pos-rest-api")
}

func test_it_persists_order_item_attributes_in_storage() throws {
// Given
let attributes = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,37 @@ final class OrderListCellViewModelTests: XCTestCase {
XCTAssertEqual(accessoryView.image, expectedImage)
XCTAssertEqual(accessoryView.tintColor, .tertiaryLabel)
}

func test_salesChannel_when_createdVia_is_pos_rest_api_then_returns_POS() {
// Given
let order = MockOrders().sampleOrder().copy(createdVia: "pos-rest-api")

// When
let viewModel = OrderListCellViewModel(order: order, currencySettings: ServiceLocator.currencySettings)

// Then
XCTAssertEqual(viewModel.salesChannel, "POS")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: is "POS" directly shown in the UI? If so, might we consider making this string localizable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, it does show in the UI but I didn't consider it's a string we'd make localizable, ie: In Spanish the acronym is still POS despite the translation being "punto de venta" 🤔 . I see this is set as localizable string in POSTabViewController thought and definitely makes sense for it to be localized. Updated on 1f93588

}

func test_salesChannel_when_createdVia_is_nil_then_returns_nil() {
// Given
let order = MockOrders().sampleOrder().copy(createdVia: nil)

// When
let viewModel = OrderListCellViewModel(order: order, currencySettings: ServiceLocator.currencySettings)

// Then
XCTAssertNil(viewModel.salesChannel)
}

func test_salesChannel_when_createdVia_is_not_pos_rest_api_then_returns_nil() {
// Given
let order = MockOrders().sampleOrder().copy(createdVia: "checkout")

// When
let viewModel = OrderListCellViewModel(order: order, currencySettings: ServiceLocator.currencySettings)

// Then
XCTAssertNil(viewModel.salesChannel)
}
}