feat: add printer types
This commit is contained in:
@@ -44,8 +44,9 @@ func InventoryModelResponseToResponse(inv *models.InventoryResponse) *contract.I
|
||||
IsLowStock: inv.IsLowStock,
|
||||
UpdatedAt: inv.UpdatedAt,
|
||||
Product: &contract.ProductResponse{
|
||||
ID: inv.ProductID,
|
||||
Name: inv.ProductName,
|
||||
ID: inv.ProductID,
|
||||
Name: inv.ProductName,
|
||||
PrinterTypes: []string{},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ func OrderModelToContract(resp *models.OrderResponse) *contract.OrderResponse {
|
||||
Status: string(item.Status),
|
||||
CreatedAt: item.CreatedAt,
|
||||
UpdatedAt: item.UpdatedAt,
|
||||
PrinterType: item.PrinterType,
|
||||
PrinterTypes: item.PrinterTypes,
|
||||
PrintToChecker: item.PrintToChecker,
|
||||
PaidQuantity: item.PaidQuantity,
|
||||
}
|
||||
@@ -195,6 +195,7 @@ func AddToOrderModelToContract(resp *models.AddToOrderResponse) *contract.AddToO
|
||||
Status: string(item.Status),
|
||||
CreatedAt: item.CreatedAt,
|
||||
UpdatedAt: item.UpdatedAt,
|
||||
PrinterTypes: item.PrinterTypes,
|
||||
PrintToChecker: item.PrintToChecker,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
package transformer
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
|
||||
"apskel-pos-be/internal/entities"
|
||||
"apskel-pos-be/internal/mappers"
|
||||
"apskel-pos-be/internal/models"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// The POS prints items added to an open order from this response, so each one has to
|
||||
// say where it is printed.
|
||||
func TestAddToOrderModelToContractCarriesPrinters(t *testing.T) {
|
||||
result := AddToOrderModelToContract(&models.AddToOrderResponse{
|
||||
AddedItems: []models.OrderItemResponse{{PrinterTypes: []string{"kitchen", "bar"}}},
|
||||
})
|
||||
|
||||
require.Len(t, result.AddedItems, 1)
|
||||
assert.Equal(t, []string{"kitchen", "bar"}, result.AddedItems[0].PrinterTypes)
|
||||
}
|
||||
|
||||
// Follows an order from the database row to the JSON the POS reads.
|
||||
func TestOrderJSONCarriesPrinters(t *testing.T) {
|
||||
paket := entities.Product{ID: uuid.New(), Name: "Paket Makan Minum"}
|
||||
paket.SetPrinterTypes([]string{"kitchen", "bar"})
|
||||
order := &entities.Order{
|
||||
ID: uuid.New(),
|
||||
OrderItems: []entities.OrderItem{{ID: uuid.New(), ProductID: paket.ID, Product: paket, Quantity: 1}},
|
||||
}
|
||||
|
||||
body, err := json.Marshal(OrderModelToContract(mappers.OrderEntityToResponse(order)))
|
||||
require.NoError(t, err)
|
||||
|
||||
assert.Contains(t, string(body), `"printer_types":["kitchen","bar"]`)
|
||||
assert.NotContains(t, string(body), `"printer_type":`, "printer_types replaced it")
|
||||
}
|
||||
|
||||
func TestOrderModelToContractCarriesPrinters(t *testing.T) {
|
||||
result := OrderModelToContract(&models.OrderResponse{
|
||||
OrderItems: []models.OrderItemResponse{{PrinterTypes: []string{"kitchen", "bar"}}},
|
||||
})
|
||||
|
||||
require.Len(t, result.OrderItems, 1)
|
||||
assert.Equal(t, []string{"kitchen", "bar"}, result.OrderItems[0].PrinterTypes)
|
||||
}
|
||||
@@ -61,7 +61,7 @@ func CreateProductRequestToModel(apctx *appcontext.ContextInfo, req *contract.Cr
|
||||
Cost: cost,
|
||||
BusinessType: businessType,
|
||||
ImageURL: req.ImageURL,
|
||||
PrinterType: req.PrinterType,
|
||||
PrinterTypes: req.PrinterTypes,
|
||||
PrintToChecker: req.PrintToChecker,
|
||||
UnitID: req.UnitID,
|
||||
SellBy: sellBy,
|
||||
@@ -91,7 +91,7 @@ func UpdateProductRequestToModel(apctx *appcontext.ContextInfo, req *contract.Up
|
||||
Price: req.Price,
|
||||
Cost: req.Cost,
|
||||
ImageURL: req.ImageURL,
|
||||
PrinterType: req.PrinterType,
|
||||
PrinterTypes: req.PrinterTypes,
|
||||
PrintToChecker: req.PrintToChecker,
|
||||
UnitID: req.UnitID,
|
||||
SellBy: req.SellBy,
|
||||
@@ -152,7 +152,7 @@ func ProductModelResponseToResponse(prod *models.ProductResponse) *contract.Prod
|
||||
Cost: prod.Cost,
|
||||
BusinessType: string(prod.BusinessType),
|
||||
ImageURL: prod.ImageURL,
|
||||
PrinterType: prod.PrinterType,
|
||||
PrinterTypes: prod.PrinterTypes,
|
||||
PrintToChecker: prod.PrintToChecker,
|
||||
UnitID: prod.UnitID,
|
||||
SellBy: prod.SellBy,
|
||||
|
||||
Reference in New Issue
Block a user