Files
portal/app/tests/Feature/Advertising/CampaignEstimateEndpointTest.php
T

40 lines
1.6 KiB
PHP
Raw Normal View History

<?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');
});