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