chore: extend `TestRetrieveBlockedContact`
Extended test with unblock scenario.
This commit is contained in:
parent
4f5a25befa
commit
b5887c9c60
|
@ -701,14 +701,16 @@ func (s *MessengerSuite) TestRetrieveBlockedContact() {
|
||||||
theirMessenger := s.newMessenger(s.shh)
|
theirMessenger := s.newMessenger(s.shh)
|
||||||
_, err := theirMessenger.Start()
|
_, err := theirMessenger.Start()
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
theirChat := CreatePublicChat("status", s.m.transport)
|
theirChat := CreatePublicChat("status", s.m.transport)
|
||||||
err = theirMessenger.SaveChat(theirChat)
|
err = theirMessenger.SaveChat(theirChat)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
_, err = theirMessenger.Join(theirChat)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
chat := CreatePublicChat("status", s.m.transport)
|
chat := CreatePublicChat("status", s.m.transport)
|
||||||
err = s.m.SaveChat(chat)
|
err = s.m.SaveChat(chat)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
_, err = s.m.Join(chat)
|
_, err = s.m.Join(chat)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
@ -717,22 +719,50 @@ func (s *MessengerSuite) TestRetrieveBlockedContact() {
|
||||||
ID: publicKeyHex,
|
ID: publicKeyHex,
|
||||||
EnsName: "contact-name",
|
EnsName: "contact-name",
|
||||||
LastUpdated: 20,
|
LastUpdated: 20,
|
||||||
Blocked: true,
|
Blocked: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
requireMessageArrival := func(receiver *Messenger, require bool) {
|
||||||
|
// Wait for the message to reach its destination
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
response, err := receiver.RetrieveAll()
|
||||||
|
s.Require().NoError(err)
|
||||||
|
if require {
|
||||||
|
s.Require().Len(response.Messages(), 1)
|
||||||
|
} else {
|
||||||
|
s.Require().Len(response.Messages(), 0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Block contact
|
||||||
_, err = s.m.BlockContact(blockedContact.ID)
|
_, err = s.m.BlockContact(blockedContact.ID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
inputMessage := buildTestMessage(*chat)
|
// Blocked contact sends message, we should not receive it
|
||||||
|
theirMessage := buildTestMessage(*theirChat)
|
||||||
_, err = theirMessenger.SendChatMessage(context.Background(), inputMessage)
|
_, err = theirMessenger.SendChatMessage(context.Background(), theirMessage)
|
||||||
s.NoError(err)
|
s.NoError(err)
|
||||||
|
requireMessageArrival(s.m, false)
|
||||||
|
|
||||||
// Wait for the message to reach its destination
|
// We send a message, blocked contact should still receive it
|
||||||
time.Sleep(100 * time.Millisecond)
|
ourMessage := buildTestMessage(*chat)
|
||||||
response, err := s.m.RetrieveAll()
|
_, err = s.m.SendChatMessage(context.Background(), ourMessage)
|
||||||
|
s.NoError(err)
|
||||||
|
requireMessageArrival(theirMessenger, true)
|
||||||
|
|
||||||
|
// Unblock contact
|
||||||
|
err = s.m.UnblockContact(blockedContact.ID)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Len(response.Messages(), 0)
|
|
||||||
|
// Unblocked contact sends message, we should receive it
|
||||||
|
_, err = theirMessenger.SendChatMessage(context.Background(), theirMessage)
|
||||||
|
s.Require().NoError(err)
|
||||||
|
requireMessageArrival(s.m, true)
|
||||||
|
|
||||||
|
// We send a message, unblocked contact should receive it
|
||||||
|
_, err = s.m.SendChatMessage(context.Background(), ourMessage)
|
||||||
|
s.NoError(err)
|
||||||
|
requireMessageArrival(theirMessenger, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Resend their public message, receive only once
|
// Resend their public message, receive only once
|
||||||
|
|
Loading…
Reference in New Issue