Files
unified-restaurant-original/backend/tests/Auth0ServiceTest.php

34 lines
1.1 KiB
PHP

<?php
use App\Services\Auth0Service;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Http;
class Auth0ServiceTest extends TestCase {
public function testIsNotInCache() {
Redis::shouldReceive('get')->once()->with('auth0_token')->andReturns(null);
Http::fake([
'*' => Http::response([
"access_token" => "token",
"scope" => "read:client_grants",
"expires_in" => 86400,
"token_type" => "Bearer"
])
]);
Redis::shouldReceive('set')->with('auth0_token', "token", 'EX', 86400);
$tokenService = app(Auth0Service::class);
$this->assertEquals("token", $tokenService->getToken());
}
public function testIsInCache() {
Redis::shouldReceive('get')->once()->with('auth0_token')->andReturns("token");
Redis::shouldReceive('set')->never();
Http::shouldReceive('post')->never();
$tokenService = app(Auth0Service::class);
$this->assertEquals("token", $tokenService->getToken());
}
}