feat(blog): add admin endpoint to list all blog posts with status filtering
This commit is contained in:
@@ -58,6 +58,46 @@ class BlogV2FieldsTest extends ApiTestCase
|
||||
$this->assertSame(6, $b['reading_time']);
|
||||
}
|
||||
|
||||
// ── Admin list shows drafts (public list does not) ────────────────────────
|
||||
|
||||
public function testAdminListReturnsDraftsThatPublicListHides(): void
|
||||
{
|
||||
$admin = $this->createUser(['ROLE_ADMIN']);
|
||||
$tag = bin2hex(random_bytes(4));
|
||||
|
||||
$draft = new Blog($admin, "پیشنویس-$tag", 'متن آزمایشی مقاله برای تست');
|
||||
$draft->setStatus(Blog::STATUS_DRAFT);
|
||||
$pub = new Blog($admin, "منتشر-$tag", 'متن آزمایشی مقاله برای تست');
|
||||
$pub->setStatus(Blog::STATUS_PUBLISHED);
|
||||
$this->em->persist($draft);
|
||||
$this->em->persist($pub);
|
||||
$this->em->flush();
|
||||
|
||||
// admin list — sees both
|
||||
$adminList = $this->authJson('GET', '/api/v1/admin/blogs?limit=50', $admin);
|
||||
$titles = array_column($adminList['data'], 'title');
|
||||
$this->assertContains("پیشنویس-$tag", $titles, 'admin list must show drafts');
|
||||
$this->assertContains("منتشر-$tag", $titles);
|
||||
|
||||
// status filter
|
||||
$draftsOnly = $this->authJson('GET', '/api/v1/admin/blogs?limit=50&status=draft', $admin);
|
||||
$dTitles = array_column($draftsOnly['data'], 'title');
|
||||
$this->assertContains("پیشنویس-$tag", $dTitles);
|
||||
$this->assertNotContains("منتشر-$tag", $dTitles);
|
||||
|
||||
// public list — drafts hidden
|
||||
$this->client->request('GET', '/api/v1/blogs?limit=50');
|
||||
$publicTitles = array_column(json_decode($this->client->getResponse()->getContent(), true)['data'], 'title');
|
||||
$this->assertNotContains("پیشنویس-$tag", $publicTitles, 'public list must never expose drafts');
|
||||
}
|
||||
|
||||
public function testAdminListRequiresAdmin(): void
|
||||
{
|
||||
$user = $this->createUser(['ROLE_USER']);
|
||||
$this->authJson('GET', '/api/v1/admin/blogs', $user);
|
||||
$this->assertSame(403, $this->responseCode());
|
||||
}
|
||||
|
||||
// ── Representative scope ──────────────────────────────────────────────────
|
||||
|
||||
public function testRepresentativeCreatesPostInOwnCity(): void
|
||||
|
||||
Reference in New Issue
Block a user