diff --git a/go/pkg/hey/entries.go b/go/pkg/hey/entries.go index 82f6556..f084852 100644 --- a/go/pkg/hey/entries.go +++ b/go/pkg/hey/entries.go @@ -3,6 +3,7 @@ package hey import ( "context" "fmt" + "strings" "time" "github.com/basecamp/hey-sdk/go/pkg/generated" @@ -73,13 +74,13 @@ func (s *EntriesService) CreateReply(ctx context.Context, entryID int64, content } addressed := map[string]any{} if len(to) > 0 { - addressed["directly"] = to + addressed["directly"] = strings.Join(to, ",") } if len(cc) > 0 { - addressed["copied"] = cc + addressed["copied"] = strings.Join(cc, ",") } if len(bcc) > 0 { - addressed["blindcopied"] = bcc + addressed["blindcopied"] = strings.Join(bcc, ",") } if len(addressed) > 0 { body["entry"] = map[string]any{ diff --git a/go/pkg/hey/messages.go b/go/pkg/hey/messages.go index df3543d..a3483ef 100644 --- a/go/pkg/hey/messages.go +++ b/go/pkg/hey/messages.go @@ -3,6 +3,7 @@ package hey import ( "context" "fmt" + "strings" "time" "github.com/basecamp/hey-sdk/go/pkg/generated" @@ -69,13 +70,13 @@ func (s *MessagesService) Create(ctx context.Context, subject, content string, t addressed := map[string]any{} if len(to) > 0 { - addressed["directly"] = to + addressed["directly"] = strings.Join(to, ",") } if len(cc) > 0 { - addressed["copied"] = cc + addressed["copied"] = strings.Join(cc, ",") } if len(bcc) > 0 { - addressed["blindcopied"] = bcc + addressed["blindcopied"] = strings.Join(bcc, ",") } body := map[string]any{ diff --git a/go/pkg/hey/services_test.go b/go/pkg/hey/services_test.go index 0915621..1daf967 100644 --- a/go/pkg/hey/services_test.go +++ b/go/pkg/hey/services_test.go @@ -437,13 +437,13 @@ func TestMessagesService_Create(t *testing.T) { if !ok { t.Fatal("missing addressed in entry") } - directly, ok := addressed["directly"].([]any) - if !ok || len(directly) != 1 || directly[0] != "test@example.com" { - t.Errorf("expected directly ['test@example.com'], got %v", addressed["directly"]) + directly, ok := addressed["directly"].(string) + if !ok || directly != "test@example.com" { + t.Errorf("expected directly 'test@example.com', got %v", addressed["directly"]) } - copied, ok := addressed["copied"].([]any) - if !ok || len(copied) != 1 || copied[0] != "cc@example.com" { - t.Errorf("expected copied ['cc@example.com'], got %v", addressed["copied"]) + copied, ok := addressed["copied"].(string) + if !ok || copied != "cc@example.com" { + t.Errorf("expected copied 'cc@example.com', got %v", addressed["copied"]) } if _, ok := addressed["blindcopied"]; ok { t.Error("expected no blindcopied key for empty bcc") @@ -512,6 +512,24 @@ func TestEntriesService_CreateReply(t *testing.T) { if msg["content"] != "My reply" { t.Errorf("expected content 'My reply', got %v", msg["content"]) } + entry, ok := body["entry"].(map[string]any) + if !ok { + t.Fatal("missing entry wrapper") + } + addressed, ok := entry["addressed"].(map[string]any) + if !ok { + t.Fatal("missing addressed in entry") + } + directly, ok := addressed["directly"].(string) + if !ok || directly != "test@example.com" { + t.Errorf("expected directly 'test@example.com', got %v", addressed["directly"]) + } + if _, ok := addressed["copied"]; ok { + t.Error("expected no copied key for nil cc") + } + if _, ok := addressed["blindcopied"]; ok { + t.Error("expected no blindcopied key for nil bcc") + } }, `{"notice":"sent"}`, )