| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- <?php
- declare(strict_types=1);
- namespace App\Tests\Integration\Admin;
- use App\Domain\Auth\Role;
- use App\Domain\Auth\TokenKind;
- use App\Tests\Integration\Support\AppTestCase;
- final class ConsumersControllerTest extends AppTestCase
- {
- public function testCreateAndListConsumer(): void
- {
- $token = $this->createToken(TokenKind::Admin, role: Role::Admin);
- $policyId = (int) $this->db->fetchOne('SELECT id FROM policies WHERE name = :name', ['name' => 'moderate']);
- $created = $this->request(
- 'POST',
- '/api/v1/admin/consumers',
- ['Authorization' => 'Bearer ' . $token, 'Content-Type' => 'application/json'],
- json_encode(['name' => 'fw-edge-01', 'policy_id' => $policyId]) ?: null,
- );
- self::assertSame(201, $created->getStatusCode());
- $body = $this->decode($created);
- self::assertSame('fw-edge-01', $body['name']);
- self::assertSame($policyId, $body['policy_id']);
- $list = $this->request('GET', '/api/v1/admin/consumers', [
- 'Authorization' => 'Bearer ' . $token,
- ]);
- self::assertSame(200, $list->getStatusCode());
- $listBody = $this->decode($list);
- self::assertGreaterThan(0, $listBody['total']);
- }
- public function testCreateRejectsUnknownPolicy(): void
- {
- $token = $this->createToken(TokenKind::Admin, role: Role::Admin);
- $resp = $this->request(
- 'POST',
- '/api/v1/admin/consumers',
- ['Authorization' => 'Bearer ' . $token, 'Content-Type' => 'application/json'],
- json_encode(['name' => 'bogus', 'policy_id' => 99999]) ?: null,
- );
- self::assertSame(400, $resp->getStatusCode());
- self::assertArrayHasKey('policy_id', $this->decode($resp)['details']);
- }
- }
|