Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
minor #15927 [API] Missing AvatarImage Tests (Rafikooo)
This PR was merged into the 1.13 branch. Discussion ---------- | Q | A | |-----------------|--------------------------------------------------------------| | Branch? | 1.13 <!-- see the comment below --> | | Bug fix? | no | | New feature? | no | | BC breaks? | no | | Deprecations? | no<!-- don't forget to update the UPGRADE-*.md file --> | | License | MIT | <!-- - Bug fixes must be submitted against the 1.12 branch - Features and deprecations must be submitted against the 1.13 branch - Make sure that the correct base branch is set To be sure you are not breaking any Backward Compatibilities, check the documentation: https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html --> Commits ------- [API] Add contract tests for AvatarImage Api resources [Unit][Admin] Cherry-pick avatar-image tests
- Loading branch information
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Sylius package. | ||
* | ||
* (c) Sylius Sp. z o.o. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Api\Admin; | ||
|
||
use Sylius\Component\Core\Model\AdminUserInterface; | ||
use Sylius\Component\Core\Model\AvatarImageInterface; | ||
use Sylius\Tests\Api\JsonApiTestCase; | ||
use Sylius\Tests\Api\Utils\AdminUserLoginTrait; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
final class AvatarImageTest extends JsonApiTestCase | ||
{ | ||
use AdminUserLoginTrait; | ||
|
||
/** @test */ | ||
public function it_gets_an_avatar_image(): void | ||
{ | ||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'avatar_image.yaml']); | ||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER); | ||
|
||
/** @var AvatarImageInterface $avatarImage */ | ||
$avatarImage = $fixtures['avatar_image']; | ||
|
||
$this->client->request( | ||
method: 'GET', | ||
uri: sprintf('/api/v2/admin/avatar-images/%s', $avatarImage->getId()), | ||
server: $header, | ||
); | ||
|
||
$this->assertResponse( | ||
$this->client->getResponse(), | ||
'admin/avatar_image/get_an_avatar_image', | ||
Response::HTTP_OK, | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function it_gets_nothing_if_avatar_image_not_found(): void | ||
{ | ||
$this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'avatar_image.yaml']); | ||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER); | ||
|
||
$this->client->request( | ||
method: 'GET', | ||
uri: sprintf('/api/v2/admin/avatar-images/%s', 'wrong input'), | ||
server: $header, | ||
); | ||
|
||
$response = $this->client->getResponse(); | ||
|
||
$this->assertSame(Response::HTTP_NOT_FOUND, $response->getStatusCode()); | ||
} | ||
|
||
/** @test */ | ||
public function it_creates_an_avatar_image(): void | ||
{ | ||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'avatar_image.yaml']); | ||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER); | ||
|
||
/** @var AdminUserInterface $adminUser */ | ||
$adminUser = $fixtures['admin']; | ||
|
||
$this->client->request( | ||
method: 'POST', | ||
uri: '/api/v2/admin/avatar-images', | ||
parameters: [ | ||
'owner' => sprintf('/api/v2/admin/administrators/%s', $adminUser->getId()), | ||
], | ||
files: ['file' => $this->getUploadedFile('fixtures/ford.jpg', 'ford.jpg')], | ||
server: $header, | ||
); | ||
|
||
$response = $this->client->getResponse(); | ||
$this->assertResponse( | ||
$response, | ||
'admin/avatar_image/post_avatar_image', | ||
Response::HTTP_CREATED, | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function it_deletes_an_avatar_image(): void | ||
{ | ||
$fixtures = $this->loadFixturesFromFiles(['authentication/api_administrator.yaml', 'avatar_image.yaml']); | ||
$header = array_merge($this->logInAdminUser('api@example.com'), self::CONTENT_TYPE_HEADER); | ||
|
||
/** @var AvatarImageInterface $avatarImage */ | ||
$avatarImage = $fixtures['avatar_image']; | ||
|
||
$this->client->request( | ||
method: 'DELETE', | ||
uri: sprintf('/api/v2/admin/avatar-images/%s', $avatarImage->getId()), | ||
server: $header, | ||
); | ||
|
||
$this->assertResponseCode($this->client->getResponse(), Response::HTTP_NO_CONTENT); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Sylius\Component\Core\Model\AvatarImage: | ||
avatar_image: | ||
owner: "@admin" | ||
path: "uo/avatar_image.jpg" |
8 changes: 8 additions & 0 deletions
8
tests/Api/Responses/admin/avatar_image/get_an_avatar_image.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"@context": "/api/v2/contexts/AvatarImage", | ||
"@id": "/api/v2/admin/avatar-images/@integer@", | ||
"@type": "AvatarImage", | ||
"id": @integer@, | ||
"path": "uo/avatar_image.jpg", | ||
"owner": "\/api\/v2\/admin\/administrators/@integer@" | ||
} |
8 changes: 8 additions & 0 deletions
8
tests/Api/Responses/admin/avatar_image/post_avatar_image.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"@context": "/api/v2/contexts/AvatarImage", | ||
"@id": "/api/v2/admin/avatar-images/@integer@", | ||
"@type": "AvatarImage", | ||
"id": @integer@, | ||
"path": "@string@\/ford.jpg", | ||
"owner": "\/api\/v2\/admin\/administrators/@integer@" | ||
} |