Skip to content

Commit

Permalink
fix: tests and formats option
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Oct 4, 2023
1 parent 515be20 commit a34ac7f
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
1 change: 0 additions & 1 deletion api/config/packages/api_platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ api_platform:
graphql_playground: false
formats:
jsonld: ['application/ld+json']
json: ['application/json']
docs_formats:
jsonld: ['application/ld+json']
jsonopenapi: ['application/vnd.openapi+json']
Expand Down
31 changes: 29 additions & 2 deletions api/tests/Api/Admin/BookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ public function testAsNonAdminUserICannotCreateABook(int $expectedCode, string $
'book' => 'https://openlibrary.org/books/OL28346544M.json',
'condition' => BookCondition::NewCondition->value,
],
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
]);

self::assertResponseStatusCodeSame($expectedCode);
Expand All @@ -269,6 +273,10 @@ public function testAsAdminUserICannotCreateABookWithInvalidData(array $data, in
$this->client->request('POST', '/admin/books', [
'auth_bearer' => $token,
'json' => $data,
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
]);

self::assertResponseStatusCodeSame($statusCode);
Expand Down Expand Up @@ -389,6 +397,10 @@ public function testAsAdminUserICanCreateABook(): void
'book' => 'https://openlibrary.org/books/OL28346544M.json',
'condition' => BookCondition::NewCondition->value,
],
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
]);

self::assertResponseStatusCodeSame(Response::HTTP_CREATED);
Expand Down Expand Up @@ -448,6 +460,10 @@ public function testAsNonAdminUserICannotUpdateBook(int $expectedCode, string $h
'book' => 'https://openlibrary.org/books/OL28346544M.json',
'condition' => BookCondition::NewCondition->value,
],
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
]);

self::assertResponseStatusCodeSame($expectedCode);
Expand All @@ -473,6 +489,10 @@ public function testAsAdminUserICannotUpdateAnInvalidBook(): void
'json' => [
'condition' => BookCondition::DamagedCondition->value,
],
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
]);

self::assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
Expand All @@ -492,6 +512,10 @@ public function testAsAdminUserICannotUpdateABookWithInvalidData(array $data, in
$this->client->request('PUT', '/admin/books/'.$book->getId(), [
'auth_bearer' => $token,
'json' => $data,
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
]);

self::assertResponseStatusCodeSame($statusCode);
Expand All @@ -518,12 +542,15 @@ public function testAsAdminUserICanUpdateABook(): void
$this->client->request('PUT', '/admin/books/'.$book->getId(), [
'auth_bearer' => $token,
'json' => [
/* @see https://github.com/api-platform/core/blob/main/src/Serializer/ItemNormalizer.php */
'id' => '/books/'.$book->getId(),
'@id' => '/books/'.$book->getId(),
// Must set all data because of standard PUT
'book' => 'https://openlibrary.org/books/OL28346544M.json',
'condition' => BookCondition::DamagedCondition->value,
],
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
]);

self::assertResponseStatusCodeSame(Response::HTTP_OK);
Expand Down
12 changes: 12 additions & 0 deletions api/tests/Api/Admin/ReviewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ public function testAsNonAdminUserICannotUpdateAReview(int $expectedCode, string
'body' => 'Very good book!',
'rating' => 5,
],
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
]);

self::assertResponseStatusCodeSame($expectedCode);
Expand All @@ -240,6 +244,10 @@ public function testAsAdminUserICannotUpdateAnInvalidReview(): void
'body' => 'Very good book!',
'rating' => 5,
],
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
]);

self::assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
Expand Down Expand Up @@ -267,6 +275,10 @@ public function testAsAdminUserICanUpdateAReview(): void
'body' => 'Very good book!',
'rating' => 5,
],
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
]);

self::assertResponseStatusCodeSame(Response::HTTP_OK);
Expand Down
16 changes: 16 additions & 0 deletions api/tests/Api/BookmarkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public function testAsAnonymousICannotCreateABookmark(): void
'json' => [
'book' => '/books/'.$book->getId(),
],
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
]);

self::assertResponseStatusCodeSame(Response::HTTP_UNAUTHORIZED);
Expand All @@ -105,6 +109,10 @@ public function testAsAUserICannotCreateABookmarkWithInvalidData(): void
'json' => [
'book' => '/books/'.$uuid,
],
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
'auth_bearer' => $token,
]);

Expand Down Expand Up @@ -149,6 +157,10 @@ public function testAsAUserICanCreateABookmark(): void
'json' => [
'book' => '/books/'.$book->getId(),
],
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
'auth_bearer' => $token,
]);

Expand Down Expand Up @@ -190,6 +202,10 @@ public function testAsAUserICannotCreateADuplicateBookmark(): void
'json' => [
'book' => '/books/'.$book->getId(),
],
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
'auth_bearer' => $token,
]);

Expand Down
20 changes: 20 additions & 0 deletions api/tests/Api/ReviewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ public function testAsAnonymousICannotAddAReviewOnABook(): void
'body' => 'Very good book!',
'rating' => 5,
],
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
]);

self::assertResponseStatusCodeSame(Response::HTTP_UNAUTHORIZED);
Expand All @@ -163,6 +167,10 @@ public function testAsAUserICannotAddAReviewOnABookWithInvalidData(array $data,
$this->client->request('POST', '/books/'.$book->getId().'/reviews', [
'auth_bearer' => $token,
'json' => $data,
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
]);

self::assertResponseStatusCodeSame($statusCode);
Expand Down Expand Up @@ -209,6 +217,10 @@ public function testAsAUserICannotAddAReviewWithValidDataOnAnInvalidBook(): void
'body' => 'Very good book!',
'rating' => 5,
],
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
]);

self::assertResponseStatusCodeSame(Response::HTTP_NOT_FOUND);
Expand Down Expand Up @@ -241,6 +253,10 @@ public function testAsAUserICanAddAReviewOnABook(): void
'body' => 'Very good book!',
'rating' => 5,
],
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
]);

self::assertResponseStatusCodeSame(Response::HTTP_CREATED);
Expand Down Expand Up @@ -290,6 +306,10 @@ public function testAsAUserICannotAddADuplicateReviewOnABook(): void
'body' => 'Very good book!',
'rating' => 5,
],
'headers' => [
'Content-Type' => 'application/ld+json',
'Accept' => 'application/ld+json',
],
]);

self::assertResponseStatusCodeSame(Response::HTTP_UNPROCESSABLE_ENTITY);
Expand Down

0 comments on commit a34ac7f

Please sign in to comment.