chore: build
ci-api / test (push) Failing after 8m7s
ci-web / test (push) Failing after 5m5s

This commit is contained in:
Xor290
2026-09-20 12:18:33 +02:00
parent 8f4c7fa47a
commit 919c807004
174 changed files with 9669 additions and 1308 deletions
+25 -40
View File
@@ -42,23 +42,22 @@ func (r *fakeRepository) FindByID(_ context.Context, id uuid.UUID) (*orders.Orde
return o, r.items[id], nil
}
func (r *fakeRepository) List(_ context.Context, status string) ([]*orders.Order, error) {
func (r *fakeRepository) List(_ context.Context) ([]*orders.Order, error) {
var list []*orders.Order
for _, o := range r.orders {
if status == "" || o.Status == status {
list = append(list, o)
}
list = append(list, o)
}
return list, nil
}
func (r *fakeRepository) UpdateStatus(_ context.Context, id uuid.UUID, status string) (*orders.Order, error) {
o, ok := r.orders[id]
if !ok {
return nil, orders.ErrNotFound
func (r *fakeRepository) ListByCustomer(_ context.Context, customerID uuid.UUID) ([]*orders.Order, error) {
var list []*orders.Order
for _, o := range r.orders {
if o.CustomerID != nil && *o.CustomerID == customerID {
list = append(list, o)
}
}
o.Status = status
return o, nil
return list, nil
}
// fakeProducts / fakeUnits / fakePrices back the small consumer-defined
@@ -103,18 +102,13 @@ func (f *fakePrices) PriceForQuantity(_ context.Context, tierID uuid.UUID, multi
}
type fakeNotifier struct {
newOrderCalls []string
statusChangeCalls []string
newOrderCalls []string
}
func (f *fakeNotifier) NotifyNewOrder(_ context.Context, summary string) {
f.newOrderCalls = append(f.newOrderCalls, summary)
}
func (f *fakeNotifier) NotifyOrderStatusChange(_ context.Context, summary string) {
f.statusChangeCalls = append(f.statusChangeCalls, summary)
}
// testFixture wires a full set of fakes with one product/unit/tier, ready
// for a service under test.
type testFixture struct {
@@ -137,7 +131,7 @@ func newFixture() *testFixture {
return &testFixture{
repo: newFakeRepository(),
products: &fakeProducts{byID: map[uuid.UUID]*products.Product{
productID: {ID: productID, Name: "Honey jar", Slug: "honey-jar", IsActive: true},
productID: {ID: productID, Name: "Honey jar", IsActive: true},
}},
units: &fakeUnits{byID: map[uuid.UUID]*units.Unit{
unitID: {ID: unitID, Name: "Kilogram", Symbol: "kg"},
@@ -173,9 +167,6 @@ func TestService_Create_ComputesTotalAndNotifies(t *testing.T) {
if order.TotalCents != 9000 {
t.Fatalf("Create() order.TotalCents = %d, want 9000 (2x 4500)", order.TotalCents)
}
if order.Status != orders.StatusPending {
t.Fatalf("Create() order.Status = %q, want %q", order.Status, orders.StatusPending)
}
if len(items) != 1 || items[0].ProductName != "Honey jar" || items[0].UnitSymbol != "kg" {
t.Fatalf("Create() items = %+v, want snapshot of product name/unit symbol", items)
}
@@ -199,7 +190,7 @@ func TestService_Create_RejectsTierProductMismatch(t *testing.T) {
svc := f.service()
otherProduct := uuid.New()
f.products.byID[otherProduct] = &products.Product{ID: otherProduct, Name: "Other", Slug: "other", IsActive: true}
f.products.byID[otherProduct] = &products.Product{ID: otherProduct, Name: "Other", IsActive: true}
_, _, err := svc.Create(context.Background(), orders.CreateInput{
CustomerName: "Alice",
@@ -214,31 +205,25 @@ func TestService_Create_RejectsTierProductMismatch(t *testing.T) {
}
}
func TestService_UpdateStatus_ValidatesStatus(t *testing.T) {
func TestService_List_ReturnsAllOrders(t *testing.T) {
f := newFixture()
svc := f.service()
order, _, err := svc.Create(context.Background(), orders.CreateInput{
CustomerName: "Alice",
CustomerEmail: "alice@example.com",
Items: []orders.ItemInput{{ProductID: f.productID, PriceTierID: f.tierID, Multiplier: 1}},
})
if err != nil {
t.Fatalf("Create() error = %v", err)
for range 2 {
if _, _, err := svc.Create(context.Background(), orders.CreateInput{
CustomerName: "Alice",
CustomerEmail: "alice@example.com",
Items: []orders.ItemInput{{ProductID: f.productID, PriceTierID: f.tierID, Multiplier: 1}},
}); err != nil {
t.Fatalf("Create() error = %v", err)
}
}
if _, err := svc.UpdateStatus(context.Background(), order.ID, "not-a-real-status"); !errors.Is(err, orders.ErrInvalidStatus) {
t.Fatalf("UpdateStatus() error = %v, want ErrInvalidStatus", err)
}
updated, err := svc.UpdateStatus(context.Background(), order.ID, orders.StatusConfirmed)
list, err := svc.List(context.Background())
if err != nil {
t.Fatalf("UpdateStatus() error = %v", err)
t.Fatalf("List() error = %v", err)
}
if updated.Status != orders.StatusConfirmed {
t.Fatalf("UpdateStatus() status = %q, want %q", updated.Status, orders.StatusConfirmed)
}
if len(f.notifier.statusChangeCalls) != 1 {
t.Fatalf("UpdateStatus() triggered %d status-change notifications, want exactly 1", len(f.notifier.statusChangeCalls))
if len(list) != 2 {
t.Fatalf("List() returned %d orders, want 2", len(list))
}
}