feat(subscription): implement resource quota management based on subscription plans

This commit is contained in:
hamed
2026-08-04 19:38:49 +03:30
parent 0dca245246
commit 3e7028d77a
16 changed files with 408 additions and 18 deletions
+30 -8
View File
@@ -63,21 +63,43 @@ abstract class ApiTestCase extends WebTestCase
* and the patient / service / insurance endpoints answer 403 instead of doing
* their job. db_test is never reset, so the insert is idempotent.
*
* Mirrors the row shipped in the dev database.
* Mirrors the row shipped in the dev database, except for max_resources: the
* fixture grants an unlimited resource quota so that the dozens of suites which
* merely need a room or a device are not rewritten into subscription tests. The
* real per-plan quota is exercised explicitly by ResourceQuotaTest, which lowers
* it with setPlanResourceQuota().
*/
private function ensureFreePlan(): void
{
$repo = $this->em->getRepository(SubscriptionPlan::class);
if ($repo->findOneBy(['name' => 'free']) !== null) {
$plan = $repo->findOneBy(['name' => 'free']);
if ($plan === null) {
$this->em->persist(new SubscriptionPlan('free', 0, 1, [
'patient_records' => true,
'services' => true,
'sms_panel' => true,
'insurance' => true,
], SubscriptionPlan::UNLIMITED));
$this->em->flush();
return;
}
$this->em->persist(new SubscriptionPlan('free', 0, 1, [
'patient_records' => true,
'services' => true,
'sms_panel' => true,
'insurance' => true,
]));
// db_test is never reset, so a quota lowered by a previous case must be undone.
if ($plan->getMaxResources() !== SubscriptionPlan::UNLIMITED) {
$plan->setMaxResources(SubscriptionPlan::UNLIMITED);
$this->em->flush();
}
}
/** سقف منابعِ پلن مؤثرِ تست‌ها؛ `SubscriptionPlan::UNLIMITED` یعنی بی‌نهایت. */
protected function setPlanResourceQuota(int $max, string $plan = 'free'): void
{
$entity = $this->em->getRepository(SubscriptionPlan::class)->findOneBy(['name' => $plan]);
self::assertNotNull($entity, sprintf('Plan "%s" is missing from the test database.', $plan));
$entity->setMaxResources($max);
$this->em->flush();
}