feat: add LLM prediction providers with structured output support
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -11,8 +11,8 @@ beforeEach(function () {
|
||||
$this->withHeaders(['X-Api-Key' => config('app.api_secret_key')]);
|
||||
});
|
||||
|
||||
it('returns a prediction response for diesel', function () {
|
||||
$this->getJson('/api/prediction?fuel_type=diesel')
|
||||
it('returns a prediction response', function () {
|
||||
$this->getJson('/api/prediction')
|
||||
->assertOk()
|
||||
->assertJsonStructure([
|
||||
'fuel_type', 'current_avg', 'predicted_direction', 'predicted_change_pence',
|
||||
@@ -27,7 +27,7 @@ it('returns a prediction response for diesel', function () {
|
||||
'price_stickiness' => ['score', 'confidence', 'direction', 'detail', 'data_points', 'enabled'],
|
||||
],
|
||||
])
|
||||
->assertJsonPath('fuel_type', 'b7_standard')
|
||||
->assertJsonPath('fuel_type', 'e10')
|
||||
->assertJsonPath('region_key', 'national');
|
||||
});
|
||||
|
||||
@@ -35,29 +35,36 @@ it('includes current average from live prices', function () {
|
||||
$station = Station::factory()->create();
|
||||
StationPriceCurrent::factory()->create([
|
||||
'station_id' => $station->node_id,
|
||||
'fuel_type' => FuelType::B7Standard,
|
||||
'fuel_type' => FuelType::E10,
|
||||
'price_pence' => 14750,
|
||||
]);
|
||||
|
||||
$response = $this->getJson('/api/prediction?fuel_type=diesel')->assertOk();
|
||||
$response = $this->getJson('/api/prediction')->assertOk();
|
||||
|
||||
expect($response->json('current_avg'))->toBe(147.5);
|
||||
});
|
||||
|
||||
it('accepts optional lat and lng for regional context', function () {
|
||||
$this->getJson('/api/prediction?fuel_type=diesel&lat=52.5&lng=-0.2')
|
||||
it('returns regional prediction when lat and lng are provided', function () {
|
||||
$this->getJson('/api/prediction?lat=52.5&lng=-0.2')
|
||||
->assertOk()
|
||||
->assertJsonPath('region_key', 'national'); // still national, regional_momentum signal updated internally
|
||||
->assertJsonPath('region_key', 'regional')
|
||||
->assertJsonPath('fuel_type', 'e10');
|
||||
});
|
||||
|
||||
it('returns 422 when fuel_type is missing', function () {
|
||||
it('returns national prediction without coordinates', function () {
|
||||
$this->getJson('/api/prediction')
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['fuel_type']);
|
||||
->assertOk()
|
||||
->assertJsonPath('region_key', 'national');
|
||||
});
|
||||
|
||||
it('returns 422 for unknown fuel_type alias', function () {
|
||||
$this->getJson('/api/prediction?fuel_type=rocket_fuel')
|
||||
it('returns 422 for invalid lat', function () {
|
||||
$this->getJson('/api/prediction?lat=999&lng=0')
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['fuel_type']);
|
||||
->assertJsonValidationErrors(['lat']);
|
||||
});
|
||||
|
||||
it('returns 422 for invalid lng', function () {
|
||||
$this->getJson('/api/prediction?lat=51.5&lng=999')
|
||||
->assertUnprocessable()
|
||||
->assertJsonValidationErrors(['lng']);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user