53 lines
2.0 KiB
PHP
53 lines
2.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
declare(strict_types=1);
|
||
|
|
|
||
|
|
use App\Models\AdCampaign;
|
||
|
|
use App\Models\AdCampaignBanner;
|
||
|
|
use App\Models\Tenant;
|
||
|
|
use App\Models\User;
|
||
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||
|
|
|
||
|
|
use function Pest\Laravel\actingAs;
|
||
|
|
|
||
|
|
uses(DatabaseTransactions::class);
|
||
|
|
|
||
|
|
function makeReadyCampaign(int $tenantId): AdCampaign
|
||
|
|
{
|
||
|
|
$c = AdCampaign::create([
|
||
|
|
'tenant_id' => $tenantId, 'name' => 'Готовая', 'audience_days' => 10,
|
||
|
|
'frequency' => 5, 'estimated_impressions' => 2500, 'budget_rub' => '300.00',
|
||
|
|
'banners_approved_at' => now(),
|
||
|
|
]);
|
||
|
|
AdCampaignBanner::create(['tenant_id' => $tenantId, 'campaign_id' => $c->id,
|
||
|
|
'width' => 300, 'height' => 250, 'path' => 'x', 'bytes' => 1]);
|
||
|
|
|
||
|
|
return $c;
|
||
|
|
}
|
||
|
|
|
||
|
|
it('переводит готовую кампанию в статус queued', function () {
|
||
|
|
$tenant = Tenant::factory()->create();
|
||
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
||
|
|
$c = makeReadyCampaign($tenant->id);
|
||
|
|
$res = actingAs($user)->postJson("/api/advertising/campaigns/{$c->id}/submit");
|
||
|
|
$res->assertOk()->assertJson(['status' => 'queued']);
|
||
|
|
expect($c->fresh()->status)->toBe('queued');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('не отправляет без утверждённых баннеров', function () {
|
||
|
|
$tenant = Tenant::factory()->create();
|
||
|
|
$user = User::factory()->create(['tenant_id' => $tenant->id]);
|
||
|
|
$c = AdCampaign::create(['tenant_id' => $tenant->id, 'name' => 'Пустая',
|
||
|
|
'audience_days' => 10, 'frequency' => 5, 'estimated_impressions' => 2500, 'budget_rub' => '300.00']);
|
||
|
|
actingAs($user)->postJson("/api/advertising/campaigns/{$c->id}/submit")->assertStatus(422);
|
||
|
|
expect($c->fresh()->status)->toBe('draft');
|
||
|
|
});
|
||
|
|
|
||
|
|
it('чужую кампанию не отправляет (404)', function () {
|
||
|
|
$t1 = Tenant::factory()->create();
|
||
|
|
$t2 = Tenant::factory()->create();
|
||
|
|
$user = User::factory()->create(['tenant_id' => $t1->id]);
|
||
|
|
$c = makeReadyCampaign($t2->id);
|
||
|
|
actingAs($user)->postJson("/api/advertising/campaigns/{$c->id}/submit")->assertNotFound();
|
||
|
|
});
|