Files
apskel-pos-backend/internal/processor/order_add_items_test.go
T

47 lines
1.8 KiB
Go
Raw Normal View History

2026-10-01 22:26:44 +07:00
package processor
import (
"testing"
"apskel-pos-be/internal/entities"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// The items AddToOrder creates have no product loaded, so their responses used to go out
// without a name or a printer, and the POS could not print them.
func TestAddedItemsFromOrderUsesTheReloadedProduct(t *testing.T) {
outletID := uuid.New()
paket := entities.Product{ID: uuid.New(), Name: "Paket Makan Minum"}
paket.SetPrinterTypes([]string{"kitchen", "bar"})
paket.ProductOutletPrices = []entities.ProductOutletPrice{{OutletID: outletID, PrintToChecker: false}}
esTeh := entities.Product{ID: uuid.New(), Name: "Es Teh"}
esTeh.SetPrinterTypes([]string{"bar"})
existing := entities.OrderItem{ID: uuid.New(), ProductID: esTeh.ID, Product: esTeh}
addedPaket := &entities.OrderItem{ID: uuid.New(), ProductID: paket.ID}
addedEsTeh := &entities.OrderItem{ID: uuid.New(), ProductID: esTeh.ID}
order := &entities.Order{
OutletID: outletID,
OrderItems: []entities.OrderItem{
existing,
{ID: addedEsTeh.ID, ProductID: esTeh.ID, Product: esTeh},
{ID: addedPaket.ID, ProductID: paket.ID, Product: paket},
},
}
responses := addedItemsFromOrder([]*entities.OrderItem{addedPaket, addedEsTeh}, order)
require.Len(t, responses, 2, "only the added items, not the ones already on the order")
assert.Equal(t, addedPaket.ID, responses[0].ID, "in the order they were requested")
assert.Equal(t, "Paket Makan Minum", responses[0].ProductName)
assert.Equal(t, []string{"kitchen", "bar"}, responses[0].PrinterTypes)
assert.False(t, responses[0].PrintToChecker, "the outlet's print_to_checker is loaded too")
assert.Equal(t, addedEsTeh.ID, responses[1].ID)
assert.Equal(t, []string{"bar"}, responses[1].PrinterTypes)
}