Fix MAX attachment send and self push echoes
This commit is contained in:
@@ -666,6 +666,77 @@ public sealed class ApiSmokeTests : IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task SyncDoesNotPushListPreviewEchoOfOwnOutgoingAttachment()
|
||||
{
|
||||
var pushNotifications = new RecordingPushNotificationService();
|
||||
var bridge = new OutgoingPreviewEchoMaxBridgeClient(
|
||||
$"mock-self-echo-attachment-chat-{Guid.NewGuid():N}",
|
||||
"\u0424\u043e\u0442\u043e");
|
||||
using var factory = _factory.WithWebHostBuilder(builder =>
|
||||
{
|
||||
builder.ConfigureTestServices(services =>
|
||||
{
|
||||
services.RemoveAll<IHostedService>();
|
||||
services.RemoveAll<IMaxBridgeClient>();
|
||||
services.RemoveAll<IPushNotificationService>();
|
||||
services.AddSingleton<IMaxBridgeClient>(bridge);
|
||||
services.AddSingleton<IPushNotificationService>(pushNotifications);
|
||||
});
|
||||
});
|
||||
using var client = factory.CreateClient();
|
||||
await LoginAsync(client);
|
||||
|
||||
Guid chatId;
|
||||
var sentAt = DateTimeOffset.UtcNow.AddSeconds(-20);
|
||||
using (var scope = factory.Services.CreateScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<QMaxDbContext>();
|
||||
var chat = new Chat
|
||||
{
|
||||
ExternalId = bridge.ChatExternalId,
|
||||
Title = "Self Attachment Echo",
|
||||
LastMessagePreview = "\u041c\u0435\u0434\u0438\u0430",
|
||||
LastMessageAt = sentAt,
|
||||
UnreadCount = 0
|
||||
};
|
||||
var message = new Message
|
||||
{
|
||||
Chat = chat,
|
||||
ExternalId = "self-echo-attachment-message",
|
||||
Direction = MessageDirection.Outgoing,
|
||||
SentAt = sentAt,
|
||||
DeliveryState = MessageDeliveryState.Sent
|
||||
};
|
||||
message.Attachments.Add(new MessageAttachment
|
||||
{
|
||||
Message = message,
|
||||
OriginalFileName = "sent-photo.jpg",
|
||||
StorageFileName = "sent-photo.jpg",
|
||||
ContentType = "image/jpeg",
|
||||
FileSizeBytes = 1024,
|
||||
Kind = AttachmentKind.Image
|
||||
});
|
||||
db.Chats.Add(chat);
|
||||
db.Messages.Add(message);
|
||||
await db.SaveChangesAsync();
|
||||
chatId = chat.Id;
|
||||
}
|
||||
|
||||
var sync = await client.PostAsync("/api/max/sync", null);
|
||||
await AssertStatusAsync(HttpStatusCode.OK, sync);
|
||||
|
||||
Assert.Empty(pushNotifications.SentMessages);
|
||||
using (var scope = factory.Services.CreateScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<QMaxDbContext>();
|
||||
var chat = await db.Chats.FindAsync(chatId);
|
||||
Assert.NotNull(chat);
|
||||
Assert.Equal(0, chat!.UnreadCount);
|
||||
Assert.Equal("\u041c\u0435\u0434\u0438\u0430", chat.LastMessagePreview);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task FirebasePushSkipsOutgoingMessages()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user