package archied import ( "context" "errors" "log/slog" "testing" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "github.com/samcharles93/archie-core/internal/domain/workflow/task" ) type outcomeStore struct{ posted []int64 } func (s *outcomeStore) UnpostedOutcomes(context.Context) ([]*task.Task, error) { return []*task.Task{{ID: 7, Origin: "web:chat-1"}}, nil } func (s *outcomeStore) MarkOutcomePosted(_ context.Context, id int64) error { s.posted = append(s.posted, id) return nil } func TestPostPendingOutcomes(t *testing.T) { tests := []struct { name string err error posted bool }{ {"delivered", nil, true}, {"no such channel", status.Error(codes.NotFound, "messaging: no such channel"), true}, {"channel stopped", status.Error(codes.FailedPrecondition, "messaging: channel unavailable"), false}, {"messaging down", errors.New("connection refused"), false}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { store := &outcomeStore{} deliver := func(context.Context, string, string, string) error { return tt.err } postPendingOutcomes(context.Background(), store, deliver, slog.New(slog.DiscardHandler)) if got := len(store.posted) == 1; got != tt.posted { t.Fatalf("posted = %v, want %v", got, tt.posted) } }) } }