public async Task RedeemSponsorship_BadToken_ThrowsBadRequest(string sponsorshipToken, User user, 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(false); var exception = await Assert.ThrowsAsync <BadRequestException>(() => sutProvider.Sut.RedeemSponsorship(sponsorshipToken, model)); Assert.Contains("Failed to parse sponsorship token.", exception.Message); await sutProvider.GetDependency <IOrganizationSponsorshipService>() .DidNotReceiveWithAnyArgs() .SetUpSponsorshipAsync(default, default);
public async Task RedeemSponsorship([FromQuery] string sponsorshipToken, [FromBody] OrganizationSponsorshipRedeemRequestModel model) { if (!await _organizationsSponsorshipService.ValidateRedemptionTokenAsync(sponsorshipToken, (await CurrentUser).Email)) { throw new BadRequestException("Failed to parse sponsorship token."); } if (!await _currentContext.OrganizationOwner(model.SponsoredOrganizationId)) { throw new BadRequestException("Can only redeem sponsorship for an organization you own."); } await _organizationsSponsorshipService.SetUpSponsorshipAsync( await _organizationSponsorshipRepository .GetByOfferedToEmailAsync((await CurrentUser).Email), // Check org to sponsor's product type await _organizationRepository.GetByIdAsync(model.SponsoredOrganizationId)); }
public async Task RedeemSponsorship([FromQuery] string sponsorshipToken, [FromBody] OrganizationSponsorshipRedeemRequestModel model) { var(valid, sponsorship) = await _validateRedemptionTokenCommand.ValidateRedemptionTokenAsync(sponsorshipToken, (await CurrentUser).Email); if (!valid) { throw new BadRequestException("Failed to parse sponsorship token."); } if (!await _currentContext.OrganizationOwner(model.SponsoredOrganizationId)) { throw new BadRequestException("Can only redeem sponsorship for an organization you own."); } await _setUpSponsorshipCommand.SetUpSponsorshipAsync( sponsorship, await _organizationRepository.GetByIdAsync(model.SponsoredOrganizationId)); }