mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 16:12:49 -05:00
Merge branch 'km/pm-10600-full-notification-content' into km/pm-10564
# Conflicts: # src/Core/Models/PushNotification.cs # src/Core/Services/IPushNotificationService.cs # src/Core/Services/NoopImplementations/NoopPushNotificationService.cs # test/Core.Test/NotificationCenter/Commands/CreateNotificationCommandTest.cs # test/Core.Test/NotificationHub/NotificationHubPushNotificationServiceTests.cs # test/Core.Test/Services/AzureQueuePushNotificationServiceTests.cs
This commit is contained in:
@ -25,7 +25,7 @@ public class AzureQueuePushNotificationServiceTests
|
||||
[BitAutoData]
|
||||
[NotificationCustomize]
|
||||
[CurrentContextCustomize]
|
||||
public async Task PushSyncNotificationAsync_Notification_Sent(
|
||||
public async Task PushNotificationAsync_Notification_Sent(
|
||||
SutProvider<AzureQueuePushNotificationService> sutProvider, Notification notification, Guid deviceIdentifier,
|
||||
ICurrentContext currentContext)
|
||||
{
|
||||
@ -33,11 +33,12 @@ public class AzureQueuePushNotificationServiceTests
|
||||
sutProvider.GetDependency<IHttpContextAccessor>().HttpContext!.RequestServices
|
||||
.GetService(Arg.Any<Type>()).Returns(currentContext);
|
||||
|
||||
await sutProvider.Sut.PushSyncNotificationAsync(notification);
|
||||
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||
|
||||
await sutProvider.GetDependency<QueueClient>().Received(1)
|
||||
.SendMessageAsync(Arg.Is<string>(message =>
|
||||
MatchMessage(PushType.SyncNotification, message, new SyncNotificationEquals(notification, null),
|
||||
MatchMessage(PushType.SyncNotification, message,
|
||||
new NotificationPushNotificationEquals(notification, null),
|
||||
deviceIdentifier.ToString())));
|
||||
}
|
||||
|
||||
@ -46,7 +47,7 @@ public class AzureQueuePushNotificationServiceTests
|
||||
[NotificationCustomize]
|
||||
[NotificationStatusCustomize]
|
||||
[CurrentContextCustomize]
|
||||
public async Task PushSyncNotificationStatusAsync_Notification_Sent(
|
||||
public async Task PushNotificationStatusAsync_Notification_Sent(
|
||||
SutProvider<AzureQueuePushNotificationService> sutProvider, Notification notification, Guid deviceIdentifier,
|
||||
ICurrentContext currentContext, NotificationStatus notificationStatus)
|
||||
{
|
||||
@ -54,36 +55,42 @@ public class AzureQueuePushNotificationServiceTests
|
||||
sutProvider.GetDependency<IHttpContextAccessor>().HttpContext!.RequestServices
|
||||
.GetService(Arg.Any<Type>()).Returns(currentContext);
|
||||
|
||||
await sutProvider.Sut.PushSyncNotificationStatusAsync(notification, notificationStatus);
|
||||
await sutProvider.Sut.PushNotificationStatusAsync(notification, notificationStatus);
|
||||
|
||||
await sutProvider.GetDependency<QueueClient>().Received(1)
|
||||
.SendMessageAsync(Arg.Is<string>(message =>
|
||||
MatchMessage(PushType.SyncNotificationStatus, message,
|
||||
new SyncNotificationEquals(notification, notificationStatus),
|
||||
new NotificationPushNotificationEquals(notification, notificationStatus),
|
||||
deviceIdentifier.ToString())));
|
||||
}
|
||||
|
||||
private static bool MatchMessage<T>(PushType pushType, string message, IEquatable<T> expectedPayloadEquatable,
|
||||
string contextId)
|
||||
{
|
||||
var pushNotificationData =
|
||||
JsonSerializer.Deserialize<PushNotificationData<T>>(message);
|
||||
var pushNotificationData = JsonSerializer.Deserialize<PushNotificationData<T>>(message);
|
||||
return pushNotificationData != null &&
|
||||
pushNotificationData.Type == pushType &&
|
||||
expectedPayloadEquatable.Equals(pushNotificationData.Payload) &&
|
||||
pushNotificationData.ContextId == contextId;
|
||||
}
|
||||
|
||||
private class SyncNotificationEquals(Notification notification, NotificationStatus? notificationStatus)
|
||||
: IEquatable<SyncNotificationPushNotification>
|
||||
private class NotificationPushNotificationEquals(Notification notification, NotificationStatus? notificationStatus)
|
||||
: IEquatable<NotificationPushNotification>
|
||||
{
|
||||
public bool Equals(SyncNotificationPushNotification? other)
|
||||
public bool Equals(NotificationPushNotification? other)
|
||||
{
|
||||
return other != null &&
|
||||
other.Id == notification.Id &&
|
||||
other.UserId == notification.UserId &&
|
||||
other.OrganizationId == notification.OrganizationId &&
|
||||
other.Priority == notification.Priority &&
|
||||
other.Global == notification.Global &&
|
||||
other.ClientType == notification.ClientType &&
|
||||
other.UserId.HasValue == notification.UserId.HasValue &&
|
||||
other.UserId == notification.UserId &&
|
||||
other.OrganizationId.HasValue == notification.OrganizationId.HasValue &&
|
||||
other.OrganizationId == notification.OrganizationId &&
|
||||
other.Title == notification.Title &&
|
||||
other.Body == notification.Body &&
|
||||
other.CreationDate == notification.CreationDate &&
|
||||
other.RevisionDate == notification.RevisionDate &&
|
||||
other.ReadDate == notificationStatus?.ReadDate &&
|
||||
other.DeletedDate == notificationStatus?.DeletedDate;
|
||||
|
Reference in New Issue
Block a user