woocommerce / woocommerce-ios

WooCommerce iOS app
https://www.woocommerce.com/mobile
GNU General Public License v2.0
298 stars 110 forks source link

[Woo POS] Improve testability: Consider change unique ID for `CartItem` #13209

Open iamgabrielma opened 2 months ago

iamgabrielma commented 2 months ago

Currently, we initialize CartItem within addItemToCart(:), and provide it with an unique ID. This acts as unique identifier to differentiate between multiple items in the cart that could share the same product ID

    func addItemToCart(_ item: POSItem) {
        let cartItem = CartItem(id: UUID(), item: item, quantity: 1)
        itemsInCart.append(cartItem)
    }

We should consider if, for testability, we should create the CartItem and it's ID not as a side effect of "adding items to cart", but as a separate method. On the other end, this UUID is exclusively of internal usage for the CartView, so perhaps is not needed to expose it.

dangermattic commented 2 months ago

Thanks for reporting! 👍