Also extend Pest TestCase to Unit tests and guard MySQL-only migration DDL (composite PK + PARTITION BY) behind a driver check so in-memory SQLite tests can run migrations cleanly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
use App\Services\FuelPriceService;
|
|
use App\Services\StationTaggingService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function (): void {
|
|
$this->service = new FuelPriceService(new StationTaggingService());
|
|
});
|
|
|
|
it('fetches and caches an access token', function (): void {
|
|
Http::fake([
|
|
'*/oauth/generate_access_token' => Http::response([
|
|
'data' => [
|
|
'access_token' => 'test-token-abc',
|
|
'expires_in' => 3600,
|
|
],
|
|
]),
|
|
]);
|
|
|
|
$token = $this->service->getAccessToken();
|
|
|
|
expect($token)->toBe('test-token-abc');
|
|
expect(Cache::get('fuel_finder_access_token'))->toBe('test-token-abc');
|
|
});
|
|
|
|
it('returns cached token without hitting API', function (): void {
|
|
Cache::put('fuel_finder_access_token', 'cached-token', 3540);
|
|
|
|
Http::fake();
|
|
|
|
$token = $this->service->getAccessToken();
|
|
|
|
expect($token)->toBe('cached-token');
|
|
Http::assertNothingSent();
|
|
});
|