mirror of
https://github.com/bitwarden/server
synced 2025-12-15 07:43:54 +00:00
[PM-24011] Create new policy sync push notification (#6594)
* create new policy sync push notification * CR feedback * add tests, fix typo
This commit is contained in:
@@ -225,6 +225,30 @@ public class HubHelpersTest
|
||||
.Group(Arg.Any<string>());
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
public async Task SendNotificationToHubAsync_PolicyChanged_SentToOrganizationGroup(
|
||||
SutProvider<HubHelpers> sutProvider,
|
||||
SyncPolicyPushNotification notification,
|
||||
string contextId,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var json = ToNotificationJson(notification, PushType.PolicyChanged, contextId);
|
||||
await sutProvider.Sut.SendNotificationToHubAsync(json, cancellationToken);
|
||||
|
||||
sutProvider.GetDependency<IHubContext<NotificationsHub>>().Clients.Received(0).User(Arg.Any<string>());
|
||||
await sutProvider.GetDependency<IHubContext<NotificationsHub>>().Clients.Received(1)
|
||||
.Group($"Organization_{notification.OrganizationId}")
|
||||
.Received(1)
|
||||
.SendCoreAsync("ReceiveMessage", Arg.Is<object?[]>(objects =>
|
||||
objects.Length == 1 && AssertSyncPolicyPushNotification(notification, objects[0],
|
||||
PushType.PolicyChanged, contextId)),
|
||||
cancellationToken);
|
||||
sutProvider.GetDependency<IHubContext<AnonymousNotificationsHub>>().Clients.Received(0).User(Arg.Any<string>());
|
||||
sutProvider.GetDependency<IHubContext<AnonymousNotificationsHub>>().Clients.Received(0)
|
||||
.Group(Arg.Any<string>());
|
||||
}
|
||||
|
||||
private static string ToNotificationJson(object payload, PushType type, string contextId)
|
||||
{
|
||||
var notification = new PushNotificationData<object>(type, payload, contextId);
|
||||
@@ -247,4 +271,20 @@ public class HubHelpersTest
|
||||
expected.ClientType == pushNotificationData.Payload.ClientType &&
|
||||
expected.RevisionDate == pushNotificationData.Payload.RevisionDate;
|
||||
}
|
||||
|
||||
private static bool AssertSyncPolicyPushNotification(SyncPolicyPushNotification expected, object? actual,
|
||||
PushType type, string contextId)
|
||||
{
|
||||
if (actual is not PushNotificationData<SyncPolicyPushNotification> pushNotificationData)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return pushNotificationData.Type == type &&
|
||||
pushNotificationData.ContextId == contextId &&
|
||||
expected.OrganizationId == pushNotificationData.Payload.OrganizationId &&
|
||||
expected.Policy.Id == pushNotificationData.Payload.Policy.Id &&
|
||||
expected.Policy.Type == pushNotificationData.Payload.Policy.Type &&
|
||||
expected.Policy.Enabled == pushNotificationData.Payload.Policy.Enabled;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user