5a4c0e0235
Часть 5c — баннеры: клиент грузит свой готовый файл на каждый из 15 размеров вместо автогенерации из одной картинки. Частичное утверждение флагом included, замена и удаление отдельного баннера, валидация точного размера и веса. Админ-поле цены за 1000 показов. Пример CSV для скачивания и подъём лимита загрузки. Часть 5d — два режима сбора аудитории. Авто: скользящее окно, обновляется ежедневно, только контакты системы. Ручной: снимок сделок за период плюс свой список номеров и срок показа. Клиент сам задаёт цену за 1000 показов с дефолтом из админки. Наценка настраивается в админке, по умолчанию 40 процентов, в Директ уходит меньше, клиенту не видна нигде. Миграции: ad_campaign_banners += included; ad_campaigns += mode/snapshot_from/snapshot_to/run_days/client_cpm_rub; ad_settings += ad_margin_percent. RLS-ревью PASS на всех миграциях. Backend 166 тестов, фронт 123 теста, сборка чистая. Маржа и yandex_cost_rub клиенту не сериализуются. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
79 lines
3.4 KiB
PHP
79 lines
3.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\AdCampaign;
|
|
use App\Models\Deal;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
|
|
it('endpoint возвращает смету, когда передана частота', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$campaign = AdCampaign::create([
|
|
'tenant_id' => $tenant->id, 'name' => 'C', 'audience_days' => 10, 'use_uploaded_list' => false,
|
|
]);
|
|
Deal::factory()->create(['tenant_id' => $tenant->id, 'phone' => '79990000001', 'received_at' => now()->subDays(2)]);
|
|
Deal::factory()->create(['tenant_id' => $tenant->id, 'phone' => '79990000002', 'received_at' => now()->subDays(3)]);
|
|
|
|
$res = $this->actingAs($user)->getJson("/api/advertising/campaigns/{$campaign->id}/audience-size?days=10&frequency=10");
|
|
|
|
$res->assertOk()
|
|
->assertJsonPath('size', 2)
|
|
->assertJsonPath('impressions', 20)
|
|
->assertJsonPath('cpm_rub', '120.00')
|
|
->assertJsonPath('cost_rub', '2.40')
|
|
->assertJsonPath('enough', false);
|
|
});
|
|
|
|
it('без частоты endpoint отдаёт прежний ответ без сметы', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$campaign = AdCampaign::create([
|
|
'tenant_id' => $tenant->id, 'name' => 'C', 'audience_days' => 10, 'use_uploaded_list' => false,
|
|
]);
|
|
|
|
$res = $this->actingAs($user)->getJson("/api/advertising/campaigns/{$campaign->id}/audience-size?days=10");
|
|
|
|
$res->assertOk()->assertJsonPath('size', 0)->assertJsonMissingPath('cost_rub');
|
|
});
|
|
|
|
it('T4b: manual+from/to возвращает размер по диапазону снимка', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$campaign = AdCampaign::create([
|
|
'tenant_id' => $tenant->id, 'name' => 'C', 'mode' => AdCampaign::MODE_AUTO,
|
|
'audience_days' => 10, 'use_uploaded_list' => false,
|
|
]);
|
|
Deal::factory()->create(['tenant_id' => $tenant->id, 'phone' => '79990010001', 'received_at' => now()->subDays(3)]);
|
|
Deal::factory()->create(['tenant_id' => $tenant->id, 'phone' => '79990010002', 'received_at' => now()->subDays(20)]);
|
|
|
|
$from = now()->subDays(5)->format('Y-m-d');
|
|
$to = now()->subDays(1)->format('Y-m-d');
|
|
|
|
$res = $this->actingAs($user)->getJson(
|
|
"/api/advertising/campaigns/{$campaign->id}/audience-size?mode=manual&from={$from}&to={$to}"
|
|
);
|
|
|
|
$res->assertOk()->assertJsonPath('size', 1);
|
|
});
|
|
|
|
it('T4b: передача cpm=90 в смету считает стоимость по 90, не по дефолту ad_settings', function () {
|
|
$tenant = Tenant::factory()->create();
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
|
$campaign = AdCampaign::create([
|
|
'tenant_id' => $tenant->id, 'name' => 'C', 'audience_days' => 10, 'use_uploaded_list' => false,
|
|
]);
|
|
Deal::factory()->create(['tenant_id' => $tenant->id, 'phone' => '79990011001', 'received_at' => now()->subDays(2)]);
|
|
|
|
$res = $this->actingAs($user)->getJson(
|
|
"/api/advertising/campaigns/{$campaign->id}/audience-size?days=10&frequency=10&cpm=90"
|
|
);
|
|
|
|
$res->assertOk()
|
|
->assertJsonPath('size', 1)
|
|
->assertJsonPath('impressions', 10)
|
|
->assertJsonPath('cpm_rub', '90.00')
|
|
->assertJsonPath('cost_rub', '0.90');
|
|
});
|