|
|
|
|
@ -45,7 +45,7 @@ namespace Bit.Api.Test.Controllers
@@ -45,7 +45,7 @@ namespace Bit.Api.Test.Controllers
|
|
|
|
|
sutProvider.GetDependency<IUserService>().GetUserByIdAsync(user.Id) |
|
|
|
|
.Returns(user); |
|
|
|
|
sutProvider.GetDependency<IOrganizationSponsorshipService>().ValidateRedemptionTokenAsync(sponsorshipToken, |
|
|
|
|
user.Email).Returns(false); |
|
|
|
|
user.Email).Returns((false, null)); |
|
|
|
|
|
|
|
|
|
var exception = await Assert.ThrowsAsync<BadRequestException>(() => |
|
|
|
|
sutProvider.Sut.RedeemSponsorship(sponsorshipToken, model)); |
|
|
|
|
@ -59,13 +59,14 @@ namespace Bit.Api.Test.Controllers
@@ -59,13 +59,14 @@ namespace Bit.Api.Test.Controllers
|
|
|
|
|
[Theory] |
|
|
|
|
[BitAutoData] |
|
|
|
|
public async Task RedeemSponsorship_NotSponsoredOrgOwner_ThrowsBadRequest(string sponsorshipToken, User user, |
|
|
|
|
OrganizationSponsorshipRedeemRequestModel model, SutProvider<OrganizationSponsorshipsController> sutProvider) |
|
|
|
|
OrganizationSponsorship sponsorship, OrganizationSponsorshipRedeemRequestModel model, |
|
|
|
|
SutProvider<OrganizationSponsorshipsController> sutProvider) |
|
|
|
|
{ |
|
|
|
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(user.Id); |
|
|
|
|
sutProvider.GetDependency<IUserService>().GetUserByIdAsync(user.Id) |
|
|
|
|
.Returns(user); |
|
|
|
|
sutProvider.GetDependency<IOrganizationSponsorshipService>().ValidateRedemptionTokenAsync(sponsorshipToken, |
|
|
|
|
user.Email).Returns(true); |
|
|
|
|
user.Email).Returns((true, sponsorship)); |
|
|
|
|
sutProvider.GetDependency<ICurrentContext>().OrganizationOwner(model.SponsoredOrganizationId).Returns(false); |
|
|
|
|
|
|
|
|
|
var exception = await Assert.ThrowsAsync<BadRequestException>(() => |
|
|
|
|
@ -77,14 +78,36 @@ namespace Bit.Api.Test.Controllers
@@ -77,14 +78,36 @@ namespace Bit.Api.Test.Controllers
|
|
|
|
|
.SetUpSponsorshipAsync(default, default); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Theory] |
|
|
|
|
[BitAutoData] |
|
|
|
|
public async Task RedeemSponsorship_NotSponsoredOrgOwner_Success(string sponsorshipToken, User user, |
|
|
|
|
OrganizationSponsorship sponsorship, Organization sponsoringOrganization, |
|
|
|
|
OrganizationSponsorshipRedeemRequestModel model, SutProvider<OrganizationSponsorshipsController> sutProvider) |
|
|
|
|
{ |
|
|
|
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(user.Id); |
|
|
|
|
sutProvider.GetDependency<IUserService>().GetUserByIdAsync(user.Id) |
|
|
|
|
.Returns(user); |
|
|
|
|
sutProvider.GetDependency<IOrganizationSponsorshipService>().ValidateRedemptionTokenAsync(sponsorshipToken, |
|
|
|
|
user.Email).Returns((true, sponsorship)); |
|
|
|
|
sutProvider.GetDependency<ICurrentContext>().OrganizationOwner(model.SponsoredOrganizationId).Returns(true); |
|
|
|
|
sutProvider.GetDependency<IOrganizationRepository>().GetByIdAsync(model.SponsoredOrganizationId).Returns(sponsoringOrganization); |
|
|
|
|
|
|
|
|
|
await sutProvider.Sut.RedeemSponsorship(sponsorshipToken, model); |
|
|
|
|
|
|
|
|
|
await sutProvider.GetDependency<IOrganizationSponsorshipService>().Received(1) |
|
|
|
|
.SetUpSponsorshipAsync(sponsorship, sponsoringOrganization); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
[Theory] |
|
|
|
|
[BitAutoData] |
|
|
|
|
public async Task PreValidateSponsorshipToken_ValidatesToken_Success(string sponsorshipToken, User user, |
|
|
|
|
SutProvider<OrganizationSponsorshipsController> sutProvider) |
|
|
|
|
OrganizationSponsorship sponsorship, SutProvider<OrganizationSponsorshipsController> sutProvider) |
|
|
|
|
{ |
|
|
|
|
sutProvider.GetDependency<ICurrentContext>().UserId.Returns(user.Id); |
|
|
|
|
sutProvider.GetDependency<IUserService>().GetUserByIdAsync(user.Id) |
|
|
|
|
.Returns(user); |
|
|
|
|
sutProvider.GetDependency<IOrganizationSponsorshipService>() |
|
|
|
|
.ValidateRedemptionTokenAsync(sponsorshipToken, user.Email).Returns((true, sponsorship)); |
|
|
|
|
|
|
|
|
|
await sutProvider.Sut.PreValidateSponsorshipToken(sponsorshipToken); |
|
|
|
|
|
|
|
|
|
|