Feature 13 integration fix: deck error surfacing, active-batch tracking, modal key scope, three-card deck (#111)
Co-authored-by: orchestrator-agent <20+orchestrator-agent@code.cubecraftcreations.com>
This commit was merged in pull request #111.
This commit is contained in:
@@ -10,10 +10,6 @@ import (
|
||||
"code.cubecraftlabs.com/Maniacs_Mansion/Meal-Quest/internal/suggest"
|
||||
)
|
||||
|
||||
type deck struct {
|
||||
Suggestions []suggest.Suggestion `json:"suggestions"`
|
||||
}
|
||||
|
||||
// postSuggestionBatch starts a manual suggestion batch and answers 202 with
|
||||
// its batch_id and the job_id that GET /jobs/{id} reports on, without
|
||||
// waiting for the job. When a batch is already pending or running it
|
||||
@@ -30,15 +26,15 @@ func postSuggestionBatch(logger *slog.Logger, svc *suggest.Service) http.Handler
|
||||
}
|
||||
|
||||
// getSuggestionDeck answers GET /suggestions/deck with the pending
|
||||
// suggestions, oldest first.
|
||||
// suggestions, oldest first, and the batch pending or running, or null.
|
||||
func getSuggestionDeck(logger *slog.Logger, svc *suggest.Service) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
list, err := svc.Deck(r.Context())
|
||||
d, err := svc.Deck(r.Context())
|
||||
if err != nil {
|
||||
writeSuggestionError(w, r, logger, "list suggestion deck", err)
|
||||
return
|
||||
}
|
||||
writeJSON(w, r, logger, http.StatusOK, deck{Suggestions: list})
|
||||
writeJSON(w, r, logger, http.StatusOK, d)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -148,8 +148,44 @@ func TestSuggestionDecisions(t *testing.T) {
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("decline = %d: %s", rec.Code, rec.Body)
|
||||
}
|
||||
if id, _ := body["replenish_job_id"].(string); id == "" {
|
||||
t.Errorf("decline leaving 4 = %v, want a replenish_job_id", body)
|
||||
replenish, _ := body["replenish_job_id"].(string)
|
||||
if replenish == "" {
|
||||
t.Fatalf("decline leaving 4 = %v, want a replenish_job_id", body)
|
||||
}
|
||||
|
||||
// A fourth decision joins the batch already pending and reports its job.
|
||||
rec, body = callDinners(t, h, http.MethodPost, suggestionsPath+"/"+ids[3]+"/accept", "")
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("accept = %d: %s", rec.Code, rec.Body)
|
||||
}
|
||||
if body["replenish_job_id"] != replenish {
|
||||
t.Errorf("accept leaving 3 = %v, want replenish_job_id %s", body, replenish)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSuggestionDeckActiveBatch(t *testing.T) {
|
||||
t.Parallel()
|
||||
h, _, _ := newSuggestionsRouter(t, "Pho")
|
||||
|
||||
rec, body := callDinners(t, h, http.MethodGet, suggestionsPath+"/deck", "")
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("GET deck = %d: %s", rec.Code, rec.Body)
|
||||
}
|
||||
if active, ok := body["active_batch"]; !ok || active != nil {
|
||||
t.Fatalf("deck = %v, want active_batch null", body)
|
||||
}
|
||||
|
||||
rec, started := callDinners(t, h, http.MethodPost, suggestionsPath+"/batches", "")
|
||||
if rec.Code != http.StatusAccepted {
|
||||
t.Fatalf("POST batches = %d: %s", rec.Code, rec.Body)
|
||||
}
|
||||
rec, body = callDinners(t, h, http.MethodGet, suggestionsPath+"/deck", "")
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("GET deck = %d: %s", rec.Code, rec.Body)
|
||||
}
|
||||
active, _ := body["active_batch"].(map[string]any)
|
||||
if active == nil || active["batch_id"] != started["batch_id"] || active["job_id"] != started["job_id"] || active["status"] != "pending" {
|
||||
t.Errorf("deck active_batch = %v, want the started batch %v", body["active_batch"], started)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user