From e61492f864a69fe94f4d5dd7a446d1bb5724159d Mon Sep 17 00:00:00 2001 From: Yisroel Baum Date: Wed, 6 May 2026 22:30:32 +0300 Subject: [PATCH] test ListFeaturedPosts use case --- .../Post/UseCases/ListFeaturedPostsTest.php | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 backend/tests/Unit/Post/UseCases/ListFeaturedPostsTest.php diff --git a/backend/tests/Unit/Post/UseCases/ListFeaturedPostsTest.php b/backend/tests/Unit/Post/UseCases/ListFeaturedPostsTest.php new file mode 100644 index 0000000..b01c4a7 --- /dev/null +++ b/backend/tests/Unit/Post/UseCases/ListFeaturedPostsTest.php @@ -0,0 +1,71 @@ +now = new DateTimeImmutable( + '2026-05-06T12:00:00', + new DateTimeZone('UTC'), + ); + $this->postRepo = new FakePostRepository; + $this->useCase = new ListFeaturedPosts($this->postRepo); + } + + private function seedFeaturedPost(string $title, ?int $slot): Post + { + $post = $this->postRepo->create(new CreatePostDto( + userId: 1, + title: $title, + body: 'B', + createdAt: $this->now, + )); + if ($slot === null) { + return $post; + } + + return $this->postRepo->update(new Post( + id: $post->getId(), + userId: $post->getUserId(), + title: $post->getTitle(), + body: $post->getBody(), + createdAt: $post->getCreatedAt(), + featureSlot: $slot, + )); + } + + public function test_returns_empty_when_none_featured(): void + { + $this->seedFeaturedPost('not featured', null); + $this->assertSame([], $this->useCase->execute()); + } + + public function test_returns_featured_posts_in_slot_order(): void + { + $this->seedFeaturedPost('slot-2', 2); + $this->seedFeaturedPost('slot-1', 1); + $this->seedFeaturedPost('not-featured', null); + + $featured = $this->useCase->execute(); + + $this->assertCount(2, $featured); + $this->assertSame('slot-1', $featured[0]->getTitle()); + $this->assertSame('slot-2', $featured[1]->getTitle()); + } +}