(t *testing.T)
| 9667 | } |
| 9668 | |
| 9669 | func TestPostChatFile(t *testing.T) { |
| 9670 | t.Parallel() |
| 9671 | |
| 9672 | t.Run("Success/PNG", func(t *testing.T) { |
| 9673 | t.Parallel() |
| 9674 | ctx := testutil.Context(t, testutil.WaitLong) |
| 9675 | client := newChatClient(t) |
| 9676 | firstUser := coderdtest.CreateFirstUser(t, client.Client) |
| 9677 | |
| 9678 | // Valid PNG header + padding. |
| 9679 | data := append([]byte{0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}, make([]byte, 64)...) |
| 9680 | resp, err := client.UploadChatFile(ctx, firstUser.OrganizationID, "image/png", "test.png", bytes.NewReader(data)) |
| 9681 | require.NoError(t, err) |
| 9682 | require.NotEqual(t, uuid.Nil, resp.ID) |
| 9683 | }) |
| 9684 | |
| 9685 | t.Run("MissingFilename", func(t *testing.T) { |
| 9686 | t.Parallel() |
| 9687 | ctx := testutil.Context(t, testutil.WaitLong) |
| 9688 | client := newChatClient(t) |
| 9689 | firstUser := coderdtest.CreateFirstUser(t, client.Client) |
| 9690 | |
| 9691 | data := append([]byte{0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}, make([]byte, 64)...) |
| 9692 | _, err := client.UploadChatFile(ctx, firstUser.OrganizationID, "image/png", "", bytes.NewReader(data)) |
| 9693 | sdkErr := requireSDKError(t, err, http.StatusBadRequest) |
| 9694 | require.Contains(t, sdkErr.Message, "Filename is required") |
| 9695 | require.Contains(t, sdkErr.Detail, "Content-Disposition") |
| 9696 | }) |
| 9697 | |
| 9698 | t.Run("Success/TextPlain", func(t *testing.T) { |
| 9699 | t.Parallel() |
| 9700 | ctx := testutil.Context(t, testutil.WaitLong) |
| 9701 | client := newChatClient(t) |
| 9702 | firstUser := coderdtest.CreateFirstUser(t, client.Client) |
| 9703 | |
| 9704 | data := []byte(`This is a test paste. |
| 9705 | With multiple lines. |
| 9706 | `) |
| 9707 | resp, err := client.UploadChatFile(ctx, firstUser.OrganizationID, "text/plain", "test.txt", bytes.NewReader(data)) |
| 9708 | require.NoError(t, err) |
| 9709 | require.NotEqual(t, uuid.Nil, resp.ID) |
| 9710 | }) |
| 9711 | |
| 9712 | t.Run("Success/TextPlainRefinesToJSON", func(t *testing.T) { |
| 9713 | t.Parallel() |
| 9714 | ctx := testutil.Context(t, testutil.WaitLong) |
| 9715 | client := newChatClient(t) |
| 9716 | firstUser := coderdtest.CreateFirstUser(t, client.Client) |
| 9717 | |
| 9718 | resp, err := client.UploadChatFile(ctx, firstUser.OrganizationID, "text/plain", "pasted-text.txt", bytes.NewReader([]byte(`{"ok":true}`))) |
| 9719 | require.NoError(t, err) |
| 9720 | require.NotEqual(t, uuid.Nil, resp.ID) |
| 9721 | }) |
| 9722 | |
| 9723 | t.Run("Success/TextPlainRefinesToCSV", func(t *testing.T) { |
| 9724 | t.Parallel() |
| 9725 | ctx := testutil.Context(t, testutil.WaitLong) |
| 9726 | client := newChatClient(t) |
nothing calls this directly
no test coverage detected