Private
Public Access
1
0

server: implements /markConversation

This commit is contained in:
2023-07-19 12:10:25 -06:00
parent 1fce2c7cb3
commit b77020e23c
3 changed files with 88 additions and 6 deletions

View File

@@ -299,3 +299,46 @@ func TestUpdates(t *testing.T) {
t.Fatalf("Unexpected message text: %s (expected %s)", update.Message.Text, message.Text)
}
}
func TestMarkConversation(t *testing.T) {
s := web.NewMockHTTPServer(web.MockHTTPServerConfiguration{AuthEnabled: true})
httpServer := httptest.NewServer(s)
// Mock conversation
guid := "1234567890"
conversation := model.Conversation{
Date: time.Now(),
Participants: []string{"Alice"},
UnreadCount: 0,
Guid: guid,
}
s.Server.AddConversation(conversation)
// Receive message to mark as unread
message := model.Message{
Text: "This is a test.",
Sender: &conversation.Participants[0],
Date: time.Now(),
}
s.Server.ReceiveMessage(&conversation, message)
if convo, _ := s.Server.ConversationForGUID(guid); convo.UnreadCount != 1 {
t.Fatalf("Unexpected unread count: %d (expected %d)", convo.UnreadCount, 1)
}
// Mark conversation as read
resp, err := http.Post(httpServer.URL+"/markConversation?guid="+guid, "", nil)
if err != nil {
t.Fatalf("TestMarkConversation error: %s", err)
}
if resp.StatusCode != http.StatusOK {
t.Fatalf("Unexpected status code: %d (expected %d)", resp.StatusCode, http.StatusOK)
}
if convo, _ := s.Server.ConversationForGUID(guid); convo.UnreadCount != 0 {
t.Fatalf("Unexpected unread count: %d (expected %d)", convo.UnreadCount, 0)
}
}