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:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user