feat(смс-клиент): таблицы имени/авто-правила + модели + грант админ-кошелька
client_sms_senders (жизненный цикл имени) и client_sms_auto_rule (авто-рассылка) — RLS tenant-таблицы; гварды грантов для crm_supplier_worker/crm_admin_user (cross-tenant джоб и админ-подтверждение). Грант записи в ad_wallets для crm_admin_user (approve списывает/снимает заморозку). CHANGELOG v8.97/v8.98 с deploy-note про ре-ран srv_bypass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use App\Models\ClientSmsAutoRule;
|
||||
use App\Models\ClientSmsSender;
|
||||
use App\Models\Tenant;
|
||||
use Illuminate\Database\QueryException;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
uses(RefreshDatabase::class);
|
||||
|
||||
it('creates a client sms sender and reads back casts correctly', function () {
|
||||
$tenant = Tenant::factory()->create();
|
||||
|
||||
$sender = ClientSmsSender::create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'name' => 'LIDERRA',
|
||||
'name_type' => ClientSmsSender::TYPE_COMPANY,
|
||||
'status' => ClientSmsSender::STATUS_PENDING,
|
||||
'operators' => ['mts'],
|
||||
'monthly_fee_rub' => '2500.00',
|
||||
'consent_at' => now(),
|
||||
'note' => null,
|
||||
'requested_by' => null,
|
||||
'approved_at' => null,
|
||||
'paid_until' => now()->toDateString(),
|
||||
'debt_since' => null,
|
||||
]);
|
||||
|
||||
$sender->refresh();
|
||||
|
||||
expect($sender->operators)->toBeArray()
|
||||
->and($sender->operators)->toBe(['mts'])
|
||||
->and((string) $sender->monthly_fee_rub)->toBe('2500.00')
|
||||
->and($sender->paid_until)->toBeInstanceOf(Carbon\Carbon::class)
|
||||
->and($sender->status)->toBe(ClientSmsSender::STATUS_PENDING);
|
||||
});
|
||||
|
||||
it('creates a client sms auto rule and reads back the boolean cast', function () {
|
||||
$tenant = Tenant::factory()->create();
|
||||
|
||||
$rule = ClientSmsAutoRule::create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'enabled' => true,
|
||||
'body' => 'текст',
|
||||
'sender_name' => 'LIDERRA',
|
||||
'updated_by' => null,
|
||||
]);
|
||||
|
||||
$rule->refresh();
|
||||
|
||||
expect($rule->enabled)->toBeTrue()
|
||||
->and($rule->enabled)->toBeBool();
|
||||
});
|
||||
|
||||
it('enforces a unique sender per tenant', function () {
|
||||
$tenant = Tenant::factory()->create();
|
||||
|
||||
ClientSmsSender::create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'name' => 'LIDERRA',
|
||||
'name_type' => ClientSmsSender::TYPE_COMPANY,
|
||||
'status' => ClientSmsSender::STATUS_PENDING,
|
||||
'operators' => ['mts'],
|
||||
'monthly_fee_rub' => '0.00',
|
||||
'consent_at' => null,
|
||||
'note' => null,
|
||||
'requested_by' => null,
|
||||
'approved_at' => null,
|
||||
'paid_until' => null,
|
||||
'debt_since' => null,
|
||||
]);
|
||||
|
||||
// Nested transaction (Postgres savepoint) so the aborted INSERT doesn't
|
||||
// poison the outer RefreshDatabase transaction for the rest of the test.
|
||||
expect(fn () => DB::transaction(fn () => ClientSmsSender::create([
|
||||
'tenant_id' => $tenant->id,
|
||||
'name' => 'OTHER',
|
||||
'name_type' => ClientSmsSender::TYPE_WEBSITE,
|
||||
'status' => ClientSmsSender::STATUS_PENDING,
|
||||
'operators' => ['beeline'],
|
||||
'monthly_fee_rub' => '0.00',
|
||||
'consent_at' => null,
|
||||
'note' => null,
|
||||
'requested_by' => null,
|
||||
'approved_at' => null,
|
||||
'paid_until' => null,
|
||||
'debt_since' => null,
|
||||
])))->toThrow(QueryException::class);
|
||||
|
||||
expect(ClientSmsSender::where('tenant_id', $tenant->id)->count())->toBe(1);
|
||||
});
|
||||
Reference in New Issue
Block a user