Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
19 / 19 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| CreateTestUserAction | |
100.00% |
19 / 19 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __invoke | |
100.00% |
18 / 18 |
|
100.00% |
1 / 1 |
4 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Action\SuperAdmin; |
| 6 | |
| 7 | use App\Domain\Auth\Data\UserAuthData; |
| 8 | use App\Domain\Exception\ForbiddenException; |
| 9 | use App\Domain\SuperAdmin\Service\SuperAdminService; |
| 10 | use App\Renderer\JsonRenderer; |
| 11 | use Psr\Http\Message\ResponseInterface; |
| 12 | use Psr\Http\Message\ServerRequestInterface; |
| 13 | |
| 14 | /** |
| 15 | * Create a single test user with investor profile and optional account. |
| 16 | */ |
| 17 | final readonly class CreateTestUserAction |
| 18 | { |
| 19 | public function __construct( |
| 20 | private JsonRenderer $renderer, |
| 21 | private SuperAdminService $service, |
| 22 | ) {} |
| 23 | |
| 24 | public function __invoke(ServerRequestInterface $request, ResponseInterface $response): ResponseInterface |
| 25 | { |
| 26 | // Verify super_admin role |
| 27 | $user = $request->getAttribute('user'); |
| 28 | if (!$user instanceof UserAuthData || $user->role !== 'super_admin') { |
| 29 | throw new ForbiddenException('Super admin access required'); |
| 30 | } |
| 31 | |
| 32 | $data = (array)$request->getParsedBody(); |
| 33 | |
| 34 | $result = $this->service->createTestUser( |
| 35 | firstName: $data['firstName'] ?? '', |
| 36 | lastName: $data['lastName'] ?? '', |
| 37 | email: $data['email'] ?? null, |
| 38 | password: $data['password'] ?? null, |
| 39 | kycStatus: $data['kycStatus'] ?? 'verified', |
| 40 | createAccount: (bool)($data['createAccount'] ?? true), |
| 41 | initialDeposit: isset($data['initialDeposit']) ? (float)$data['initialDeposit'] : null, |
| 42 | ); |
| 43 | |
| 44 | return $this->renderer->json($response, [ |
| 45 | 'success' => true, |
| 46 | 'message' => 'Test user created successfully', |
| 47 | 'data' => $result, |
| 48 | ])->withStatus(201); |
| 49 | } |
| 50 | } |