mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 16:12:49 -05:00
PM-10600: Push notification with full notification center content.
Notification Center push notification now includes all the fields.
This commit is contained in:
@ -58,6 +58,6 @@ public class CreateNotificationCommandTest
|
||||
Assert.Equal(notification.CreationDate, notification.RevisionDate);
|
||||
await sutProvider.GetDependency<IPushNotificationService>()
|
||||
.Received(1)
|
||||
.PushSyncNotificationAsync(newNotification);
|
||||
.PushNotificationAsync(newNotification);
|
||||
}
|
||||
}
|
||||
|
@ -20,10 +20,10 @@ public class NotificationHubPushNotificationServiceTests
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
[NotificationCustomize]
|
||||
public async void PushSyncNotificationAsync_Global_NotSent(
|
||||
public async void PushNotificationAsync_Global_NotSent(
|
||||
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification)
|
||||
{
|
||||
await sutProvider.Sut.PushSyncNotificationAsync(notification);
|
||||
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||
|
||||
await sutProvider.GetDependency<INotificationHubPool>()
|
||||
.Received(0)
|
||||
@ -39,7 +39,7 @@ public class NotificationHubPushNotificationServiceTests
|
||||
[BitAutoData(false)]
|
||||
[BitAutoData(true)]
|
||||
[NotificationCustomize(false)]
|
||||
public async void PushSyncNotificationAsync_UserIdProvidedClientTypeAll_SentToUser(
|
||||
public async void PushNotificationAsync_UserIdProvidedClientTypeAll_SentToUser(
|
||||
bool organizationIdNull, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
||||
Notification notification)
|
||||
{
|
||||
@ -51,7 +51,7 @@ public class NotificationHubPushNotificationServiceTests
|
||||
notification.ClientType = ClientType.All;
|
||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification);
|
||||
|
||||
await sutProvider.Sut.PushSyncNotificationAsync(notification);
|
||||
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||
|
||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotification, expectedSyncNotification,
|
||||
$"(template:payload_userId:{notification.UserId})");
|
||||
@ -70,7 +70,7 @@ public class NotificationHubPushNotificationServiceTests
|
||||
[BitAutoData(true, ClientType.Web)]
|
||||
[BitAutoData(true, ClientType.Mobile)]
|
||||
[NotificationCustomize(false)]
|
||||
public async void PushSyncNotificationAsync_UserIdProvidedClientTypeNotAll_SentToUser(bool organizationIdNull,
|
||||
public async void PushNotificationAsync_UserIdProvidedClientTypeNotAll_SentToUser(bool organizationIdNull,
|
||||
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
||||
Notification notification)
|
||||
{
|
||||
@ -82,7 +82,7 @@ public class NotificationHubPushNotificationServiceTests
|
||||
notification.ClientType = clientType;
|
||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification);
|
||||
|
||||
await sutProvider.Sut.PushSyncNotificationAsync(notification);
|
||||
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||
|
||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotification, expectedSyncNotification,
|
||||
$"(template:payload_userId:{notification.UserId} && clientType:{clientType})");
|
||||
@ -94,14 +94,14 @@ public class NotificationHubPushNotificationServiceTests
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
[NotificationCustomize(false)]
|
||||
public async void PushSyncNotificationAsync_UserIdNullOrganizationIdProvidedClientTypeAll_SentToOrganization(
|
||||
public async void PushNotificationAsync_UserIdNullOrganizationIdProvidedClientTypeAll_SentToOrganization(
|
||||
SutProvider<NotificationHubPushNotificationService> sutProvider, Notification notification)
|
||||
{
|
||||
notification.UserId = null;
|
||||
notification.ClientType = ClientType.All;
|
||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification);
|
||||
|
||||
await sutProvider.Sut.PushSyncNotificationAsync(notification);
|
||||
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||
|
||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotification, expectedSyncNotification,
|
||||
$"(template:payload && organizationId:{notification.OrganizationId})");
|
||||
@ -116,7 +116,7 @@ public class NotificationHubPushNotificationServiceTests
|
||||
[BitAutoData(ClientType.Web)]
|
||||
[BitAutoData(ClientType.Mobile)]
|
||||
[NotificationCustomize(false)]
|
||||
public async void PushSyncNotificationAsync_UserIdNullOrganizationIdProvidedClientTypeNotAll_SentToOrganization(
|
||||
public async void PushNotificationAsync_UserIdNullOrganizationIdProvidedClientTypeNotAll_SentToOrganization(
|
||||
ClientType clientType, SutProvider<NotificationHubPushNotificationService> sutProvider,
|
||||
Notification notification)
|
||||
{
|
||||
@ -125,7 +125,7 @@ public class NotificationHubPushNotificationServiceTests
|
||||
|
||||
var expectedSyncNotification = ToSyncNotificationPushNotification(notification);
|
||||
|
||||
await sutProvider.Sut.PushSyncNotificationAsync(notification);
|
||||
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||
|
||||
await AssertSendTemplateNotificationAsync(sutProvider, PushType.SyncNotification, expectedSyncNotification,
|
||||
$"(template:payload && organizationId:{notification.OrganizationId} && clientType:{clientType})");
|
||||
@ -206,13 +206,18 @@ public class NotificationHubPushNotificationServiceTests
|
||||
.UpsertAsync(Arg.Any<InstallationDeviceEntity>());
|
||||
}
|
||||
|
||||
private static SyncNotificationPushNotification ToSyncNotificationPushNotification(Notification notification) =>
|
||||
private static NotificationPushNotification ToSyncNotificationPushNotification(Notification notification) =>
|
||||
new()
|
||||
{
|
||||
Id = notification.Id,
|
||||
Priority = notification.Priority,
|
||||
Global = notification.Global,
|
||||
ClientType = notification.ClientType,
|
||||
UserId = notification.UserId,
|
||||
OrganizationId = notification.OrganizationId,
|
||||
ClientType = notification.ClientType,
|
||||
Title = notification.Title,
|
||||
Body = notification.Body,
|
||||
CreationDate = notification.CreationDate,
|
||||
RevisionDate = notification.RevisionDate
|
||||
};
|
||||
|
||||
|
@ -25,7 +25,7 @@ public class AzureQueuePushNotificationServiceTests
|
||||
[BitAutoData]
|
||||
[NotificationCustomize]
|
||||
[CurrentContextCustomize]
|
||||
public async void PushSyncNotificationAsync_Notification_Sent(
|
||||
public async void PushNotificationAsync_Notification_Sent(
|
||||
SutProvider<AzureQueuePushNotificationService> sutProvider, Notification notification, Guid deviceIdentifier,
|
||||
ICurrentContext currentContext)
|
||||
{
|
||||
@ -33,7 +33,7 @@ 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 =>
|
||||
@ -44,23 +44,29 @@ public class AzureQueuePushNotificationServiceTests
|
||||
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) : IEquatable<SyncNotificationPushNotification>
|
||||
private class SyncNotificationEquals(Notification notification) : 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;
|
||||
}
|
||||
}
|
||||
|
@ -16,15 +16,15 @@ public class MultiServicePushNotificationServiceTests
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
[NotificationCustomize]
|
||||
public async Task PushSyncNotificationAsync_Notification_Sent(
|
||||
public async Task PushNotificationAsync_Notification_Sent(
|
||||
SutProvider<MultiServicePushNotificationService> sutProvider, Notification notification)
|
||||
{
|
||||
await sutProvider.Sut.PushSyncNotificationAsync(notification);
|
||||
await sutProvider.Sut.PushNotificationAsync(notification);
|
||||
|
||||
await sutProvider.GetDependency<IEnumerable<IPushNotificationService>>()
|
||||
.First()
|
||||
.Received(1)
|
||||
.PushSyncNotificationAsync(notification);
|
||||
.PushNotificationAsync(notification);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
Reference in New Issue
Block a user