298afb835a
Сессия 1 плана docs/superpowers/plans/2026-07-27-client-telegram-ads-module.md. Бэкенд-ядро — зеркало готового СМС-модуля. Робота ещё нет — он в Сессии 2. - 8 таблиц client_tg_* с RLS tenant_isolation и GRANT crm_app_user; справочные tariffs/settings без RLS с guarded-GRANT. rls-reviewer PASS 8 из 8. - 7 моделей ClientTg + связи campaign->phones. - Ступенчатая цена TelegramTariffService — ₽ за показ по объёму; тариф = потолок, точную стоимость считает МТС. - Сборка аудитории TelegramAudienceService — сделки за период / своя база / свой список, нормализация телефона, стоп-лист и дедуп; отдаёт кандидатов, реальный охват узнаёт робот после загрузки в МТС. - Канал кошелька telegram: перенесён общий AdWallet со свежей версии портала — модели, сервис, миграции; списание и заморозка по каналу telegram под тестами, charge не бросает и не уходит в минус, нехватка средств ловится freeze до списания. Проверки: 26 из 26 Pest зелёные, larastan 0, gitleaks чисто. db/CHANGELOG_schema.md v8.86 — номер предварительный, ветка отстаёт от main. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
82 lines
3.0 KiB
PHP
82 lines
3.0 KiB
PHP
<?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();
|
|
});
|