feat: gate full prediction by ai_predictions feature flag
Add a prediction box above filter results on the homepage.
Server returns the full payload only when PlanFeatures::can(
'ai_predictions') — currently plus and pro. Other tiers and
guests get a trimmed {fuel_type, predicted_direction,
tier_locked: true} response so the gate is enforced server-side.
Frontend renders a compact one-liner with the national trend
direction for trimmed responses, full card for unlocked.
Hide the Pro plan card from the pricing section (pro plan
disabled in DB pending real Stripe price ids), and only show
the bottom signup CTA when the visitor is a guest.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,17 +1,44 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\FuelType;
|
||||
use App\Filament\Resources\UserResource;
|
||||
use App\Models\Station;
|
||||
use App\Models\StationPriceCurrent;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
beforeEach(function () {
|
||||
$this->withHeaders(['X-Api-Key' => config('app.api_secret_key')]);
|
||||
$this->artisan('db:seed', ['--class' => 'PlanSeeder']);
|
||||
});
|
||||
|
||||
it('returns a prediction response', function () {
|
||||
function actAsTier(string $tier): User
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
if ($tier !== 'free') {
|
||||
UserResource::applyTier($user, $tier, 'monthly');
|
||||
}
|
||||
|
||||
test()->actingAs($user->fresh());
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
it('returns the full payload for plus users', function () {
|
||||
actAsTier('plus');
|
||||
|
||||
$this->getJson('/api/prediction')
|
||||
->assertOk()
|
||||
->assertJsonStructure(['fuel_type', 'reasoning', 'signals'])
|
||||
->assertJsonMissingPath('tier_locked');
|
||||
});
|
||||
|
||||
it('returns the full payload for pro users', function () {
|
||||
actAsTier('pro');
|
||||
|
||||
$this->getJson('/api/prediction')
|
||||
->assertOk()
|
||||
->assertJsonStructure([
|
||||
@@ -31,7 +58,40 @@ it('returns a prediction response', function () {
|
||||
->assertJsonPath('region_key', 'national');
|
||||
});
|
||||
|
||||
it('includes current average from live prices', function () {
|
||||
it('returns only direction + tier_locked flag for guests', function () {
|
||||
$response = $this->getJson('/api/prediction')->assertOk();
|
||||
|
||||
expect($response->json())
|
||||
->toHaveKey('fuel_type')
|
||||
->toHaveKey('predicted_direction')
|
||||
->toHaveKey('tier_locked', true)
|
||||
->not->toHaveKey('current_avg')
|
||||
->not->toHaveKey('reasoning')
|
||||
->not->toHaveKey('signals');
|
||||
});
|
||||
|
||||
it('returns the trimmed payload for free users', function () {
|
||||
actAsTier('free');
|
||||
|
||||
$this->getJson('/api/prediction')
|
||||
->assertOk()
|
||||
->assertJsonPath('tier_locked', true)
|
||||
->assertJsonMissing(['signals' => []])
|
||||
->assertJsonMissingPath('reasoning');
|
||||
});
|
||||
|
||||
it('returns the trimmed payload for basic users', function () {
|
||||
actAsTier('basic');
|
||||
|
||||
$this->getJson('/api/prediction')
|
||||
->assertOk()
|
||||
->assertJsonPath('tier_locked', true)
|
||||
->assertJsonMissingPath('reasoning');
|
||||
});
|
||||
|
||||
it('includes current average from live prices for pro users', function () {
|
||||
actAsTier('pro');
|
||||
|
||||
$station = Station::factory()->create();
|
||||
StationPriceCurrent::factory()->create([
|
||||
'station_id' => $station->node_id,
|
||||
@@ -44,14 +104,18 @@ it('includes current average from live prices', function () {
|
||||
expect($response->json('current_avg'))->toBe(147.5);
|
||||
});
|
||||
|
||||
it('returns regional prediction when lat and lng are provided', function () {
|
||||
it('returns regional prediction when lat and lng are provided to pro users', function () {
|
||||
actAsTier('pro');
|
||||
|
||||
$this->getJson('/api/prediction?lat=52.5&lng=-0.2')
|
||||
->assertOk()
|
||||
->assertJsonPath('region_key', 'regional')
|
||||
->assertJsonPath('fuel_type', 'e10');
|
||||
});
|
||||
|
||||
it('returns national prediction without coordinates', function () {
|
||||
it('returns national prediction without coordinates for pro users', function () {
|
||||
actAsTier('pro');
|
||||
|
||||
$this->getJson('/api/prediction')
|
||||
->assertOk()
|
||||
->assertJsonPath('region_key', 'national');
|
||||
|
||||
Reference in New Issue
Block a user