Remove prediction API endpoint and integrate into stations search
Consolidate prediction functionality by merging /api/prediction endpoint into /api/stations response. Move prediction logic from PredictionController into StationController, returning prediction data alongside station results. Replace usePrediction composable with unified useStations that returns {stations, meta, prediction}. Remove PredictionRequest, related tests, and unused Vue components (FuelFinderTest, MapTest, RecommendationTest, StationListTest). Add PredictionFull component and UpsellBanner. Extend NationalFuelPredictionService to include weekly_summary (7-day series, yesterday/today averages, cheapest/priciest days) and oil signal from price_predictions table. Update Home.vue to consume prediction from stations response. Add Plan::resolveCadenceForUser helper and configure Cashier to use custom Subscription model.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
@@ -68,6 +69,146 @@ it('returns the authenticated user on /me', function () {
|
||||
->assertJsonPath('email', $user->email);
|
||||
});
|
||||
|
||||
it('reports subscription_cancelled=false for a user with no subscription', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->getJson('/api/auth/me')
|
||||
->assertOk()
|
||||
->assertJsonPath('subscription_cancelled', false);
|
||||
});
|
||||
|
||||
it('reports subscription_cancelled=false for an active paid subscription', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$user->subscriptions()->create([
|
||||
'type' => 'default',
|
||||
'stripe_id' => 'sub_active',
|
||||
'stripe_status' => 'active',
|
||||
'stripe_price' => 'price_plus_monthly',
|
||||
'quantity' => 1,
|
||||
]);
|
||||
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->getJson('/api/auth/me')
|
||||
->assertOk()
|
||||
->assertJsonPath('subscription_cancelled', false);
|
||||
});
|
||||
|
||||
it('reports subscription_cancelled=true once the subscription is set to end at period end', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$user->subscriptions()->create([
|
||||
'type' => 'default',
|
||||
'stripe_id' => 'sub_cancelling',
|
||||
'stripe_status' => 'active',
|
||||
'stripe_price' => 'price_plus_monthly',
|
||||
'quantity' => 1,
|
||||
'ends_at' => now()->addDays(20),
|
||||
]);
|
||||
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->getJson('/api/auth/me')
|
||||
->assertOk()
|
||||
->assertJsonPath('subscription_cancelled', true);
|
||||
});
|
||||
|
||||
it('exposes subscribed_at, cadence and renewal date for an active monthly subscription', function () {
|
||||
Plan::create([
|
||||
'name' => 'plus',
|
||||
'stripe_price_id_monthly' => 'price_plus_monthly_test',
|
||||
'stripe_price_id_annual' => 'price_plus_annual_test',
|
||||
'features' => ['fuel_types' => ['max' => 1]],
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$subscribedAt = now()->subDays(10)->startOfSecond();
|
||||
$renewalAt = now()->addDays(20)->startOfSecond();
|
||||
|
||||
$user->subscriptions()->create([
|
||||
'type' => 'default',
|
||||
'stripe_id' => 'sub_monthly_active',
|
||||
'stripe_status' => 'active',
|
||||
'stripe_price' => 'price_plus_monthly_test',
|
||||
'quantity' => 1,
|
||||
'current_period_end' => $renewalAt,
|
||||
'created_at' => $subscribedAt,
|
||||
'updated_at' => $subscribedAt,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user, 'sanctum')
|
||||
->getJson('/api/auth/me')
|
||||
->assertOk()
|
||||
->assertJsonPath('subscription_cancelled', false)
|
||||
->assertJsonPath('subscription_cadence', 'monthly');
|
||||
|
||||
expect($response->json('subscribed_at'))->toStartWith($subscribedAt->toDateString());
|
||||
expect($response->json('subscription_expires_at'))->toStartWith($renewalAt->toDateString());
|
||||
});
|
||||
|
||||
it('reports cadence as annual when the active price is the annual one', function () {
|
||||
Plan::create([
|
||||
'name' => 'pro',
|
||||
'stripe_price_id_monthly' => 'price_pro_monthly_test',
|
||||
'stripe_price_id_annual' => 'price_pro_annual_test',
|
||||
'features' => ['fuel_types' => ['max' => null]],
|
||||
'active' => true,
|
||||
]);
|
||||
|
||||
$user = User::factory()->create();
|
||||
|
||||
$user->subscriptions()->create([
|
||||
'type' => 'default',
|
||||
'stripe_id' => 'sub_annual_active',
|
||||
'stripe_status' => 'active',
|
||||
'stripe_price' => 'price_pro_annual_test',
|
||||
'quantity' => 1,
|
||||
]);
|
||||
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->getJson('/api/auth/me')
|
||||
->assertOk()
|
||||
->assertJsonPath('subscription_cadence', 'annual');
|
||||
});
|
||||
|
||||
it('uses ends_at as the expiry date when subscription is cancelled', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$endsAt = now()->addDays(15)->startOfSecond();
|
||||
$renewalAt = now()->addDays(30)->startOfSecond();
|
||||
|
||||
$user->subscriptions()->create([
|
||||
'type' => 'default',
|
||||
'stripe_id' => 'sub_cancelling_with_period',
|
||||
'stripe_status' => 'active',
|
||||
'stripe_price' => 'price_plus_monthly',
|
||||
'quantity' => 1,
|
||||
'ends_at' => $endsAt,
|
||||
'current_period_end' => $renewalAt,
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($user, 'sanctum')
|
||||
->getJson('/api/auth/me')
|
||||
->assertOk()
|
||||
->assertJsonPath('subscription_cancelled', true);
|
||||
|
||||
expect($response->json('subscription_expires_at'))->toStartWith($endsAt->toDateString());
|
||||
});
|
||||
|
||||
it('returns null subscription metadata for users with no subscription', function () {
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->actingAs($user, 'sanctum')
|
||||
->getJson('/api/auth/me')
|
||||
->assertOk()
|
||||
->assertJsonPath('subscription_cancelled', false)
|
||||
->assertJsonPath('subscription_cadence', null)
|
||||
->assertJsonPath('subscribed_at', null)
|
||||
->assertJsonPath('subscription_expires_at', null);
|
||||
});
|
||||
|
||||
it('logs out and revokes the token', function () {
|
||||
$user = User::factory()->create();
|
||||
$token = $user->createToken('api')->plainTextToken;
|
||||
|
||||
Reference in New Issue
Block a user