(t *testing.T)
| 14557 | } |
| 14558 | |
| 14559 | func TestChatHasUnread(t *testing.T) { |
| 14560 | t.Parallel() |
| 14561 | |
| 14562 | store, _ := dbtestutil.NewDB(t) |
| 14563 | ctx := context.Background() |
| 14564 | |
| 14565 | org := dbgen.Organization(t, store, database.Organization{}) |
| 14566 | user := dbgen.User(t, store, database.User{}) |
| 14567 | dbgen.OrganizationMember(t, store, database.OrganizationMember{UserID: user.ID, OrganizationID: org.ID}) |
| 14568 | |
| 14569 | dbgen.ChatProvider(t, store, database.ChatProvider{ |
| 14570 | Provider: "openai", |
| 14571 | DisplayName: "OpenAI", |
| 14572 | APIKey: "test-key", |
| 14573 | Enabled: true, |
| 14574 | CentralApiKeyEnabled: true, |
| 14575 | }) |
| 14576 | |
| 14577 | modelCfg, err := insertChatModelConfigForTest(ctx, t, store, database.InsertChatModelConfigParams{ |
| 14578 | Provider: "openai", |
| 14579 | Model: "test-model-" + uuid.NewString(), |
| 14580 | DisplayName: "Test Model", |
| 14581 | CreatedBy: uuid.NullUUID{UUID: user.ID, Valid: true}, |
| 14582 | UpdatedBy: uuid.NullUUID{UUID: user.ID, Valid: true}, |
| 14583 | Enabled: true, |
| 14584 | IsDefault: true, |
| 14585 | ContextLimit: 128000, |
| 14586 | CompressionThreshold: 80, |
| 14587 | Options: json.RawMessage(`{}`), |
| 14588 | }) |
| 14589 | require.NoError(t, err) |
| 14590 | |
| 14591 | chat, err := store.InsertChat(ctx, database.InsertChatParams{ |
| 14592 | OrganizationID: org.ID, |
| 14593 | Status: database.ChatStatusWaiting, |
| 14594 | ClientType: database.ChatClientTypeUi, |
| 14595 | OwnerID: user.ID, |
| 14596 | LastModelConfigID: modelCfg.ID, |
| 14597 | Title: "test-chat-" + uuid.NewString(), |
| 14598 | }) |
| 14599 | require.NoError(t, err) |
| 14600 | |
| 14601 | getHasUnread := func() bool { |
| 14602 | rows, err := store.GetChats(ctx, database.GetChatsParams{ |
| 14603 | OwnedOnly: true, |
| 14604 | ViewerID: user.ID, |
| 14605 | }) |
| 14606 | require.NoError(t, err) |
| 14607 | for _, row := range rows { |
| 14608 | if row.Chat.ID == chat.ID { |
| 14609 | return row.HasUnread |
| 14610 | } |
| 14611 | } |
| 14612 | t.Fatal("chat not found in GetChats result") |
| 14613 | return false |
| 14614 | } |
| 14615 | |
| 14616 | // New chat with no messages: not unread. |
nothing calls this directly
no test coverage detected