Skip to content

Commit

Permalink
Add TestDeleteEmptyChats()
Browse files Browse the repository at this point in the history
  • Loading branch information
hsluoyz committed Mar 3, 2024
1 parent 26c7c0e commit d434386
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
21 changes: 21 additions & 0 deletions object/chat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package object

import (
"fmt"
"testing"

"github.com/casibase/casibase/model"
Expand Down Expand Up @@ -95,6 +96,26 @@ func TestUpdateMessageTokens(t *testing.T) {
}
}

func TestDeleteEmptyChats(t *testing.T) {
InitConfig()

chats, err := GetGlobalChats()
if err != nil {
panic(err)
}

for i, chat := range chats {
if chat.MessageCount == 0 {
_, err = DeleteChat(chat)
if err != nil {
panic(err)
}

fmt.Printf("[%d/%d] deleted chat: %s, user: %s, clientIP: %s (%s), userAgent: %s (%s)\n", i+1, len(chats), chat.Name, chat.User, chat.ClientIpDesc, chat.ClientIp, chat.UserAgentDesc, chat.UserAgent)
}
}
}

func TestUpdateChatDescs(t *testing.T) {
InitConfig()
util.InitIpDb()
Expand Down
6 changes: 6 additions & 0 deletions object/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,9 @@ func TestUpdateMessages(t *testing.T) {
}
}
}

func TestUpdateMessagesAndChats(t *testing.T) {
TestUpdateMessages(t)
TestUpdateMessageCounts(t)
TestUpdateMessageTokens(t)
}

0 comments on commit d434386

Please sign in to comment.