1
0
mirror of https://github.com/bitwarden/server synced 2025-12-16 08:13:33 +00:00
Files
server/test/Core.Test/AdminConsole/OrganizationFeatures/Organizations/GetOrganizationSubscriptionsToUpdateQueryTests.cs
Jared McCannon 86ce3a86e9 [PM-20452] - Offloading Stripe Update (#6034)
* 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
2025-07-31 07:54:51 -05:00

55 lines
2.0 KiB
C#

using Bit.Core.AdminConsole.Entities;
using Bit.Core.AdminConsole.OrganizationFeatures.Organizations;
using Bit.Core.Billing.Enums;
using Bit.Core.Billing.Models.StaticStore.Plans;
using Bit.Core.Billing.Pricing;
using Bit.Core.Repositories;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;
using NSubstitute;
using Xunit;
namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.Organizations;
[SutProviderCustomize]
public class GetOrganizationSubscriptionsToUpdateQueryTests
{
[Theory]
[BitAutoData]
public async Task GetOrganizationSubscriptionsToUpdateAsync_WhenNoOrganizationsNeedToBeSynced_ThenAnEmptyListIsReturned(
SutProvider<GetOrganizationSubscriptionsToUpdateQuery> sutProvider)
{
sutProvider.GetDependency<IOrganizationRepository>()
.GetOrganizationsForSubscriptionSyncAsync()
.Returns([]);
var result = await sutProvider.Sut.GetOrganizationSubscriptionsToUpdateAsync();
Assert.Empty(result);
}
[Theory]
[BitAutoData]
public async Task GetOrganizationSubscriptionsToUpdateAsync_WhenOrganizationsNeedToBeSynced_ThenUpdateIsReturnedWithCorrectPlanAndOrg(
Organization organization,
SutProvider<GetOrganizationSubscriptionsToUpdateQuery> sutProvider)
{
organization.PlanType = PlanType.EnterpriseAnnually2023;
sutProvider.GetDependency<IOrganizationRepository>()
.GetOrganizationsForSubscriptionSyncAsync()
.Returns([organization]);
sutProvider.GetDependency<IPricingClient>()
.ListPlans()
.Returns([new Enterprise2023Plan(true)]);
var result = await sutProvider.Sut.GetOrganizationSubscriptionsToUpdateAsync();
var matchingUpdate = result.FirstOrDefault(x => x.Organization.Id == organization.Id);
Assert.NotNull(matchingUpdate);
Assert.Equal(organization.PlanType, matchingUpdate.Plan!.Type);
Assert.Equal(organization, matchingUpdate.Organization);
}
}