1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-29 13:25:17 +01:00

Add is sponsored item to subscription response

This commit is contained in:
Matt Gibson 2021-11-10 18:05:31 -05:00 committed by Justin Baur
parent 3d28ae1547
commit be6ab1883c
5 changed files with 14 additions and 6 deletions

View File

@ -158,10 +158,15 @@ namespace Bit.Api.Controllers
var existingOrgSponsorship = await _organizationSponsorshipRepository
.GetBySponsoringOrganizationUserIdAsync(orgUser.Id);
if (existingOrgSponsorship == null || existingOrgSponsorship.SponsoredOrganizationId == null)
if (existingOrgSponsorship == null)
{
throw new BadRequestException("You are not currently sponsoring an organization.");
}
if (existingOrgSponsorship.SponsoredOrganizationId == null)
{
await _organizationSponsorshipRepository.DeleteAsync(existingOrgSponsorship);
return;
}
var sponsoredOrganization = await _organizationRepository
.GetByIdAsync(existingOrgSponsorship.SponsoredOrganizationId.Value);

View File

@ -82,12 +82,14 @@ namespace Bit.Core.Models.Api
Amount = item.Amount;
Interval = item.Interval;
Quantity = item.Quantity;
SponsoredSubscriptionItem = item.SponsoredSubscriptionItem;
}
public string Name { get; set; }
public decimal Amount { get; set; }
public int Quantity { get; set; }
public string Interval { get; set; }
public bool SponsoredSubscriptionItem { get; set; }
}
}

View File

@ -52,12 +52,14 @@ namespace Bit.Core.Models.Business
}
Quantity = (int)item.Quantity;
SponsoredSubscriptionItem = Utilities.StaticStore.SponsoredPlans.Any(p => p.StripePlanId == item.Plan.Id);
}
public string Name { get; set; }
public decimal Amount { get; set; }
public int Quantity { get; set; }
public string Interval { get; set; }
public bool SponsoredSubscriptionItem { get; set; }
}
}

View File

@ -198,8 +198,7 @@ namespace Bit.Core.Services
var sponsoredPlan = Utilities.StaticStore.GetSponsoredPlan(sponsorship.PlanSponsorshipType.Value);
var subscriptionUpdate = new SponsorOrganizationSubscriptionUpdate(existingPlan, sponsoredPlan, applySponsorship);
var prorationTime = DateTime.UtcNow;
await FinalizeSubscriptionChangeAsync(org, subscriptionUpdate, prorationTime);
await FinalizeSubscriptionChangeAsync(org, subscriptionUpdate, DateTime.UtcNow);
var sub = await _stripeAdapter.SubscriptionGetAsync(org.GatewaySubscriptionId);
org.ExpirationDate = sub.CurrentPeriodEnd;

View File

@ -393,10 +393,10 @@ namespace Bit.Api.Test.Controllers
.GetBySponsoringOrganizationUserIdAsync(orgUser.Id)
.Returns((OrganizationSponsorship)sponsorship);
var exception = await Assert.ThrowsAsync<BadRequestException>(() =>
sutProvider.Sut.RevokeSponsorship(orgUser.OrganizationId.ToString()));
await sutProvider.Sut.RevokeSponsorship(orgUser.OrganizationId.ToString());
await sutProvider.GetDependency<IOrganizationSponsorshipRepository>().Received(1).DeleteAsync(sponsorship);
Assert.Contains("You are not currently sponsoring an organization.", exception.Message);
await sutProvider.GetDependency<IOrganizationSponsorshipService>()
.DidNotReceiveWithAnyArgs()
.RemoveSponsorshipAsync(default, default);