thread-master/apps/backend/internal/logic/radar/notready_test.go

35 lines
942 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package radar
import (
"context"
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
"testing"
"apps/backend/internal/domain"
radarDomain "apps/backend/internal/module/radar/domain"
"apps/backend/internal/response"
)
// notReady envelope 契約:若日後有殘留未實作 route 仍須回 501501010不可 102000 空成功。
func TestNotReadyEnvelope(t *testing.T) {
err := notReady("example.capability")
if !errors.Is(err, radarDomain.ErrNotReady) {
t.Fatalf("expected ErrNotReady, got %v", err)
}
rec := httptest.NewRecorder()
response.Write(context.Background(), rec, nil, err)
if rec.Code != http.StatusNotImplemented {
t.Fatalf("expected HTTP 501, got %d", rec.Code)
}
var env response.Envelope
if decErr := json.NewDecoder(rec.Body).Decode(&env); decErr != nil {
t.Fatalf("decode envelope: %v", decErr)
}
if env.Code == domain.SuccessCode {
t.Fatal("not-ready must not use success code")
}
}