mirror of
https://github.com/bitwarden/server.git
synced 2025-12-10 00:42:07 -06:00
* Adding job to update stripe subscriptions and increment seat count when inviting a user. * Updating name * Added ef migrations * Fixing script * Fixing procedures. Added repo tests. * Fixed set stored procedure. Fixed parameter name. * Added tests for database calls and updated stored procedures * Fixed build for sql file. * fixing sproc * File is nullsafe * Adding view to select from instead of table. * Updating UpdateSubscriptionStatus to use a CTE and do all the updates in 1 statement. * Setting revision date when incrementing seat count * Added feature flag check for the background job. * Fixing nullable property. * Removing new table and just adding the column to org. Updating to query and command. Updated tests. * Adding migration script rename * Add SyncSeats to Org.sql def * Adding contraint name * Removing old table files. * Added tests * Upped the frequency to be at the top of every 3rd hour. * Updating error message. * Removing extension method * Changed to GuidIdArray * Added xml doc and switched class to record
61 lines
2.1 KiB
C#
61 lines
2.1 KiB
C#
using Bit.Api.AdminConsole.Jobs;
|
|
using Bit.Core;
|
|
using Bit.Core.AdminConsole.Models.Data.Organizations;
|
|
using Bit.Core.AdminConsole.OrganizationFeatures.Organizations.Interfaces;
|
|
using Bit.Core.Services;
|
|
using Bit.Test.Common.AutoFixture;
|
|
using Bit.Test.Common.AutoFixture.Attributes;
|
|
using NSubstitute;
|
|
using Quartz;
|
|
using Xunit;
|
|
|
|
namespace Bit.Api.Test.AdminConsole.Jobs;
|
|
|
|
[SutProviderCustomize]
|
|
public class OrganizationSubscriptionUpdateJobTests
|
|
{
|
|
[Theory]
|
|
[BitAutoData]
|
|
public async Task ExecuteJobAsync_WhenScimInviteUserIsDisabled_ThenQueryAndCommandAreNotExecuted(
|
|
SutProvider<OrganizationSubscriptionUpdateJob> sutProvider)
|
|
{
|
|
sutProvider.GetDependency<IFeatureService>()
|
|
.IsEnabled(FeatureFlagKeys.ScimInviteUserOptimization)
|
|
.Returns(false);
|
|
|
|
var contextMock = Substitute.For<IJobExecutionContext>();
|
|
|
|
await sutProvider.Sut.Execute(contextMock);
|
|
|
|
await sutProvider.GetDependency<IGetOrganizationSubscriptionsToUpdateQuery>()
|
|
.DidNotReceive()
|
|
.GetOrganizationSubscriptionsToUpdateAsync();
|
|
|
|
await sutProvider.GetDependency<IUpdateOrganizationSubscriptionCommand>()
|
|
.DidNotReceive()
|
|
.UpdateOrganizationSubscriptionAsync(Arg.Any<IEnumerable<OrganizationSubscriptionUpdate>>());
|
|
}
|
|
|
|
[Theory]
|
|
[BitAutoData]
|
|
public async Task ExecuteJobAsync_WhenScimInviteUserIsEnabled_ThenQueryAndCommandAreExecuted(
|
|
SutProvider<OrganizationSubscriptionUpdateJob> sutProvider)
|
|
{
|
|
sutProvider.GetDependency<IFeatureService>()
|
|
.IsEnabled(FeatureFlagKeys.ScimInviteUserOptimization)
|
|
.Returns(true);
|
|
|
|
var contextMock = Substitute.For<IJobExecutionContext>();
|
|
|
|
await sutProvider.Sut.Execute(contextMock);
|
|
|
|
await sutProvider.GetDependency<IGetOrganizationSubscriptionsToUpdateQuery>()
|
|
.Received(1)
|
|
.GetOrganizationSubscriptionsToUpdateAsync();
|
|
|
|
await sutProvider.GetDependency<IUpdateOrganizationSubscriptionCommand>()
|
|
.Received(1)
|
|
.UpdateOrganizationSubscriptionAsync(Arg.Any<IEnumerable<OrganizationSubscriptionUpdate>>());
|
|
}
|
|
}
|