Merge pull request 'fix(order): carry item weight through the contract-to-model transformer' (#30) from feature/weight-based-products into main
Reviewed-on: https://gits.altru.id/apksel-dev/apskel-pos-backend/pulls/30
This commit was merged in pull request #30.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user