Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ private async Task<Cart> GetPremiumCartAsync(

var (cartLevelDiscount, productLevelDiscounts) = GetStripeDiscounts(subscription);

var cartDiscount = cartLevelDiscount ?? await GetSchedulePhase2DiscountAsync(subscription);
var scheduleDiscount = cartLevelDiscount == null
? await GetSchedulePhase2DiscountAsync(subscription)
: null;

var availablePlan = plans.First(plan => plan.Available);
var onCurrentPricing = passwordManagerSeatsItem.Price.Id == availablePlan.Seat.StripePriceId;
Expand All @@ -133,7 +135,7 @@ private async Task<Cart> GetPremiumCartAsync(
TranslationKey = "premiumMembership",
Quantity = passwordManagerSeatsItem.Quantity,
Cost = seatCost,
Discount = productLevelDiscounts.FirstOrDefault(discount => discount.AppliesTo(passwordManagerSeatsItem))
Discount = productLevelDiscounts.FirstOrDefault(discount => discount.AppliesTo(passwordManagerSeatsItem)) ?? scheduleDiscount
};

var additionalStorage = additionalStorageItem != null
Expand All @@ -154,7 +156,7 @@ private async Task<Cart> GetPremiumCartAsync(
AdditionalStorage = additionalStorage
},
Cadence = PlanCadenceType.Annually,
Discount = cartDiscount,
Discount = cartLevelDiscount,
EstimatedTax = estimatedTax
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ public async Task Run_UserOnCurrentPricing_ReturnsCostFromSubscriptionItem()
}

[Fact]
public async Task Run_WithSchedulePhase2Discount_IncludesDiscountInCart()
public async Task Run_WithSchedulePhase2Discount_IncludesDiscountOnSeats()
{
var user = CreateUser();
var subscription = CreateSubscription(SubscriptionStatus.Active);
Expand All @@ -600,9 +600,10 @@ public async Task Run_WithSchedulePhase2Discount_IncludesDiscountInCart()
var result = await _query.Run(user);

Assert.NotNull(result);
Assert.NotNull(result.Cart.Discount);
Assert.Equal(BitwardenDiscountType.PercentOff, result.Cart.Discount.Type);
Assert.Equal(30, result.Cart.Discount.Value);
Assert.Null(result.Cart.Discount);
Assert.NotNull(result.Cart.PasswordManager.Seats.Discount);
Assert.Equal(BitwardenDiscountType.PercentOff, result.Cart.PasswordManager.Seats.Discount.Type);
Assert.Equal(30, result.Cart.PasswordManager.Seats.Discount.Value);
}

[Fact]
Expand Down Expand Up @@ -650,6 +651,7 @@ public async Task Run_WithScheduleButNoPhase2Discount_ReturnsNoDiscount()

Assert.NotNull(result);
Assert.Null(result.Cart.Discount);
Assert.Null(result.Cart.PasswordManager.Seats.Discount);
}

[Fact]
Expand All @@ -672,10 +674,11 @@ public async Task Run_WithScheduleStripeException_ReturnsNoDiscount()

Assert.NotNull(result);
Assert.Null(result.Cart.Discount);
Assert.Null(result.Cart.PasswordManager.Seats.Discount);
}

[Fact]
public async Task Run_WithSchedulePhase2AmountOffDiscount_IncludesAmountOffDiscountInCart()
public async Task Run_WithSchedulePhase2AmountOffDiscount_IncludesAmountOffDiscountOnSeats()
{
var user = CreateUser();
var subscription = CreateSubscription(SubscriptionStatus.Active);
Expand All @@ -694,9 +697,10 @@ public async Task Run_WithSchedulePhase2AmountOffDiscount_IncludesAmountOffDisco
var result = await _query.Run(user);

Assert.NotNull(result);
Assert.NotNull(result.Cart.Discount);
Assert.Equal(BitwardenDiscountType.AmountOff, result.Cart.Discount.Type);
Assert.Equal(500, result.Cart.Discount.Value);
Assert.Null(result.Cart.Discount);
Assert.NotNull(result.Cart.PasswordManager.Seats.Discount);
Assert.Equal(BitwardenDiscountType.AmountOff, result.Cart.PasswordManager.Seats.Discount.Type);
Assert.Equal(500, result.Cart.PasswordManager.Seats.Discount.Value);
}

[Fact]
Expand All @@ -720,6 +724,7 @@ public async Task Run_WithCompletedSchedule_ReturnsNoDiscount()

Assert.NotNull(result);
Assert.Null(result.Cart.Discount);
Assert.Null(result.Cart.PasswordManager.Seats.Discount);
}

[Fact]
Expand All @@ -743,6 +748,7 @@ public async Task Run_WithSchedulePhase2InvalidCoupon_ReturnsNoDiscount()

Assert.NotNull(result);
Assert.Null(result.Cart.Discount);
Assert.Null(result.Cart.PasswordManager.Seats.Discount);
}

#region Helper Methods
Expand Down
Loading