Browse Source

Families for enterprise/fix new org sponsorship after deleted sponsored org (#1740)

* Sponsorship exists only if sponsored org is not null

* Replace existing sponsorship if necessary

* Update src/Core/Services/Implementations/OrganizationSponsorshipService.cs

Co-authored-by: Robyn MacCallum <nickersthecat@gmail.com>

* Fix tests

Co-authored-by: Robyn MacCallum <nickersthecat@gmail.com>
pull/1744/head
Matt Gibson 4 years ago committed by GitHub
parent
commit
a70564cea8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      src/Core/Services/Implementations/OrganizationSponsorshipService.cs
  2. 4
      test/Core.Test/Services/OrganizationSponsorshipServiceTests.cs

10
src/Core/Services/Implementations/OrganizationSponsorshipService.cs

@ -98,7 +98,7 @@ namespace Bit.Core.Services @@ -98,7 +98,7 @@ namespace Bit.Core.Services
var existingOrgSponsorship = await _organizationSponsorshipRepository
.GetBySponsoringOrganizationUserIdAsync(sponsoringOrgUser.Id);
if (existingOrgSponsorship != null)
if (existingOrgSponsorship?.SponsoredOrganizationId != null)
{
throw new BadRequestException("Can only sponsor one organization per Organization User.");
}
@ -113,9 +113,15 @@ namespace Bit.Core.Services @@ -113,9 +113,15 @@ namespace Bit.Core.Services
CloudSponsor = true,
};
if (existingOrgSponsorship != null)
{
// Replace existing invalid offer with our new sponsorship offer
sponsorship.Id = existingOrgSponsorship.Id;
}
try
{
sponsorship = await _organizationSponsorshipRepository.CreateAsync(sponsorship);
await _organizationSponsorshipRepository.UpsertAsync(sponsorship);
await SendSponsorshipOfferAsync(sponsorship, sponsoringUserEmail);
}

4
test/Core.Test/Services/OrganizationSponsorshipServiceTests.cs

@ -139,7 +139,7 @@ namespace Bit.Core.Test.Services @@ -139,7 +139,7 @@ namespace Bit.Core.Test.Services
};
await sutProvider.GetDependency<IOrganizationSponsorshipRepository>().Received(1)
.CreateAsync(Arg.Is<OrganizationSponsorship>(s => SponsorshipValidator(s, expectedSponsorship)));
.UpsertAsync(Arg.Is<OrganizationSponsorship>(s => SponsorshipValidator(s, expectedSponsorship)));
await sutProvider.GetDependency<IMailService>().Received(1).
SendFamiliesForEnterpriseOfferEmailAsync(sponsoredEmail, email,
@ -156,7 +156,7 @@ namespace Bit.Core.Test.Services @@ -156,7 +156,7 @@ namespace Bit.Core.Test.Services
var expectedException = new Exception();
OrganizationSponsorship createdSponsorship = null;
sutProvider.GetDependency<IOrganizationSponsorshipRepository>().CreateAsync(default).ThrowsForAnyArgs(callInfo =>
sutProvider.GetDependency<IOrganizationSponsorshipRepository>().UpsertAsync(default).ThrowsForAnyArgs(callInfo =>
{
createdSponsorship = callInfo.ArgAt<OrganizationSponsorship>(0);
createdSponsorship.Id = Guid.NewGuid();

Loading…
Cancel
Save