droboticflow/internal/api/workforce_publication_test.go
d-robotics fc7786190f
Some checks are pending
web-ci / checks (push) Waiting to run
web-ci / pool-search-mongo (push) Waiting to run
web-ci / work-availability (push) Blocked by required conditions
web-ci / query-serving (push) Blocked by required conditions
⚡ Publish query reports and coalesce task pool reads
2026-11-13 22:31:44 -08:00

32 lines
1.2 KiB
Go

package api
import (
"errors"
"fmt"
"net/http"
"net/http/httptest"
"testing"
"droboticflow/internal/store"
)
func TestWorkforcePublicationPendingIsNotAnEmptyReport(t *testing.T) {
r := httptest.NewRequest(http.MethodGet, "/report", nil)
r.Header.Set("Accept", "application/vnd.droboticflow.prepared+json")
w := httptest.NewRecorder()
if !renderWorkforcePublicationPending(w, r, fmt.Errorf("report: %w", store.ErrWorkforcePublicationPending)) || w.Code != http.StatusAccepted || w.Header().Get("Retry-After") != "1" {
t.Fatalf("publication readiness response: %d %s", w.Code, w.Body.String())
}
legacy := httptest.NewRecorder()
if !renderWorkforcePublicationPending(legacy, httptest.NewRequest(http.MethodGet, "/report", nil), store.ErrWorkforcePublicationPending) || legacy.Code != http.StatusServiceUnavailable {
t.Fatal("legacy client received a successful non-report body")
}
for _, err := range []error{nil, store.ErrQueryReplicaNotReady, errors.New("permission denied")} {
w = httptest.NewRecorder()
if renderWorkforcePublicationPending(w, r, err) || w.Body.Len() != 0 {
t.Fatal("unrelated errors must retain their existing handling")
}
}
}