server_save_default_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
12// recipes.SAVE.2-3 tools.SAVE_RECIPE_TOOL.3
13func TestCallToolACIDRecipesSave2_3DefaultsPreparedPortionsToOne(t *testing.T) {
14	backend := &fakeBackend{saveRecipeID: testRecipeID}
15	server := NewServer(backend, "test")
16
17	_, output, err := server.callSaveRecipeTool(
18		context.Background(),
19		nil,
20		SaveRecipeArguments{Source: "prepared", Title: "Pasta", Markdown: "# Pasta\n\n1. Boil pasta."},
21	)
22	if err != nil {
23		t.Fatalf("callSaveRecipeTool() error = %v", err)
24	}
25
26	if backend.saveCalls != 1 {
27		t.Fatalf("save calls = %d, want 1", backend.saveCalls)
28	}
29	if backend.savePortions != 1 {
30		t.Fatalf("backend save portions = %g, want default 1", backend.savePortions)
31	}
32	if output.RecipeID != testRecipeID {
33		t.Fatalf("save output recipe ID = %q, want test recipe ID", output.RecipeID)
34	}
35}
36
37// recipes.SAVE.8-3 tools.SAVE_RECIPE_TOOL.6
38func TestCallToolACIDRecipesSave8_3DefaultsExistingPortionsToOne(t *testing.T) {
39	backend := &fakeBackend{}
40	server := NewServer(backend, "test")
41
42	_, output, err := server.callSaveRecipeTool(
43		context.Background(),
44		nil,
45		SaveRecipeArguments{Source: "existing", RecipeID: testRecipeID, Markdown: "# Pasta\n\n1. Boil pasta."},
46	)
47	if err != nil {
48		t.Fatalf("callSaveRecipeTool() error = %v", err)
49	}
50
51	if backend.updateCalls != 1 {
52		t.Fatalf("update calls = %d, want 1", backend.updateCalls)
53	}
54	if backend.updatePortions != 1 {
55		t.Fatalf("backend update portions = %g, want default 1", backend.updatePortions)
56	}
57	if output.RecipeID != testRecipeID {
58		t.Fatalf("save output recipe ID = %q, want test recipe ID", output.RecipeID)
59	}
60}