seed(RolesAndPermissionsSeeder::class); }); test('remaining quota reflects the used counter', function () { $user = User::factory()->create([ 'press_release_quota' => 3, 'press_release_quota_used_this_month' => 1, ]); expect($user->pressReleaseQuotaRemaining())->toBe(2); }); test('submitting a press release for review increments the monthly quota usage', function () { $user = User::factory()->create([ 'press_release_quota' => 3, 'press_release_quota_used_this_month' => 0, ]); $user->assignRole('customer'); $company = Company::factory()->presseecho()->create(); $user->companies()->attach($company->id, ['role' => 'owner']); $pr = PressRelease::factory()->create([ 'user_id' => $user->id, 'company_id' => $company->id, 'category_id' => Category::factory()->create()->id, 'portal' => $company->portal->value, 'status' => 'draft', ]); app(PressReleaseService::class)->submitForReview($pr); expect($user->fresh()->press_release_quota_used_this_month)->toBe(1); }); test('monthly reset command zeroes the used counter', function () { User::factory()->count(2)->create(['press_release_quota_used_this_month' => 2]); $untouched = User::factory()->create(['press_release_quota_used_this_month' => 0]); $this->artisan(ResetMonthlyPressReleaseQuota::class)->assertSuccessful(); expect(User::where('press_release_quota_used_this_month', '>', 0)->count())->toBe(0); expect($untouched->fresh()->press_release_quota_used_this_month)->toBe(0); });