server_test.go

 1// SPDX-FileCopyrightText: Amolith <amolith@secluded.site>
 2//
 3// SPDX-License-Identifier: LicenseRef-MutuaL-1.2
 4
 5package mcp
 6
 7import (
 8	"context"
 9	"testing"
10
11	"git.secluded.site/cooked-mcp/internal/cooked"
12)
13
14func TestCallToolACIDToolsSurface1ReadsShoppingList(t *testing.T) {
15	backend := fakeBackend{shoppingList: cooked.ShoppingList{
16		Aisles: []cooked.Aisle{{
17			ID:   "pantry",
18			Name: "Pantry",
19			ProductGroups: []cooked.ProductGroup{{
20				ID:       "pasta",
21				Name:     "Pasta",
22				Quantity: "200g",
23			}},
24		}},
25	}}
26	server := NewServer(backend, "test")
27
28	output, err := server.CallReadTool(context.Background(), ReadArguments{Target: "shopping_list"})
29	if err != nil {
30		t.Fatalf("CallReadTool() error = %v", err)
31	}
32
33	if len(output.Aisles) != 1 {
34		t.Fatalf("structured aisles = %d, want 1", len(output.Aisles))
35	}
36	if output.Aisles[0].ProductGroups[0].Name != "Pasta" {
37		t.Fatalf("first item = %q, want Pasta", output.Aisles[0].ProductGroups[0].Name)
38	}
39}
40
41type fakeBackend struct {
42	shoppingList cooked.ShoppingList
43}
44
45func (f fakeBackend) ReadShoppingList(context.Context) (cooked.ShoppingList, error) {
46	return f.shoppingList, nil
47}