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

35 lines
912 B
Go
Raw 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 crm
import (
"context"
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
"testing"
"apps/backend/internal/domain"
crmDomain "apps/backend/internal/module/crm/domain"
"apps/backend/internal/response"
)
// notReady envelope 契約:殘留未實作 capability 須 501不可 102000 空成功。
func TestNotReadyEnvelope(t *testing.T) {
err := notReady("example.capability")
if !errors.Is(err, crmDomain.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")
}
}