Fix emoji sending and self push notifications

This commit is contained in:
sevenhill
2026-07-04 21:47:06 +03:00
parent b3192d793d
commit 3e3d1538eb
4 changed files with 248 additions and 8 deletions
+64
View File
@@ -5,10 +5,12 @@ using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.TestHost;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using QMax.Api.Configuration;
using QMax.Api.Contracts;
@@ -602,6 +604,60 @@ public sealed class ApiSmokeTests : IDisposable
Assert.Equal("hello ????", MessageTextSanitizer.CleanChatPreview("hello ????"));
}
[Fact]
public async Task FirebasePushSkipsOutgoingMessages()
{
var databasePath = Path.Combine(Path.GetTempPath(), $"qmax-push-test-{Guid.NewGuid():N}.db");
try
{
var dbOptions = new DbContextOptionsBuilder<QMaxDbContext>()
.UseSqlite($"Data Source={databasePath};Pooling=False")
.Options;
await using (var db = new QMaxDbContext(dbOptions))
{
await db.Database.EnsureCreatedAsync();
var user = new User { DisplayName = "Push Test" };
db.Users.Add(user);
db.PushDevices.Add(new PushDevice { User = user, FirebaseToken = "test-token", Platform = "android" });
await db.SaveChangesAsync();
var service = new FirebasePushNotificationService(
db,
new ThrowingHttpClientFactory(),
Options.Create(new QMaxOptions
{
PushEnabled = true,
FirebaseProjectId = "qmax-test",
FirebaseServiceAccountJson = "{ this is not valid json"
}),
NullLogger<FirebasePushNotificationService>.Instance);
var chat = new Chat { Title = "Self Chat" };
var message = new Message
{
Chat = chat,
Direction = MessageDirection.Outgoing,
Text = "message from me",
DeliveryState = MessageDeliveryState.Sent
};
await service.SendNewMessageAsync(chat, message, CancellationToken.None);
Assert.Equal(1, await db.PushDevices.CountAsync());
}
}
finally
{
foreach (var suffix in new[] { "", "-shm", "-wal" })
{
var path = databasePath + suffix;
if (File.Exists(path))
{
File.Delete(path);
}
}
}
}
[Fact]
public async Task AdminStatusRequiresPairingCode()
{
@@ -685,6 +741,14 @@ public sealed class ApiSmokeTests : IDisposable
}
}
private sealed class ThrowingHttpClientFactory : IHttpClientFactory
{
public HttpClient CreateClient(string name)
{
throw new InvalidOperationException("Push for outgoing messages must not reach Firebase HTTP calls.");
}
}
private sealed class FailingActionMaxBridgeClient : IMaxBridgeClient
{
public Task<MaxBridgeStatus> GetStatusAsync(CancellationToken cancellationToken)