diff --git a/internal/transformer/order_transformer.go b/internal/transformer/order_transformer.go index 92b8ab8..b297cef 100644 --- a/internal/transformer/order_transformer.go +++ b/internal/transformer/order_transformer.go @@ -17,6 +17,7 @@ func CreateOrderContractToModel(req *contract.CreateOrderRequest) *models.Create ProductID: item.ProductID, ProductVariantID: item.ProductVariantID, Quantity: item.Quantity, + Weight: item.Weight, UnitPrice: item.UnitPrice, // Now optional Modifiers: item.Modifiers, Notes: item.Notes, @@ -58,6 +59,7 @@ func AddToOrderContractToModel(req *contract.AddToOrderRequest) *models.AddToOrd ProductID: item.ProductID, ProductVariantID: item.ProductVariantID, Quantity: item.Quantity, + Weight: item.Weight, UnitPrice: item.UnitPrice, // Now optional Modifiers: item.Modifiers, Notes: item.Notes, diff --git a/internal/transformer/order_transformer_test.go b/internal/transformer/order_transformer_test.go new file mode 100644 index 0000000..c3067a0 --- /dev/null +++ b/internal/transformer/order_transformer_test.go @@ -0,0 +1,48 @@ +package transformer + +import ( + "testing" + + "apskel-pos-be/internal/contract" + + "github.com/google/uuid" + "github.com/stretchr/testify/require" +) + +func TestCreateOrderContractToModelCarriesWeight(t *testing.T) { + weight := 1.25 + + result := CreateOrderContractToModel(&contract.CreateOrderRequest{ + OutletID: uuid.New(), + UserID: uuid.New(), + OrderItems: []contract.CreateOrderItemRequest{ + { + ProductID: uuid.New(), + Quantity: 1, + Weight: &weight, + }, + }, + }) + + require.Len(t, result.OrderItems, 1) + require.NotNil(t, result.OrderItems[0].Weight) + require.Equal(t, weight, *result.OrderItems[0].Weight) +} + +func TestAddToOrderContractToModelCarriesWeight(t *testing.T) { + weight := 0.8 + + result := AddToOrderContractToModel(&contract.AddToOrderRequest{ + OrderItems: []contract.CreateOrderItemRequest{ + { + ProductID: uuid.New(), + Quantity: 1, + Weight: &weight, + }, + }, + }) + + require.Len(t, result.OrderItems, 1) + require.NotNil(t, result.OrderItems[0].Weight) + require.Equal(t, weight, *result.OrderItems[0].Weight) +}