From 0da5e621ac4309e9fded016d834f4022ffde082a Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 9 Jan 2023 11:38:24 -0500 Subject: [PATCH] test(persistence): improve reply test to test deleted reply --- protocol/persistence_test.go | 45 +++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 8 deletions(-) diff --git a/protocol/persistence_test.go b/protocol/persistence_test.go index ceaa9388e..e9a196e2f 100644 --- a/protocol/persistence_test.go +++ b/protocol/persistence_test.go @@ -513,7 +513,32 @@ func TestMessageReplies(t *testing.T) { From: "3", } - messages := []*common.Message{message1, message2, message3} + // Message that is deleted + message4 := &common.Message{ + ID: "id-4", + LocalChatID: chatID, + Deleted: true, + ChatMessage: protobuf.ChatMessage{ + Text: "content-4", + Clock: uint64(4), + }, + From: "2", + } + + // Message replied to a deleted message. It will not have QuotedMessage info + message5 := &common.Message{ + ID: "id-5", + LocalChatID: chatID, + ChatMessage: protobuf.ChatMessage{ + Text: "content-4", + Clock: uint64(5), + ResponseTo: "id-4", + }, + From: "3", + } + + // messages := []*common.Message{message1, message2, message3} + messages := []*common.Message{message1, message2, message3, message4, message5} err = p.SaveMessages(messages) require.NoError(t, err) @@ -521,14 +546,18 @@ func TestMessageReplies(t *testing.T) { retrievedMessages, _, err := p.MessageByChatID(chatID, "", 10) require.NoError(t, err) - require.Equal(t, "non-existing", retrievedMessages[0].ResponseTo) - require.Nil(t, retrievedMessages[0].QuotedMessage) - - require.Equal(t, "id-1", retrievedMessages[1].ResponseTo) - require.Equal(t, &common.QuotedMessage{ID: "id-1", From: "1", Text: "content-1"}, retrievedMessages[1].QuotedMessage) - - require.Equal(t, "", retrievedMessages[2].ResponseTo) + require.Equal(t, "non-existing", retrievedMessages[2].ResponseTo) require.Nil(t, retrievedMessages[2].QuotedMessage) + + require.Equal(t, "id-1", retrievedMessages[3].ResponseTo) + require.Equal(t, &common.QuotedMessage{ID: "id-1", From: "1", Text: "content-1"}, retrievedMessages[3].QuotedMessage) + + require.Equal(t, "", retrievedMessages[4].ResponseTo) + require.Nil(t, retrievedMessages[4].QuotedMessage) + + // We have a ResponseTo, but no QuotedMessage, since the message was deleted + require.Equal(t, "id-4", retrievedMessages[0].ResponseTo) + require.Nil(t, retrievedMessages[0].QuotedMessage) } func TestMessageByChatIDWithTheSameClocks(t *testing.T) {