mirror of
https://github.com/bitwarden/server
synced 2025-12-13 06:43:45 +00:00
* Move PushType to Platform Folder - Move the PushType next to the rest of push notification code - Specifically exclude it from needing Platform code review - Add tests establishing rules Platform has for usage of this enum, making it safe to have no owner * Move NotificationHub code into Platform/Push directory * Update NotificationHub namespace imports * Add attribute for storing push type metadata * Rename Push Engines to have PushEngine suffix * Move Push Registration items to their own directory * Push code move * Add expected usage comment * Add Push feature registration method - Make method able to be called multipes times with no ill effects * Add Push Registration service entrypoint and tests * Use new service entrypoints * Test changes
58 lines
1.7 KiB
C#
58 lines
1.7 KiB
C#
using Bit.Core.Enums;
|
|
using Bit.Core.Platform.Push;
|
|
using Bit.Core.Platform.Push.Internal;
|
|
using Bit.Core.Settings;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Microsoft.Extensions.Time.Testing;
|
|
using NSubstitute;
|
|
using Xunit;
|
|
|
|
namespace Bit.Core.Test.Platform.Push;
|
|
|
|
public class MultiServicePushNotificationServiceTests
|
|
{
|
|
private readonly IPushEngine _fakeEngine1;
|
|
private readonly IPushEngine _fakeEngine2;
|
|
|
|
private readonly MultiServicePushNotificationService _sut;
|
|
|
|
public MultiServicePushNotificationServiceTests()
|
|
{
|
|
_fakeEngine1 = Substitute.For<IPushEngine>();
|
|
_fakeEngine2 = Substitute.For<IPushEngine>();
|
|
|
|
_sut = new MultiServicePushNotificationService(
|
|
[_fakeEngine1, _fakeEngine2],
|
|
NullLogger<MultiServicePushNotificationService>.Instance,
|
|
new GlobalSettings(),
|
|
new FakeTimeProvider()
|
|
);
|
|
}
|
|
|
|
#if DEBUG // This test requires debug code in the sut to work properly
|
|
[Fact]
|
|
public async Task PushAsync_CallsAllEngines()
|
|
{
|
|
var notification = new PushNotification<object>
|
|
{
|
|
Target = NotificationTarget.User,
|
|
TargetId = Guid.NewGuid(),
|
|
Type = PushType.AuthRequest,
|
|
Payload = new { },
|
|
ExcludeCurrentContext = false,
|
|
};
|
|
|
|
await _sut.PushAsync(notification);
|
|
|
|
await _fakeEngine1
|
|
.Received(1)
|
|
.PushAsync(Arg.Is<PushNotification<object>>(n => ReferenceEquals(n, notification)));
|
|
|
|
await _fakeEngine2
|
|
.Received(1)
|
|
.PushAsync(Arg.Is<PushNotification<object>>(n => ReferenceEquals(n, notification)));
|
|
}
|
|
|
|
#endif
|
|
}
|