Skip to content

Commit

Permalink
Add a test case on CartViewModel.removeItemFromCart.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaclync committed Jul 1, 2024
1 parent 000442f commit e15efe2
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,24 @@ final class CartViewModelTests: XCTestCase {
*/
}

func test_removeItemFromCart_after_adding_2_items_removes_item() throws {
// Given
let item = Self.makeItem(name: "Item 1")
let anotherItem = Self.makeItem(name: "Item 2")
sut.addItemToCart(item)
sut.addItemToCart(anotherItem)
XCTAssertEqual(sut.itemsInCart.count, 2)
XCTAssertEqual(sut.itemsInCart.map { $0.item.name }, [item, anotherItem].map { $0.name })

// When
let firstCartItem = try XCTUnwrap(sut.itemsInCart.first)
sut.removeItemFromCart(firstCartItem)

// Then
XCTAssertEqual(sut.itemsInCart.count, 1)
XCTAssertEqual(sut.itemsInCart.map { $0.item.name }, [anotherItem.name])
}

func test_cart_when_removeAllItemsFromCart_is_invoked_then_removes_all_items_from_cart() {
// Given
let item = Self.makeItem()
Expand Down Expand Up @@ -126,10 +144,10 @@ final class CartViewModelTests: XCTestCase {
}

private extension CartViewModelTests {
static func makeItem() -> POSItem {
static func makeItem(name: String = "") -> POSItem {
return POSProduct(itemID: UUID(),
productID: 0,
name: "",
name: name,
price: "",
formattedPrice: "",
itemCategories: [],
Expand Down

0 comments on commit e15efe2

Please sign in to comment.