Skip to content

Commit 42b46fb

Browse files
fix: fix mercure configuration on Review and Book
1 parent 701898e commit 42b46fb

File tree

8 files changed

+36
-8
lines changed

8 files changed

+36
-8
lines changed

api/src/Entity/Book.php

+6
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@
9090
normalizationContext: [
9191
AbstractNormalizer::GROUPS => ['Book:read', 'Enum:read'],
9292
AbstractObjectNormalizer::SKIP_NULL_VALUES => true,
93+
],
94+
mercure: [
95+
'topics' => [
96+
'@=iri(object, ' . UrlGeneratorInterface::ABS_URL . ', get_operation(object, "/admin/books/{id}{._format}"))',
97+
'@=iri(object, ' . UrlGeneratorInterface::ABS_URL . ', get_operation(object, "/books/{id}{._format}"))',
98+
],
9399
]
94100
)]
95101
#[ORM\Entity(repositoryClass: BookRepository::class)]

api/src/Entity/Review.php

+7-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,13 @@
142142
denormalizationContext: [
143143
AbstractNormalizer::GROUPS => ['Review:write'],
144144
],
145-
collectDenormalizationErrors: true
145+
collectDenormalizationErrors: true,
146+
mercure: [
147+
'topics' => [
148+
'@=iri(object, ' . UrlGeneratorInterface::ABS_URL . ', get_operation(object, "/admin/reviews/{id}{._format}"))',
149+
'@=iri(object, ' . UrlGeneratorInterface::ABS_URL . ', get_operation(object, "/books/{bookId}/reviews/{id}{._format}"))',
150+
],
151+
]
146152
)]
147153
#[ORM\Entity(repositoryClass: ReviewRepository::class)]
148154
#[ORM\UniqueConstraint(fields: ['user', 'book'])]

api/tests/Api/Admin/BookTest.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function asAdminUserICanGetACollectionOfBooks(FactoryCollection $factory,
7575

7676
self::assertResponseIsSuccessful();
7777
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
78+
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders()['link'][1]);
7879
self::assertJsonContains([
7980
'hydra:totalItems' => $hydraTotalItems,
8081
]);
@@ -142,6 +143,7 @@ public function asAdminUserICanGetACollectionOfBooksOrderedByTitle(): void
142143

143144
self::assertResponseIsSuccessful();
144145
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
146+
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders()['link'][1]);
145147
self::assertEquals('Ball Lightning', $response->toArray()['hydra:member'][0]['title']);
146148
self::assertEquals('Hyperion', $response->toArray()['hydra:member'][1]['title']);
147149
self::assertEquals('The Wandering Earth', $response->toArray()['hydra:member'][2]['title']);
@@ -210,10 +212,11 @@ public function asAdminUserICanGetABook(): void
210212
'email' => UserFactory::createOneAdmin()->email,
211213
]);
212214

213-
$this->client->request('GET', '/admin/books/' . $book->getId(), ['auth_bearer' => $token]);
215+
$response = $this->client->request('GET', '/admin/books/' . $book->getId(), ['auth_bearer' => $token]);
214216

215217
self::assertResponseIsSuccessful();
216218
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
219+
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders(false)['link'][1]);
217220
self::assertJsonContains([
218221
'@id' => '/admin/books/' . $book->getId(),
219222
'book' => $book->book,
@@ -385,6 +388,7 @@ public function asAdminUserICanCreateABook(): void
385388

386389
self::assertResponseStatusCodeSame(Response::HTTP_CREATED);
387390
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
391+
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders(false)['link'][1]);
388392
self::assertJsonContains([
389393
'book' => 'https://openlibrary.org/books/OL28346544M.json',
390394
'condition' => BookCondition::NewCondition->value,
@@ -508,7 +512,7 @@ public function asAdminUserICanUpdateABook(): void
508512
'email' => UserFactory::createOneAdmin()->email,
509513
]);
510514

511-
$this->client->request('PUT', '/admin/books/' . $book->getId(), [
515+
$response = $this->client->request('PUT', '/admin/books/' . $book->getId(), [
512516
'auth_bearer' => $token,
513517
'json' => [
514518
'@id' => '/books/' . $book->getId(),
@@ -524,6 +528,7 @@ public function asAdminUserICanUpdateABook(): void
524528

525529
self::assertResponseStatusCodeSame(Response::HTTP_OK);
526530
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
531+
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders(false)['link'][1]);
527532
self::assertJsonContains([
528533
'book' => 'https://openlibrary.org/books/OL28346544M.json',
529534
'condition' => BookCondition::DamagedCondition->value,

api/tests/Api/Admin/ReviewTest.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public function asAdminUserICanGetACollectionOfReviews(FactoryCollection $factor
7979

8080
self::assertResponseIsSuccessful();
8181
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
82+
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders()['link'][1]);
8283
self::assertJsonContains([
8384
'hydra:totalItems' => $hydraTotalItems,
8485
]);
@@ -189,10 +190,11 @@ public function asAdminUserICanGetAReview(): void
189190
'email' => UserFactory::createOneAdmin()->email,
190191
]);
191192

192-
$this->client->request('GET', '/admin/reviews/' . $review->getId(), ['auth_bearer' => $token]);
193+
$response = $this->client->request('GET', '/admin/reviews/' . $review->getId(), ['auth_bearer' => $token]);
193194

194195
self::assertResponseIsSuccessful();
195196
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
197+
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders(false)['link'][1]);
196198
self::assertMatchesJsonSchema(file_get_contents(__DIR__ . '/schemas/Review/item.json'));
197199
}
198200

@@ -268,7 +270,7 @@ public function asAdminUserICanUpdateAReview(): void
268270
'email' => $user->email,
269271
]);
270272

271-
$this->client->request('PUT', '/admin/reviews/' . $review->getId(), [
273+
$response = $this->client->request('PUT', '/admin/reviews/' . $review->getId(), [
272274
'auth_bearer' => $token,
273275
'json' => [
274276
// Must set all data because of standard PUT
@@ -285,6 +287,7 @@ public function asAdminUserICanUpdateAReview(): void
285287

286288
self::assertResponseStatusCodeSame(Response::HTTP_OK);
287289
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
290+
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders(false)['link'][1]);
288291
self::assertJsonContains([
289292
'body' => 'Very good book!',
290293
'rating' => 5,

api/tests/Api/Admin/UserTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function asAdminUserICanGetAUser(): void
138138
'email' => UserFactory::createOneAdmin()->email,
139139
]);
140140

141-
$this->client->request('GET', '/admin/users/' . $user->getId(), ['auth_bearer' => $token]);
141+
$response = $this->client->request('GET', '/admin/users/' . $user->getId(), ['auth_bearer' => $token]);
142142

143143
self::assertResponseIsSuccessful();
144144
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');

api/tests/Api/BookTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function asAnonymousICanGetACollectionOfBooks(FactoryCollection $factory,
3939

4040
self::assertResponseIsSuccessful();
4141
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
42+
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders()['link'][1]);
4243
self::assertJsonContains([
4344
'hydra:totalItems' => $hydraTotalItems,
4445
]);
@@ -96,6 +97,7 @@ public function asAdminUserICanGetACollectionOfBooksOrderedByTitle(): void
9697

9798
self::assertResponseIsSuccessful();
9899
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
100+
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders()['link'][1]);
99101
self::assertEquals('Ball Lightning', $response->toArray()['hydra:member'][0]['title']);
100102
self::assertEquals('Hyperion', $response->toArray()['hydra:member'][1]['title']);
101103
self::assertEquals('The Wandering Earth', $response->toArray()['hydra:member'][2]['title']);
@@ -122,10 +124,11 @@ public function asAnonymousICanGetABook(): void
122124
ReviewFactory::createOne(['rating' => 4, 'book' => $book]);
123125
ReviewFactory::createOne(['rating' => 5, 'book' => $book]);
124126

125-
$this->client->request('GET', '/books/' . $book->getId());
127+
$response = $this->client->request('GET', '/books/' . $book->getId());
126128

127129
self::assertResponseIsSuccessful();
128130
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
131+
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders(false)['link'][1]);
129132
self::assertJsonContains([
130133
'@id' => '/books/' . $book->getId(),
131134
'book' => $book->book,

api/tests/Api/BookmarkTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public function asAUserICanGetACollectionOfMyBookmarksWithoutFilters(): void
7070

7171
self::assertResponseIsSuccessful();
7272
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
73+
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders(false)['link'][1]);
7374
self::assertJsonContains([
7475
'hydra:totalItems' => 35,
7576
]);
@@ -167,6 +168,7 @@ public function asAUserICanCreateABookmark(): void
167168

168169
self::assertResponseIsSuccessful();
169170
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
171+
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders(false)['link'][1]);
170172
self::assertJsonContains([
171173
'book' => [
172174
'@id' => '/books/' . $book->getId(),

api/tests/Api/ReviewTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function asAnonymousICanGetACollectionOfBookReviewsWithoutFilters(Factory
5353

5454
self::assertResponseIsSuccessful();
5555
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
56+
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders()['link'][1]);
5657
self::assertJsonContains([
5758
'hydra:totalItems' => $hydraTotalItems,
5859
]);
@@ -266,6 +267,7 @@ public function asAUserICanAddAReviewOnABook(): void
266267

267268
self::assertResponseStatusCodeSame(Response::HTTP_CREATED);
268269
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
270+
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders(false)['link'][1]);
269271
self::assertJsonContains([
270272
'book' => '/books/' . $book->getId(),
271273
'user' => [
@@ -451,7 +453,7 @@ public function asAUserICanUpdateMyBookReview(): void
451453
'authorize' => true,
452454
]);
453455

454-
$this->client->request('PATCH', '/books/' . $review->book->getId() . '/reviews/' . $review->getId(), [
456+
$response = $this->client->request('PATCH', '/books/' . $review->book->getId() . '/reviews/' . $review->getId(), [
455457
'auth_bearer' => $token,
456458
'json' => [
457459
'body' => 'Very good book!',
@@ -464,6 +466,7 @@ public function asAUserICanUpdateMyBookReview(): void
464466

465467
self::assertResponseStatusCodeSame(Response::HTTP_OK);
466468
self::assertResponseHeaderSame('content-type', 'application/ld+json; charset=utf-8');
469+
self::assertEquals('<https://localhost/.well-known/mercure>; rel="mercure"', $response->getHeaders(false)['link'][1]);
467470
self::assertJsonContains([
468471
'body' => 'Very good book!',
469472
'rating' => 5,

0 commit comments

Comments
 (0)