(t *testing.T)
| 1765 | } |
| 1766 | |
| 1767 | func TestWatchChats(t *testing.T) { |
| 1768 | t.Parallel() |
| 1769 | |
| 1770 | t.Run("Success", func(t *testing.T) { |
| 1771 | t.Parallel() |
| 1772 | |
| 1773 | ctx := testutil.Context(t, testutil.WaitLong) |
| 1774 | client := newChatClient(t) |
| 1775 | firstUser := coderdtest.CreateFirstUser(t, client.Client) |
| 1776 | _ = createChatModelConfig(t, client) |
| 1777 | |
| 1778 | conn, err := client.Dial(ctx, "/api/experimental/chats/watch", nil) |
| 1779 | require.NoError(t, err) |
| 1780 | defer conn.Close(websocket.StatusNormalClosure, "done") |
| 1781 | |
| 1782 | createdChat, err := client.CreateChat(ctx, codersdk.CreateChatRequest{ |
| 1783 | OrganizationID: firstUser.OrganizationID, |
| 1784 | Content: []codersdk.ChatInputPart{ |
| 1785 | { |
| 1786 | Type: codersdk.ChatInputPartTypeText, |
| 1787 | Text: "watch route created event", |
| 1788 | }, |
| 1789 | }, |
| 1790 | }) |
| 1791 | require.NoError(t, err) |
| 1792 | |
| 1793 | for { |
| 1794 | var payload codersdk.ChatWatchEvent |
| 1795 | err = wsjson.Read(ctx, conn, &payload) |
| 1796 | require.NoError(t, err) |
| 1797 | |
| 1798 | if payload.Kind == codersdk.ChatWatchEventKindCreated && |
| 1799 | payload.Chat.ID == createdChat.ID { |
| 1800 | break |
| 1801 | } |
| 1802 | } |
| 1803 | }) |
| 1804 | t.Run("CreatedEventIncludesAllChatFields", func(t *testing.T) { |
| 1805 | t.Parallel() |
| 1806 | |
| 1807 | // This test verifies that the pubsub "created" event |
| 1808 | // carries a fully-populated codersdk.Chat. Exhaustive |
| 1809 | // field-level coverage of the converter is handled by |
| 1810 | // TestChat_AllFieldsPopulated (db2sdk) and |
| 1811 | // TestChat_JSONRoundTrip (codersdk). This integration |
| 1812 | // test only checks that key fields survive the full |
| 1813 | // API → pubsub → websocket pipeline. |
| 1814 | ctx := testutil.Context(t, testutil.WaitLong) |
| 1815 | client := newChatClient(t) |
| 1816 | firstUser := coderdtest.CreateFirstUser(t, client.Client) |
| 1817 | modelConfig := createChatModelConfig(t, client) |
| 1818 | |
| 1819 | conn, err := client.Dial(ctx, "/api/experimental/chats/watch", nil) |
| 1820 | require.NoError(t, err) |
| 1821 | defer conn.Close(websocket.StatusNormalClosure, "done") |
| 1822 | |
| 1823 | createdChat, err := client.CreateChat(ctx, codersdk.CreateChatRequest{ |
| 1824 | OrganizationID: firstUser.OrganizationID, |
nothing calls this directly
no test coverage detected