2026-09-06 22:44:55 +07:00
|
|
|
package transformer
|
|
|
|
|
|
|
|
|
|
import (
|
2026-09-30 15:31:44 +07:00
|
|
|
"encoding/json"
|
2026-09-06 22:44:55 +07:00
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
"apskel-pos-be/internal/contract"
|
2026-09-30 15:31:44 +07:00
|
|
|
"apskel-pos-be/internal/models"
|
2026-09-06 22:44:55 +07:00
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
2026-09-30 15:31:44 +07:00
|
|
|
"github.com/stretchr/testify/assert"
|
2026-09-06 22:44:55 +07:00
|
|
|
"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)
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-30 23:29:17 +07:00
|
|
|
func TestCreateOrderContractToModelCarriesCustomer(t *testing.T) {
|
|
|
|
|
customerID := uuid.New()
|
|
|
|
|
|
|
|
|
|
result := CreateOrderContractToModel(&contract.CreateOrderRequest{
|
|
|
|
|
OutletID: uuid.New(),
|
|
|
|
|
UserID: uuid.New(),
|
|
|
|
|
CustomerID: &customerID,
|
|
|
|
|
OrderItems: []contract.CreateOrderItemRequest{{ProductID: uuid.New(), Quantity: 1}},
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
require.NotNil(t, result.CustomerID, "the order's customer is who earns EnakPoint and EnakCoin")
|
|
|
|
|
require.Equal(t, customerID, *result.CustomerID)
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-06 22:44:55 +07:00
|
|
|
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)
|
|
|
|
|
}
|
2026-09-30 15:31:44 +07:00
|
|
|
|
|
|
|
|
func TestOrderModelToContractCarriesEarnings(t *testing.T) {
|
|
|
|
|
got := OrderModelToContract(&models.OrderResponse{PointsEarned: 875, CoinsEarned: 3})
|
|
|
|
|
assert.Equal(t, int64(875), got.PointsEarned)
|
|
|
|
|
assert.Equal(t, int64(3), got.CoinsEarned)
|
|
|
|
|
|
|
|
|
|
body, err := json.Marshal(OrderModelToContract(&models.OrderResponse{}))
|
|
|
|
|
assert.NoError(t, err)
|
|
|
|
|
assert.Contains(t, string(body), `"points_earned":0`, "present as 0 when nothing was earned")
|
|
|
|
|
assert.Contains(t, string(body), `"coins_earned":0`)
|
|
|
|
|
}
|