2026-07-27 16:15:17 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
use Illuminate\Support\Facades\Schema;
|
|
|
|
|
|
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
|
|
|
|
|
|
it('creates client_tg_campaigns with expected columns', function () {
|
|
|
|
|
expect(Schema::hasTable('client_tg_campaigns'))->toBeTrue();
|
|
|
|
|
expect(Schema::hasColumns('client_tg_campaigns', [
|
|
|
|
|
'tenant_id', 'status', 'ad_text', 'ad_link', 'media_path', 'ord_category',
|
|
|
|
|
'budget_cap_rub', 'audience_kind', 'audience_params', 'matched_count', 'created_by',
|
|
|
|
|
]))->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('creates client_tg_campaign_phones with expected columns', function () {
|
|
|
|
|
expect(Schema::hasTable('client_tg_campaign_phones'))->toBeTrue();
|
|
|
|
|
expect(Schema::hasColumns('client_tg_campaign_phones', [
|
|
|
|
|
'tenant_id', 'campaign_id', 'phone', 'expires_at',
|
|
|
|
|
]))->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('creates client_tg_optouts with expected columns', function () {
|
|
|
|
|
expect(Schema::hasTable('client_tg_optouts'))->toBeTrue();
|
|
|
|
|
expect(Schema::hasColumns('client_tg_optouts', [
|
|
|
|
|
'tenant_id', 'phone',
|
|
|
|
|
]))->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('creates client_tg_contacts with expected columns', function () {
|
|
|
|
|
expect(Schema::hasTable('client_tg_contacts'))->toBeTrue();
|
|
|
|
|
expect(Schema::hasColumns('client_tg_contacts', [
|
|
|
|
|
'tenant_id', 'phone', 'name', 'operator',
|
|
|
|
|
]))->toBeTrue();
|
|
|
|
|
});
|
|
|
|
|
|
2026-08-02 22:15:46 +03:00
|
|
|
it('creates client_tg_tariffs with expected columns and seeds exactly 3 rows', function () {
|
2026-07-27 16:15:17 +03:00
|
|
|
expect(Schema::hasTable('client_tg_tariffs'))->toBeTrue();
|
|
|
|
|
expect(Schema::hasColumns('client_tg_tariffs', [
|
2026-08-02 22:15:46 +03:00
|
|
|
'media_kind', 'price_rub',
|
2026-07-27 16:15:17 +03:00
|
|
|
]))->toBeTrue();
|
|
|
|
|
|
2026-08-02 22:15:46 +03:00
|
|
|
// Ступеней по объёму больше нет — у МТС цена плоская (миграция client_tg_cena_po_media).
|
|
|
|
|
expect(Schema::hasColumn('client_tg_tariffs', 'min_qty'))->toBeFalse();
|
|
|
|
|
|
|
|
|
|
expect(DB::table('client_tg_tariffs')->count())->toBe(3);
|
2026-07-27 16:15:17 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('enables row level security on client_tg_campaigns with a tenant_isolation policy', function () {
|
|
|
|
|
$rls = DB::selectOne("SELECT relrowsecurity FROM pg_class WHERE relname = 'client_tg_campaigns'");
|
|
|
|
|
expect((bool) $rls->relrowsecurity)->toBeTrue();
|
|
|
|
|
|
|
|
|
|
$policyExists = DB::table('pg_policies')
|
|
|
|
|
->where('tablename', 'client_tg_campaigns')
|
|
|
|
|
->where('policyname', 'tenant_isolation')
|
|
|
|
|
->exists();
|
|
|
|
|
expect($policyExists)->toBeTrue();
|
|
|
|
|
});
|