mirror of
https://github.com/bitwarden/server.git
synced 2025-07-13 05:38:25 -05:00
Families for enterprise/stripe integrations (#1699)
* Add PlanSponsorshipType to static store * Add sponsorship type to token and creates sponsorship * PascalCase properties * Require sponsorship for remove * Create subscription sponsorship helper class * Handle Sponsored subscription changes * Add sponsorship id to subscription metadata * Make sponsoring references nullable This state indicates that a sponsorship has lapsed, but was not able to be reverted for billing reasons * WIP: Validate and remove subscriptions * Update sponsorships on organization and org user delete * Add friendly name to organization sponsorship
This commit is contained in:
@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Table;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Core.Test.Enums
|
||||
{
|
||||
public class PlanTypeHelperTests
|
||||
{
|
||||
private static IEnumerable<PlanType> PlanArchetypeArray(PlanType planType) => new PlanType?[] {
|
||||
PlanTypeHelper.HasFreePlan(new Organization {PlanType = planType}) ? planType : null,
|
||||
PlanTypeHelper.HasFamiliesPlan(new Organization {PlanType = planType}) ? planType : null,
|
||||
PlanTypeHelper.HasTeamsPlan(new Organization {PlanType = planType}) ? planType : null,
|
||||
PlanTypeHelper.HasEnterprisePlan(new Organization {PlanType = planType}) ? planType : null,
|
||||
}.Where(v => v.HasValue).Select(v => (PlanType)v);
|
||||
|
||||
public static IEnumerable<object[]> PlanTypes => Enum.GetValues<PlanType>().Select(p => new object[] { p });
|
||||
public static IEnumerable<object[]> PlanTypesExceptCustom =>
|
||||
Enum.GetValues<PlanType>().Except(new[] { PlanType.Custom }).Select(p => new object[] { p });
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(PlanTypesExceptCustom))]
|
||||
public void NonCustomPlanTypesBelongToPlanArchetype(PlanType planType)
|
||||
{
|
||||
Assert.Contains(planType, PlanArchetypeArray(planType));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(PlanTypesExceptCustom))]
|
||||
public void PlanTypesBelongToOnlyOneArchetype(PlanType planType)
|
||||
{
|
||||
Console.WriteLine(planType);
|
||||
Assert.Single(PlanArchetypeArray(planType));
|
||||
}
|
||||
}
|
||||
}
|
@ -34,15 +34,16 @@ namespace Bit.Core.Test.Services
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
public async Task OfferSponsorship_CreatesSponsorship(Organization sponsoringOrg, OrganizationUser sponsoringOrgUser,
|
||||
string sponsoredEmail, SutProvider<OrganizationSponsorshipService> sutProvider)
|
||||
string sponsoredEmail, string friendlyName, SutProvider<OrganizationSponsorshipService> sutProvider)
|
||||
{
|
||||
await sutProvider.Sut.OfferSponsorshipAsync(sponsoringOrg, sponsoringOrgUser,
|
||||
PlanSponsorshipType.FamiliesForEnterprise, sponsoredEmail);
|
||||
PlanSponsorshipType.FamiliesForEnterprise, sponsoredEmail, friendlyName);
|
||||
|
||||
var expectedSponsorship = new OrganizationSponsorship
|
||||
{
|
||||
SponsoringOrganizationId = sponsoringOrg.Id,
|
||||
SponsoringOrganizationUserId = sponsoringOrgUser.Id,
|
||||
FriendlyName = friendlyName,
|
||||
OfferedToEmail = sponsoredEmail,
|
||||
CloudSponsor = true,
|
||||
};
|
||||
@ -55,7 +56,7 @@ namespace Bit.Core.Test.Services
|
||||
[Theory]
|
||||
[BitAutoData]
|
||||
public async Task OfferSponsorship_CreateSponsorshipThrows_RevertsDatabase(Organization sponsoringOrg, OrganizationUser sponsoringOrgUser,
|
||||
string sponsoredEmail, SutProvider<OrganizationSponsorshipService> sutProvider)
|
||||
string sponsoredEmail, string friendlyName, SutProvider<OrganizationSponsorshipService> sutProvider)
|
||||
{
|
||||
var expectedException = new Exception();
|
||||
OrganizationSponsorship createdSponsorship = null;
|
||||
@ -68,7 +69,7 @@ namespace Bit.Core.Test.Services
|
||||
|
||||
var actualException = await Assert.ThrowsAsync<Exception>(() =>
|
||||
sutProvider.Sut.OfferSponsorshipAsync(sponsoringOrg, sponsoringOrgUser,
|
||||
PlanSponsorshipType.FamiliesForEnterprise, sponsoredEmail));
|
||||
PlanSponsorshipType.FamiliesForEnterprise, sponsoredEmail, friendlyName));
|
||||
Assert.Same(expectedException, actualException);
|
||||
|
||||
await sutProvider.GetDependency<IOrganizationSponsorshipRepository>().Received(1)
|
||||
|
Reference in New Issue
Block a user