mirror of
https://github.com/status-im/status-go.git
synced 2026-08-31 00:51:12 +00:00
Part of the Go project layout migration, item 27. Pure move plus import-path rewrite across 502 files. No API or behaviour change. `internal/` keeps the messaging application logic unimportable from outside the module, which is what the issue asks for -- status-go is consumed through the C-bindings in mobile/, not as a Go library. Things that had to follow the move, beyond the Go imports: - tools/generate-handlers/template.txt. messenger_handlers.go is generated, and the template hard-codes the imports it emits, so the generated file kept importing protocol/common and failed typecheck. - .gitignore. The ignore rule for that generated file was pinned to the old path; without moving it, a 1486-line generated file starts being tracked. - Makefile: the logosstorage and torrent test targets (both the archive packages and ./protocol itself), the archive README, migration-protocol. - scripts/run_unit_tests.sh, which names the protocol package explicitly to shard its tests. - scripts/cleanup_generated_files.sh and .golangci.yml. scripts/migration_check.sh also needed a fix that is not specific to this move: it validated every file the branch touched under a migration dir against the timestamp naming rule, and a directory rename makes every migration in it look newly added. It now excludes renames, so moving a migration is not mistaken for adding one. refs #7067
105 lines
2.6 KiB
Go
105 lines
2.6 KiB
Go
package protocol
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/suite"
|
|
|
|
"github.com/status-im/status-go/internal/db/multiaccounts"
|
|
)
|
|
|
|
func TestMessengerReplySuite(t *testing.T) {
|
|
suite.Run(t, new(MessengerReplySuite))
|
|
}
|
|
|
|
type MessengerReplySuite struct {
|
|
MessengerBaseTestSuite
|
|
}
|
|
|
|
func (s *MessengerReplySuite) TestReceiveReply() {
|
|
alice := s.m
|
|
alice.account = &multiaccounts.Account{KeyUID: "0xdeadbeef"}
|
|
|
|
bob := s.newMessenger()
|
|
|
|
chatID := statusChatID
|
|
|
|
chat := CreatePublicChat(chatID, alice.getTimesource())
|
|
|
|
err := alice.SaveChat(chat)
|
|
s.Require().NoError(err)
|
|
|
|
_, err = alice.Join(chat)
|
|
s.Require().NoError(err)
|
|
|
|
err = bob.SaveChat(chat)
|
|
s.Require().NoError(err)
|
|
|
|
_, err = bob.Join(chat)
|
|
s.Require().NoError(err)
|
|
|
|
// Send chat message from alice to bob
|
|
message := buildTestMessage(*chat)
|
|
_, err = alice.SendChatMessage(context.Background(), message)
|
|
s.NoError(err)
|
|
|
|
// Wait for message to arrive to bob
|
|
response, err := WaitOnMessengerResponse(
|
|
bob,
|
|
func(r *MessengerResponse) bool { return len(r.Messages()) > 0 },
|
|
"no messages",
|
|
)
|
|
s.Require().NoError(err)
|
|
|
|
s.Require().Len(response.Messages(), 1)
|
|
s.Require().False(response.Messages()[0].Replied)
|
|
|
|
messageID := response.Messages()[0].ID
|
|
|
|
// Bob replies to the message
|
|
replyMessage := buildTestMessage(*chat)
|
|
replyMessage.ResponseTo = messageID
|
|
_, err = bob.SendChatMessage(context.Background(), replyMessage)
|
|
s.NoError(err)
|
|
|
|
// Wait for reply to arrive to alice
|
|
response, err = WaitOnMessengerResponse(
|
|
alice,
|
|
func(r *MessengerResponse) bool { return len(r.Messages()) > 0 },
|
|
"no messages",
|
|
)
|
|
s.Require().NoError(err)
|
|
|
|
messages := response.Messages()
|
|
s.Require().Len(messages, 2)
|
|
//* Verify that the reply reponds to the original message
|
|
messageToCheck := messages[0]
|
|
if messageToCheck.ResponseTo == "" || messageToCheck.ResponseTo != messageID {
|
|
// We need to use the second message in the response. They got out of order by accident
|
|
messageToCheck = messages[1]
|
|
}
|
|
s.Require().True(messageToCheck.ResponseTo == messageID)
|
|
// Verify that it's replied
|
|
s.Require().True(messageToCheck.Replied)
|
|
}
|
|
|
|
func (s *MessengerReplySuite) TestSendReplyToNonExistentMessage() {
|
|
alice := s.m
|
|
|
|
chatID := statusChatID
|
|
chat := CreatePublicChat(chatID, alice.getTimesource())
|
|
|
|
err := alice.SaveChat(chat)
|
|
s.Require().NoError(err)
|
|
|
|
_, err = alice.Join(chat)
|
|
s.Require().NoError(err)
|
|
|
|
// Reply to a message ID that was never sent or received
|
|
replyMessage := buildTestMessage(*chat)
|
|
replyMessage.ResponseTo = "non-existent-message-id"
|
|
_, err = alice.SendChatMessage(context.Background(), replyMessage)
|
|
s.Require().ErrorIs(err, ErrInvalidResponseTo)
|
|
}
|