mirror of
https://github.com/Govor-team/Govor.git
synced 2026-11-18 13:24:59 +00:00
Expose chat read positions and E2EE errors
Add optional chat activity and read-position details to the unread-count endpoint. Return stable E2EE rejection codes for stale timestamps and untrusted signing devices, with tests for both behaviors.
This commit is contained in:
@@ -10,6 +10,34 @@ namespace Govor.Application.Tests.Integration.Messages;
|
||||
[TestFixture]
|
||||
public class ReadBoundaryTests
|
||||
{
|
||||
[Test]
|
||||
public async Task ActivityAndReadingPositionIncludeOutgoingWithoutSkippingUnreadIncoming()
|
||||
{
|
||||
using var db = new TestDatabase();
|
||||
var reader = new MessageReadingService(db.Context, NullLogger<MessageReadingService>.Instance,
|
||||
Mock.Of<INowDateTimeProvider>(c => c.Now == DateTime.UtcNow.Date));
|
||||
var first = db.AddMessage(sender: db.Bob);
|
||||
var incoming = db.AddMessage(sender: db.Alice);
|
||||
var last = db.AddMessage(sender: db.Bob);
|
||||
first.SentAt = DateTime.UtcNow.AddMinutes(-3);
|
||||
incoming.SentAt = first.SentAt.AddMinutes(1);
|
||||
last.SentAt = first.SentAt.AddMinutes(2);
|
||||
await db.Context.SaveChangesAsync();
|
||||
|
||||
var before = (await reader.GetChatActivityAsync(db.Bob, db.ChatId, RecipientType.User, true)).Value;
|
||||
Assert.That(before.LastMessageAt, Is.EqualTo(last.SentAt));
|
||||
Assert.That(before.UnreadCount, Is.EqualTo(1));
|
||||
Assert.That(before.LastReadMessageId, Is.EqualTo(first.Id));
|
||||
Assert.That(before.FirstUnreadMessageId, Is.EqualTo(incoming.Id));
|
||||
Assert.That((await reader.GetChatActivityAsync(db.Outsider, db.ChatId, RecipientType.User, true)).IsFailure, Is.True);
|
||||
|
||||
await reader.ReadChatAsync(db.Bob, db.ChatId, RecipientType.User, upToMessageId: last.Id);
|
||||
var after = (await reader.GetChatActivityAsync(db.Bob, db.ChatId, RecipientType.User, true)).Value;
|
||||
Assert.That(after.UnreadCount, Is.Zero);
|
||||
Assert.That(after.LastReadMessageId, Is.EqualTo(last.Id));
|
||||
Assert.That(after.FirstUnreadMessageId, Is.Null);
|
||||
Assert.That(await db.Context.MessageViews.Select(v => v.MessageId).SingleAsync(), Is.EqualTo(incoming.Id));
|
||||
}
|
||||
[Test]
|
||||
public async Task EmptyChatReturnsZeroAndMissingBoundaryDoesNotCreateReceipts()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user