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
2 changes: 2 additions & 0 deletions src/Orbit.Application/Habits/Queries/GetHabitScheduleQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ private async Task<Result<PaginatedResponse<HabitScheduleItem>>> HandleScheduled

var dateFrom = request.DateFrom.Value;
var dateTo = request.DateTo.Value;
if (dateTo.DayNumber - dateFrom.DayNumber > AppConstants.MaxInstanceHorizonDays)
dateTo = dateFrom.AddDays(AppConstants.MaxInstanceHorizonDays);

var filtered = HabitScheduleFilters.FilterScheduledHabits(topLevel, dateFrom, dateTo, request.IncludeOverdue, lookup, weekStartDay);

Expand Down
7 changes: 5 additions & 2 deletions src/Orbit.Infrastructure/Services/StripeBillingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ public async Task<string> CreateCheckoutSessionAsync(
options.AllowPromotionCodes = true;
}

var idempotencyKey = $"orbit-checkout-{userId}-{priceId}-{referralCouponId ?? "std"}";
var session = await StripeRetryPolicy.ExecuteWithRetryAsync(
() => clients.CheckoutSessions.CreateAsync(options, cancellationToken: cancellationToken),
() => clients.CheckoutSessions.CreateAsync(
options, new RequestOptions { IdempotencyKey = idempotencyKey }, cancellationToken),
cancellationToken);
return session.Url;
}
Expand All @@ -90,12 +92,13 @@ public async Task<string> CreatePortalSessionAsync(string customerId, string ret
{
try
{
var idempotencyKey = $"orbit-portal-{customerId}";
var session = await StripeRetryPolicy.ExecuteWithRetryAsync(
() => clients.PortalSessions.CreateAsync(new Stripe.BillingPortal.SessionCreateOptions
{
Customer = customerId,
ReturnUrl = returnUrl,
}, cancellationToken: cancellationToken),
}, new RequestOptions { IdempotencyKey = idempotencyKey }, cancellationToken),
cancellationToken);
return session.Url;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,26 @@ public async Task Handle_SingleDailyHabitInRange_ReturnsHabit()
result.Value.Items[0].Title.Should().Be("Test Habit");
}

[Fact]
public async Task Handle_RangeExceedingHorizon_BoundsScheduledDatesAndInstancesConsistently()
{
var habit = CreateTestHabit(dueDate: Today);
SetupHabits(habit);
var query = new GetHabitScheduleQuery(UserId, Today, Today.AddDays(200));

var result = await _handler.Handle(query, CancellationToken.None);

result.IsSuccess.Should().BeTrue();
result.Value.Items.Should().HaveCount(1);
var item = result.Value.Items[0];
var horizonEnd = Today.AddDays(AppConstants.MaxInstanceHorizonDays);

item.ScheduledDates.Should().NotBeEmpty();
item.ScheduledDates.Max().Should().Be(horizonEnd);
item.Instances.Should().NotBeEmpty();
item.Instances.Select(i => i.Date).Max().Should().Be(horizonEnd);
}

[Fact]
public async Task Handle_OneTimeTaskOverdue_WhenIncludeOverdue_ReturnsAsOverdue()
{
Expand Down
Loading