Skip to content

Commit

Permalink
Merge pull request #415 from loic425/fix/refresh-token-api-test
Browse files Browse the repository at this point in the history
Fix refresh token api test
  • Loading branch information
loic425 committed Apr 25, 2022
2 parents 3604fdc + 4abb68d commit f73a4d6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class LoginApiTest extends JsonApiTestCase
{
/** @test */
public function it_provides_an_access_token()
public function it_provides_an_access_token(): void
{
$this->loadFixturesFromFile('resources/fixtures.yaml');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,38 @@ public function it_allows_to_refresh_an_access_token(): void
{
$this->loadFixturesFromFile('resources/fixtures.yaml');

$refreshToken = $this->getRefreshToken();

$data =
<<<EOT
{
"refresh_token": "SampleRefreshTokenODllODY4ZTQyOThlNWIyMjA1ZDhmZjE1ZDYyMGMwOTUxOWM2NGFmNGRjNjQ2NDBhMDVlNGZjMmQ0YzgyNDM2Ng"
"refresh_token": "$refreshToken"
}
EOT;

$this->client->request('POST', '/api/token/refresh', [], [], ['CONTENT_TYPE' => 'application/json'], $data);

$response = $this->client->getResponse();
// $this->assertResponse($response, 'authentication/new_access_token', Response::HTTP_OK);
$this->assertResponse($response, 'authentication/new_access_token', Response::HTTP_OK);
}

private function getRefreshToken(): string
{
$data =
<<<EOT
{
"username": "api@sylius.com",
"password": "sylius"
}
EOT;

$this->client->request('POST', '/api/authentication_token', [], [], ['CONTENT_TYPE' => 'application/json'], $data);
$response = $this->client->getResponse();

$refreshToken = \json_decode($response->getContent(), true)['refresh_token'] ?: null;

$this->assertNotNull($refreshToken, 'Refresh token was not found but it should.');

return $refreshToken;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
Gesdinet\JWTRefreshTokenBundle\Entity\RefreshToken:
user_refresh_token:
username: sylius
valid: "<(new DateTimeImmutable('+4 hours'))>"
refresh_token: SampleRefreshTokenODllODY4ZTQyOThlNWIyMjA1ZDhmZjE1ZDYyMGMwOTUxOWM2NGFmNGRjNjQ2NDBhMDVlNGZjMmQ0YzgyNDM2Ng

App\Entity\User\AppUser:
user:
plain_password: sylius
Expand All @@ -22,11 +16,11 @@ App\Entity\User\AppUser:
password_reset_token: 'expired_t0ken'
password_requested_at: "<(new DateTime('2 days ago'))>"
another_user:
plain_password: sylius
plain_password: monofony
roles: [ROLE_USER]
enabled: true
customer: "@another_customer"
username: sylius
username: monofony

App\Entity\Customer\Customer:
customer:
Expand Down

0 comments on commit f73a4d6

Please sign in to comment.