createUser(['ROLE_USER', 'ROLE_ADMIN']); $body = $this->authJson('POST', '/api/v1/admin/subscription/plan', $admin, [ 'name' => $this->planName(), 'level' => 7, 'max_secretaries' => 2, 'max_resources' => 5, 'features' => ['services' => true], ]); self::assertSame(201, $this->responseCode(), json_encode($body, JSON_UNESCAPED_UNICODE)); self::assertSame(5, $body['data']['max_resources']); } /** نیامدنِ فیلد یعنی محافظه‌کارانه‌ترین سقف، نه نامحدود. */ public function testOmittedQuotaDefaultsToOne(): void { $admin = $this->createUser(['ROLE_USER', 'ROLE_ADMIN']); $body = $this->authJson('POST', '/api/v1/admin/subscription/plan', $admin, [ 'name' => $this->planName(), 'level' => 7, ]); self::assertSame(201, $this->responseCode()); self::assertSame(1, $body['data']['max_resources']); } public function testQuotaIsUpdatedAndUnlimitedIsAccepted(): void { $admin = $this->createUser(['ROLE_USER', 'ROLE_ADMIN']); $created = $this->authJson('POST', '/api/v1/admin/subscription/plan', $admin, [ 'name' => $this->planName(), 'level' => 7, 'max_resources' => 3, ]); $body = $this->authJson('PATCH', '/api/v1/admin/subscription/plan/' . $created['data']['uuid'], $admin, [ 'max_resources' => SubscriptionPlan::UNLIMITED, ]); self::assertSame(200, $this->responseCode()); self::assertSame(SubscriptionPlan::UNLIMITED, $body['data']['max_resources']); } #[\PHPUnit\Framework\Attributes\DataProvider('invalidQuotas')] public function testInvalidQuotaIsRejected(int $quota): void { $admin = $this->createUser(['ROLE_USER', 'ROLE_ADMIN']); $this->authJson('POST', '/api/v1/admin/subscription/plan', $admin, [ 'name' => $this->planName(), 'level' => 7, 'max_resources' => $quota, ]); self::assertSame(422, $this->responseCode()); } /** @return array */ public static function invalidQuotas(): array { return [ 'zero' => [0], 'below unlimited' => [-2], ]; } /** فهرست پلن‌ها سقف را می‌دهد؛ وگرنه کارت‌های صفحهٔ اشتراک چیزی برای نشان‌دادن ندارند. */ public function testPlanListExposesTheQuota(): void { $user = $this->createUser(['ROLE_USER']); $body = $this->authJson('GET', '/api/v1/subscription/plans', $user); self::assertSame(200, $this->responseCode()); self::assertArrayHasKey('max_resources', $body['data'][0]); } }