Files
backend_fiesta/repositories/orderOutlet_test.go

63 lines
2.1 KiB
Go

package repositories
import (
"strings"
"testing"
)
// The block that stopped orders being placed: no outlet on the order.
//
// Stock is per-outlet, so a missing locationid read as zero available and the
// order was refused as "insufficient stock" — for Cadbury Dairy Milk at Suriya
// Peelamedu, which had 25 on the shelf. These pin the message on the actual
// cause.
func TestAnOrderWithNoOutletIsRefusedForTheRightReason(t *testing.T) {
err := assertOutletNamed([]stockLine{
{Productid: 7086, Productname: "Cadbury Dairy Milk 100g", Locationid: 0, Quantity: 1},
})
if err == nil {
t.Fatal("an order with no outlet was accepted")
}
if strings.Contains(strings.ToLower(err.Error()), "insufficient stock") {
t.Errorf("still blames the stock: %v", err)
}
if !strings.Contains(err.Error(), "locationid") {
t.Errorf("does not say what to send: %v", err)
}
if !strings.Contains(err.Error(), "Cadbury Dairy Milk 100g") {
t.Errorf("does not name the line: %v", err)
}
}
// One good line does not excuse a bad one — a mixed order would deduct part of
// the basket at a real outlet and the rest at nowhere.
func TestOneLineWithoutAnOutletFailsTheWholeOrder(t *testing.T) {
err := assertOutletNamed([]stockLine{
{Productid: 7086, Productname: "Dairy Milk", Locationid: 1170},
{Productid: 7085, Productname: "5 Star", Locationid: 0},
})
if err == nil {
t.Fatal("a mixed order was accepted")
}
if !strings.Contains(err.Error(), "5 Star") {
t.Errorf("blamed the wrong line: %v", err)
}
}
func TestAnOrderThatNamesItsOutletPasses(t *testing.T) {
if err := assertOutletNamed([]stockLine{
{Productid: 7086, Productname: "Dairy Milk", Locationid: 1170},
}); err != nil {
t.Errorf("a valid order was refused: %v", err)
}
}
// An unnamed product still has to produce a usable message — the id is all
// there is to go on.
func TestAnUnnamedLineIsIdentifiedById(t *testing.T) {
err := assertOutletNamed([]stockLine{{Productid: 7086, Locationid: 0}})
if err == nil || !strings.Contains(err.Error(), "7086") {
t.Errorf("want the product id in the message, got: %v", err)
}
}