mirror of
https://github.com/bitwarden/server.git
synced 2025-02-21 02:41:21 +01:00
PM-10600: Unit Test coverage for NotificationHubPushRegistrationService
Fixed IFeatureService substitute mocking for Android tests. Added user part of organization test with organizationId tags expectation.
This commit is contained in:
parent
67aa2eb6d9
commit
31316ee62f
@ -1,11 +1,14 @@
|
||||
#nullable enable
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Data.Organizations.OrganizationUsers;
|
||||
using Bit.Core.NotificationHub;
|
||||
using Bit.Core.Repositories;
|
||||
using Bit.Core.Services;
|
||||
using Bit.Core.Utilities;
|
||||
using Bit.Test.Common.AutoFixture;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
using Microsoft.Azure.NotificationHubs;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
@ -37,7 +40,14 @@ public class NotificationHubPushRegistrationServiceTests
|
||||
{
|
||||
var featureService = Substitute.For<IFeatureService>();
|
||||
featureService.IsEnabled(FeatureFlagKeys.AnhFcmv1Migration).Returns(true);
|
||||
sutProvider.GetDependency<IServiceProvider>().GetService(typeof(IFeatureService)).Returns(featureService);
|
||||
var serviceProvider = Substitute.For<IServiceProvider>();
|
||||
serviceProvider.GetService(typeof(IFeatureService)).Returns(featureService);
|
||||
var serviceScope = Substitute.For<IServiceScope>();
|
||||
serviceScope.ServiceProvider.Returns(serviceProvider);
|
||||
var serviceScopeFactory = Substitute.For<IServiceScopeFactory>();
|
||||
serviceScopeFactory.CreateScope().Returns(serviceScope);
|
||||
sutProvider.GetDependency<IServiceProvider>().GetService(typeof(IServiceScopeFactory))
|
||||
.Returns(serviceScopeFactory);
|
||||
var notificationHubClient = Substitute.For<INotificationHubClient>();
|
||||
sutProvider.GetDependency<INotificationHubPool>().ClientFor(Arg.Any<Guid>()).Returns(notificationHubClient);
|
||||
|
||||
@ -260,6 +270,38 @@ public class NotificationHubPushRegistrationServiceTests
|
||||
installation.Templates.Count == 0));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
public async void CreateOrUpdateRegistrationAsync_UserPartOfOrganization_InstallationCreated(
|
||||
SutProvider<NotificationHubPushRegistrationService> sutProvider, Guid deviceId, Guid userId, Guid identifier,
|
||||
OrganizationUserOrganizationDetails organizationDetails)
|
||||
{
|
||||
var notificationHubClient = Substitute.For<INotificationHubClient>();
|
||||
sutProvider.GetDependency<INotificationHubPool>().ClientFor(Arg.Any<Guid>()).Returns(notificationHubClient);
|
||||
sutProvider.GetDependency<IOrganizationUserRepository>()
|
||||
.GetManyDetailsByUserAsync(userId, OrganizationUserStatusType.Confirmed)
|
||||
.Returns([organizationDetails]);
|
||||
|
||||
var pushToken = "test push token";
|
||||
|
||||
await sutProvider.Sut.CreateOrUpdateRegistrationAsync(pushToken, deviceId.ToString(), userId.ToString(),
|
||||
identifier.ToString(), DeviceType.ChromeBrowser);
|
||||
|
||||
sutProvider.GetDependency<INotificationHubPool>()
|
||||
.Received(1)
|
||||
.ClientFor(deviceId);
|
||||
await notificationHubClient
|
||||
.Received(1)
|
||||
.CreateOrUpdateInstallationAsync(Arg.Is<Installation>(installation =>
|
||||
installation.InstallationId == deviceId.ToString() &&
|
||||
installation.PushChannel == pushToken &&
|
||||
installation.Tags.Count == 4 &&
|
||||
installation.Tags.Contains($"userId:{userId}") &&
|
||||
installation.Tags.Contains($"clientType:{DeviceTypes.ToClientType(DeviceType.ChromeBrowser)}") &&
|
||||
installation.Tags.Contains($"deviceIdentifier:{identifier}") &&
|
||||
installation.Tags.Contains($"organizationId:{organizationDetails.OrganizationId}")));
|
||||
}
|
||||
|
||||
private static bool MatchingInstallationTemplate(IDictionary<string, InstallationTemplate> templates, string key,
|
||||
string body, List<string?> tags)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user