Files
portal/app/tests/Feature/ClientTg/SchemaTest.php
T

62 lines
2.3 KiB
PHP
Raw Normal View History

<?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();
});
it('creates client_tg_tariffs with expected columns and seeds exactly 3 rows', function () {
expect(Schema::hasTable('client_tg_tariffs'))->toBeTrue();
expect(Schema::hasColumns('client_tg_tariffs', [
'media_kind', 'price_rub',
]))->toBeTrue();
// Ступеней по объёму больше нет — у МТС цена плоская (миграция client_tg_cena_po_media).
expect(Schema::hasColumn('client_tg_tariffs', 'min_qty'))->toBeFalse();
expect(DB::table('client_tg_tariffs')->count())->toBe(3);
});
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();
});