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

82 lines
3.0 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_messages with expected columns', function () {
expect(Schema::hasTable('client_tg_messages'))->toBeTrue();
expect(Schema::hasColumns('client_tg_messages', [
'tenant_id', 'campaign_id', 'deal_id', 'phone', 'status', 'cost_rub', 'error',
]))->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_templates with expected columns', function () {
expect(Schema::hasTable('client_tg_templates'))->toBeTrue();
expect(Schema::hasColumns('client_tg_templates', [
'tenant_id', 'title', 'body',
]))->toBeTrue();
});
it('creates client_tg_tariffs with expected columns and seeds exactly 5 rows', function () {
expect(Schema::hasTable('client_tg_tariffs'))->toBeTrue();
expect(Schema::hasColumns('client_tg_tariffs', [
'min_qty', 'price_rub',
]))->toBeTrue();
expect(DB::table('client_tg_tariffs')->count())->toBe(5);
});
it('creates client_tg_settings with expected columns and seeds exactly 1 row', function () {
expect(Schema::hasTable('client_tg_settings'))->toBeTrue();
expect(Schema::hasColumns('client_tg_settings', [
'name_fee_rub_per_month', 'name_debt_grace_days',
]))->toBeTrue();
expect(DB::table('client_tg_settings')->count())->toBe(1);
});
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();
});