(t *testing.T)
| 10 | ) |
| 11 | |
| 12 | func TestNewChatMessageSendPlan(t *testing.T) { |
| 13 | home, err := os.UserHomeDir() |
| 14 | if err != nil { |
| 15 | t.Fatalf("UserHomeDir: %v", err) |
| 16 | } |
| 17 | |
| 18 | plan, err := newChatMessageSendPlan(chatMessageSendInput{ |
| 19 | Space: "AAA", |
| 20 | Text: " hello ", |
| 21 | Thread: " t1 ", |
| 22 | Attachments: []string{"~/pic.png"}, |
| 23 | }) |
| 24 | if err != nil { |
| 25 | t.Fatalf("newChatMessageSendPlan: %v", err) |
| 26 | } |
| 27 | if plan.Space != "spaces/AAA" || plan.Text != "hello" { |
| 28 | t.Fatalf("unexpected message plan: %#v", plan) |
| 29 | } |
| 30 | if plan.ThreadRaw != "t1" || plan.ThreadName != "spaces/AAA/threads/t1" { |
| 31 | t.Fatalf("unexpected thread plan: %#v", plan) |
| 32 | } |
| 33 | if len(plan.Attachments) != 1 || plan.Attachments[0] != filepath.Join(home, "pic.png") { |
| 34 | t.Fatalf("unexpected attachments: %#v", plan.Attachments) |
| 35 | } |
| 36 | if plan.replyOption() != chatReplyFallbackToNewThread { |
| 37 | t.Fatalf("replyOption() = %q", plan.replyOption()) |
| 38 | } |
| 39 | |
| 40 | attachment := &chat.Attachment{} |
| 41 | message := plan.message([]*chat.Attachment{attachment}) |
| 42 | if message.Text != "hello" || message.Thread == nil || message.Thread.Name != plan.ThreadName { |
| 43 | t.Fatalf("unexpected message: %#v", message) |
| 44 | } |
| 45 | if len(message.Attachment) != 1 || message.Attachment[0] != attachment { |
| 46 | t.Fatalf("unexpected message attachments: %#v", message.Attachment) |
| 47 | } |
| 48 | |
| 49 | payload := plan.dryRunPayload() |
| 50 | if payload["reply_fallback_to_new_thread"] != true || payload["thread"] != plan.ThreadName { |
| 51 | t.Fatalf("unexpected dry-run payload: %#v", payload) |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | func TestNewChatMessageSendPlanAttachmentOnly(t *testing.T) { |
| 56 | plan, err := newChatMessageSendPlan(chatMessageSendInput{ |
nothing calls this directly
no test coverage detected