CreateOrderContractToModel and AddToOrderContractToModel copied every order item field except Weight, so a weight sent by the client never reached the processor and every weight-based line failed with "product ... is sold by weight and requires a weight". Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
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)
|
|
}
|