1
0
mirror of https://github.com/bitwarden/server synced 2025-12-30 07:03:42 +00:00

Notifications service unit test coverage with small refactor (#6126)

This commit is contained in:
Maciej Zieniuk
2025-10-23 14:40:57 +02:00
committed by GitHub
parent 69f0464e05
commit dd1f0a120a
6 changed files with 380 additions and 69 deletions

View File

@@ -1,36 +1,30 @@
using System.Text;
#nullable enable
using System.Text;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
namespace Bit.Notifications;
namespace Bit.Notifications.Controllers;
[Authorize("Internal")]
public class SendController : Controller
{
private readonly IHubContext<NotificationsHub> _hubContext;
private readonly IHubContext<AnonymousNotificationsHub> _anonymousHubContext;
private readonly ILogger<SendController> _logger;
private readonly HubHelpers _hubHelpers;
public SendController(IHubContext<NotificationsHub> hubContext, IHubContext<AnonymousNotificationsHub> anonymousHubContext, ILogger<SendController> logger)
public SendController(HubHelpers hubHelpers)
{
_hubContext = hubContext;
_anonymousHubContext = anonymousHubContext;
_logger = logger;
_hubHelpers = hubHelpers;
}
[HttpPost("~/send")]
[SelfHosted(SelfHostedOnly = true)]
public async Task PostSend()
public async Task PostSendAsync()
{
using (var reader = new StreamReader(Request.Body, Encoding.UTF8))
using var reader = new StreamReader(Request.Body, Encoding.UTF8);
var notificationJson = await reader.ReadToEndAsync();
if (!string.IsNullOrWhiteSpace(notificationJson))
{
var notificationJson = await reader.ReadToEndAsync();
if (!string.IsNullOrWhiteSpace(notificationJson))
{
await HubHelpers.SendNotificationToHubAsync(notificationJson, _hubContext, _anonymousHubContext, _logger);
}
await _hubHelpers.SendNotificationToHubAsync(notificationJson);
}
}
}