Improve tests
This commit is contained in:
parent
427debaba4
commit
48d1c9a00b
18 changed files with 267 additions and 14 deletions
|
@ -34,6 +34,50 @@ class MicropubMediaTest extends TestCase
|
|||
$response->assertJson(['url' => null]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function getRequestWithInvalidTokenReturnsErrorResponse(): void
|
||||
{
|
||||
$response = $this->get(
|
||||
'/api/media?q=last',
|
||||
['HTTP_Authorization' => 'Bearer abc123']
|
||||
);
|
||||
$response->assertStatus(400);
|
||||
$response->assertJsonFragment(['error_description' => 'The provided token did not pass validation']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function getRequestWithTokenWithoutScopeReturnsErrorResponse(): void
|
||||
{
|
||||
$response = $this->get(
|
||||
'/api/media?q=last',
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getTokenWithNoScope()]
|
||||
);
|
||||
$response->assertStatus(400);
|
||||
$response->assertJsonFragment(['error_description' => 'The provided token has no scopes']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function getRequestWithTokenWithInsufficientScopeReturnsErrorResponse(): void
|
||||
{
|
||||
$response = $this->get(
|
||||
'/api/media?q=last',
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getTokenWithIncorrectScope()]
|
||||
);
|
||||
$response->assertStatus(401);
|
||||
$response->assertJsonFragment(['error_description' => 'The token’s scope does not have the necessary requirements.']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function emptyGetRequestWithTokenReceivesOkResponse(): void
|
||||
{
|
||||
$response = $this->get(
|
||||
'/api/media',
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
);
|
||||
$response->assertStatus(200);
|
||||
$response->assertJson(['status' => 'OK']);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function clientCanListLastUpload(): void
|
||||
{
|
||||
|
@ -124,6 +168,22 @@ class MicropubMediaTest extends TestCase
|
|||
unlink(storage_path('app/') . $filename);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function mediaEndpointUploadRequiresFile(): void
|
||||
{
|
||||
$response = $this->post(
|
||||
'/api/media',
|
||||
[],
|
||||
['HTTP_Authorization' => 'Bearer ' . $this->getToken()]
|
||||
);
|
||||
$response->assertStatus(400);
|
||||
$response->assertJson([
|
||||
'response' => 'error',
|
||||
'error' => 'invalid_request',
|
||||
'error_description' => 'No file was sent with the request',
|
||||
]);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function errorResponseForUnknownQValue(): void
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue