Files
server/test/Core.Test/Services/MultiServicePushNotificationServiceTests.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

83 lines
3.2 KiB
C#
Raw Normal View History

2024-10-24 13:06:48 +01:00
#nullable enable
using Bit.Core.Enums;
using Bit.Core.NotificationCenter.Entities;
using Bit.Core.Services;
2024-10-24 13:06:48 +01:00
using Bit.Core.Test.NotificationCenter.AutoFixture;
Shard notification hub (#4450) * Allow for binning of comb IDs by date and value * Introduce notification hub pool * Replace device type sharding with comb + range sharding * Fix proxy interface * Use enumerable services for multiServiceNotificationHub * Fix push interface usage * Fix push notification service dependencies * Fix push notification keys * Fixup documentation * Remove deprecated settings * Fix tests * PascalCase method names * Remove unused request model properties * Remove unused setting * Improve DateFromComb precision * Prefer readonly service enumerable * Pascal case template holes * Name TryParse methods TryParse * Apply suggestions from code review Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com> * AllClients is a set of clients and must be deduplicated * Fix registration start time * Add logging to initialization of a notification hub * more logging * Add lower level logging for hub settings * Log when connection is resolved * Improve log message * Log pushes to notification hub * temporarily elevate log messages for visibility * Log in multi-service when relaying to another push service * Revert to more reasonable logging free of user information * Fixup merge Deleting user was extracted to a command in #4803, this updates that work to use just the device ids as I did elsewhere in abd67e8ec * Do not use bouncy castle exception types * Add required services for logging --------- Co-authored-by: Justin Baur <19896123+justindbaur@users.noreply.github.com> Co-authored-by: bnagawiecki <107435978+bnagawiecki@users.noreply.github.com>
2024-10-22 09:20:57 -07:00
using Bit.Test.Common.AutoFixture;
2024-10-24 13:06:48 +01:00
using Bit.Test.Common.AutoFixture.Attributes;
using NSubstitute;
using Xunit;
namespace Bit.Core.Test.Services;
2022-08-29 16:06:55 -04:00
2024-10-24 13:06:48 +01:00
[SutProviderCustomize]
public class MultiServicePushNotificationServiceTests
{
2024-10-24 13:06:48 +01:00
[Theory]
[BitAutoData]
2024-10-24 13:06:48 +01:00
[NotificationCustomize]
public async Task PushSyncNotificationCreateAsync_Notification_Sent(
SutProvider<MultiServicePushNotificationService> sutProvider, Notification notification)
2024-10-24 13:06:48 +01:00
{
await sutProvider.Sut.PushSyncNotificationCreateAsync(notification);
2024-10-24 13:06:48 +01:00
await sutProvider.GetDependency<IEnumerable<IPushNotificationService>>()
.First()
.Received(1)
.PushSyncNotificationCreateAsync(notification);
}
[Theory]
[BitAutoData(false)]
[BitAutoData(true)]
[NotificationCustomize]
[NotificationStatusCustomize]
public async Task PushSyncNotificationUpdateAsync_Notification_Sent(bool notificationStatusNull,
SutProvider<MultiServicePushNotificationService> sutProvider, Notification notification,
NotificationStatus notificationStatus)
{
await sutProvider.Sut.PushSyncNotificationUpdateAsync(notification,
notificationStatusNull ? null : notificationStatus);
var expectedNotificationStatus = notificationStatusNull ? null : notificationStatus;
await sutProvider.GetDependency<IEnumerable<IPushNotificationService>>()
.First()
.Received(1)
.PushSyncNotificationUpdateAsync(notification, expectedNotificationStatus);
2024-10-24 13:06:48 +01:00
}
2024-10-24 13:06:48 +01:00
[Theory]
[BitAutoData([null, null])]
[BitAutoData(ClientType.All, null)]
[BitAutoData([null, "test device id"])]
[BitAutoData(ClientType.All, "test device id")]
public async Task SendPayloadToUserAsync_Message_Sent(ClientType? clientType, string? deviceId, string userId,
PushType type, object payload, string identifier, SutProvider<MultiServicePushNotificationService> sutProvider)
{
2024-10-24 13:06:48 +01:00
await sutProvider.Sut.SendPayloadToUserAsync(userId, type, payload, identifier, deviceId, clientType);
2024-10-24 13:06:48 +01:00
await sutProvider.GetDependency<IEnumerable<IPushNotificationService>>()
.First()
.Received(1)
.SendPayloadToUserAsync(userId, type, payload, identifier, deviceId, clientType);
}
2024-10-24 13:06:48 +01:00
[Theory]
[BitAutoData([null, null])]
[BitAutoData(ClientType.All, null)]
[BitAutoData([null, "test device id"])]
[BitAutoData(ClientType.All, "test device id")]
public async Task SendPayloadToOrganizationAsync_Message_Sent(ClientType? clientType, string? deviceId,
string organizationId, PushType type, object payload, string identifier,
SutProvider<MultiServicePushNotificationService> sutProvider)
{
2024-10-24 13:06:48 +01:00
await sutProvider.Sut.SendPayloadToOrganizationAsync(organizationId, type, payload, identifier, deviceId,
clientType);
await sutProvider.GetDependency<IEnumerable<IPushNotificationService>>()
.First()
.Received(1)
.SendPayloadToOrganizationAsync(organizationId, type, payload, identifier, deviceId, clientType);
}
}