40 lines
1.4 KiB
PHP
40 lines
1.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Models\AdCampaign;
|
||
|
|
use App\Models\Tenant;
|
||
|
|
use App\Models\User;
|
||
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||
|
|
|
||
|
|
use function Pest\Laravel\actingAs;
|
||
|
|
|
||
|
|
uses(DatabaseTransactions::class);
|
||
|
|
|
||
|
|
it('создаёт черновик кампании показов без клик-полей', function () {
|
||
|
|
$tenant = Tenant::factory()->create();
|
||
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
||
|
|
$res = actingAs($user)->postJson('/api/advertising/campaigns', [
|
||
|
|
'name' => 'Показы 1', 'audience_days' => 14,
|
||
|
|
]);
|
||
|
|
$res->assertCreated();
|
||
|
|
$c = AdCampaign::firstWhere('name', 'Показы 1');
|
||
|
|
expect($c)->not->toBeNull();
|
||
|
|
expect($c->status)->toBe('draft');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('патчит частоту, показы и бюджет показов', function () {
|
||
|
|
$tenant = Tenant::factory()->create();
|
||
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
||
|
|
$c = AdCampaign::create(['tenant_id' => $tenant->id, 'name' => 'X', 'audience_days' => 10]);
|
||
|
|
$res = actingAs($user)->patchJson("/api/advertising/campaigns/{$c->id}", [
|
||
|
|
'frequency' => 5, 'frequency_period_days' => 30,
|
||
|
|
'estimated_impressions' => 2500, 'budget_rub' => '300.00',
|
||
|
|
]);
|
||
|
|
$res->assertOk();
|
||
|
|
$c->refresh();
|
||
|
|
expect($c->frequency)->toBe(5);
|
||
|
|
expect($c->estimated_impressions)->toBe(2500);
|
||
|
|
expect((string) $c->budget_rub)->toBe('300.00');
|
||
|
|
});
|