|
1 | | -using Bit.Core.AdminConsole.Enums; |
| 1 | +using Bit.Core.AdminConsole.Entities; |
| 2 | +using Bit.Core.AdminConsole.Enums; |
2 | 3 | using Bit.Core.AdminConsole.Models.Data.Organizations.Policies; |
3 | 4 | using Bit.Core.AdminConsole.OrganizationFeatures.Policies; |
4 | 5 | using Bit.Core.Billing.Enums; |
5 | 6 | using Bit.Core.Billing.Pricing; |
6 | 7 | using Bit.Core.Billing.Services; |
| 8 | +using Bit.Core.Entities; |
| 9 | +using Bit.Core.Enums; |
7 | 10 | using Bit.Core.Exceptions; |
8 | 11 | using Bit.Core.KeyManagement.Models.Data; |
9 | 12 | using Bit.Core.Models.Business; |
|
19 | 22 | using Bit.Test.Common.AutoFixture.Attributes; |
20 | 23 | using NSubstitute; |
21 | 24 | using Xunit; |
22 | | -using Organization = Bit.Core.AdminConsole.Entities.Organization; |
23 | 25 |
|
24 | 26 | namespace Bit.Core.Test.OrganizationFeatures.OrganizationSubscriptionUpdate; |
25 | 27 |
|
26 | 28 | [SutProviderCustomize] |
27 | 29 | public class UpgradeOrganizationPlanCommandTests |
28 | 30 | { |
| 31 | + private static void SetupOrganizationOwner(SutProvider<UpgradeOrganizationPlanCommand> sutProvider, Organization organization, User owner) |
| 32 | + { |
| 33 | + var ownerOrganizationUser = new OrganizationUser |
| 34 | + { |
| 35 | + OrganizationId = organization.Id, |
| 36 | + UserId = owner.Id, |
| 37 | + Type = OrganizationUserType.Owner |
| 38 | + }; |
| 39 | + sutProvider.GetDependency<IOrganizationUserRepository>() |
| 40 | + .GetManyByOrganizationAsync(organization.Id, OrganizationUserType.Owner) |
| 41 | + .Returns(new[] { ownerOrganizationUser }); |
| 42 | + sutProvider.GetDependency<IUserRepository>() |
| 43 | + .GetByIdAsync(owner.Id) |
| 44 | + .Returns(owner); |
| 45 | + } |
| 46 | + |
29 | 47 | [Theory, BitAutoData] |
30 | 48 | public async Task UpgradePlan_OrganizationIsNull_Throws(Guid organizationId, OrganizationUpgrade upgrade, |
31 | 49 | SutProvider<UpgradeOrganizationPlanCommand> sutProvider) |
@@ -76,9 +94,11 @@ public async Task UpgradePlan_SM_AlreadyInPlan_Throws(Organization organization, |
76 | 94 | [Theory] |
77 | 95 | [FreeOrganizationUpgradeCustomize, BitAutoData] |
78 | 96 | public async Task UpgradePlan_Passes(Organization organization, OrganizationUpgrade upgrade, |
| 97 | + User owner, |
79 | 98 | [Policy(PolicyType.ResetPassword, false)] PolicyStatus policy, |
80 | 99 | SutProvider<UpgradeOrganizationPlanCommand> sutProvider) |
81 | 100 | { |
| 101 | + SetupOrganizationOwner(sutProvider, organization, owner); |
82 | 102 | sutProvider.GetDependency<IPolicyQuery>() |
83 | 103 | .RunAsync(Arg.Any<Guid>(), Arg.Any<PolicyType>()) |
84 | 104 | .Returns(policy); |
@@ -153,10 +173,11 @@ await sutProvider.GetDependency<IStripePaymentService>().Received(1).AdjustSubsc |
153 | 173 | [BitAutoData(PlanType.TeamsAnnually)] |
154 | 174 | [BitAutoData(PlanType.TeamsStarter)] |
155 | 175 | public async Task UpgradePlan_SM_Passes(PlanType planType, Organization organization, OrganizationUpgrade upgrade, |
| 176 | + User owner, |
156 | 177 | [Policy(PolicyType.ResetPassword, false)] PolicyStatus policy, |
157 | 178 | SutProvider<UpgradeOrganizationPlanCommand> sutProvider) |
158 | 179 | { |
159 | | - |
| 180 | + SetupOrganizationOwner(sutProvider, organization, owner); |
160 | 181 | upgrade.Plan = planType; |
161 | 182 | sutProvider.GetDependency<IPricingClient>().GetPlanOrThrow(upgrade.Plan).Returns(MockPlans.Get(upgrade.Plan)); |
162 | 183 |
|
@@ -277,11 +298,13 @@ public async Task UpgradePlan_SM_NotEnoughServiceAccounts_Throws(PlanType planTy |
277 | 298 | public async Task UpgradePlan_WhenOrganizationIsMissingPublicAndPrivateKeys_Backfills( |
278 | 299 | Organization organization, |
279 | 300 | OrganizationUpgrade upgrade, |
| 301 | + User owner, |
280 | 302 | string newPublicKey, |
281 | 303 | string newPrivateKey, |
282 | 304 | [Policy(PolicyType.ResetPassword, false)] PolicyStatus policy, |
283 | 305 | SutProvider<UpgradeOrganizationPlanCommand> sutProvider) |
284 | 306 | { |
| 307 | + SetupOrganizationOwner(sutProvider, organization, owner); |
285 | 308 | organization.PublicKey = null; |
286 | 309 | organization.PrivateKey = null; |
287 | 310 |
|
@@ -323,9 +346,11 @@ await sutProvider.GetDependency<IOrganizationService>() |
323 | 346 | public async Task UpgradePlan_WhenOrganizationAlreadyHasPublicAndPrivateKeys_DoesNotOverwriteWithNull( |
324 | 347 | Organization organization, |
325 | 348 | OrganizationUpgrade upgrade, |
| 349 | + User owner, |
326 | 350 | [Policy(PolicyType.ResetPassword, false)] PolicyStatus policy, |
327 | 351 | SutProvider<UpgradeOrganizationPlanCommand> sutProvider) |
328 | 352 | { |
| 353 | + SetupOrganizationOwner(sutProvider, organization, owner); |
329 | 354 | // Arrange |
330 | 355 | const string existingPublicKey = "existing-public-key"; |
331 | 356 | const string existingPrivateKey = "existing-private-key"; |
@@ -369,9 +394,11 @@ await sutProvider.GetDependency<IOrganizationService>() |
369 | 394 | public async Task UpgradePlan_WhenOrganizationAlreadyHasPublicAndPrivateKeys_DoesNotBackfillWithNewKeys( |
370 | 395 | Organization organization, |
371 | 396 | OrganizationUpgrade upgrade, |
| 397 | + User owner, |
372 | 398 | [Policy(PolicyType.ResetPassword, false)] PolicyStatus policy, |
373 | 399 | SutProvider<UpgradeOrganizationPlanCommand> sutProvider) |
374 | 400 | { |
| 401 | + SetupOrganizationOwner(sutProvider, organization, owner); |
375 | 402 | // Arrange |
376 | 403 | const string existingPublicKey = "existing-public-key"; |
377 | 404 | const string existingPrivateKey = "existing-private-key"; |
|
0 commit comments