create([ 'tenant_id' => $tenantId, 'status' => Campaign::STATUS_MODERATING, 'ad_text' => 'Приходите к нам за услугой', 'ad_link' => 'https://example.test/promo', 'ord_category' => 'Размещение рекламы', 'budget_cap_rub' => '500.00', 'audience_kind' => Campaign::AUDIENCE_LIST, 'planned_count' => 2, 'estimated_cost_rub' => '315.00', 'mts_campaign_id' => '777', 'created_by' => 1, ]); } beforeEach(function () { config()->set('client_tg.sandbox', true); $this->tenant = Tenant::factory()->create(['balance_rub' => '1000.00']); DB::statement('SET LOCAL app.current_tenant_id = '.$this->tenant->id); $this->campaign = verdictCampaign($this->tenant->id); }); it('одобрение переводит кампанию в показы', function () { app(TelegramModerationVerdictApplier::class)->apply( $this->tenant->id, $this->campaign->id, RobotResult::fromRobotJson(['ok' => true, 'moderationStatus' => 'approved']), true, ); expect(Campaign::find($this->campaign->id)->status)->toBe(Campaign::STATUS_LAUNCHED); }); it('отказ переводит кампанию в отклонённые и пишет причину', function () { app(TelegramModerationVerdictApplier::class)->apply( $this->tenant->id, $this->campaign->id, RobotResult::fromRobotJson(['ok' => true, 'moderationStatus' => 'rejected', 'reason' => 'нет лицензии']), true, ); $fresh = Campaign::find($this->campaign->id); expect($fresh->status)->toBe(Campaign::STATUS_REJECTED); expect($fresh->status_reason)->toBe('нет лицензии'); }); it('вердикт «ещё на модерации» кампанию не трогает', function () { app(TelegramModerationVerdictApplier::class)->apply( $this->tenant->id, $this->campaign->id, RobotResult::fromRobotJson(['ok' => true, 'moderationStatus' => 'moderating']), true, ); expect(Campaign::find($this->campaign->id)->status)->toBe(Campaign::STATUS_MODERATING); }); it('не трогает кампанию, которая уже ушла с модерации', function () { Campaign::where('id', $this->campaign->id)->update(['status' => Campaign::STATUS_LAUNCHED]); app(TelegramModerationVerdictApplier::class)->apply( $this->tenant->id, $this->campaign->id, RobotResult::fromRobotJson(['ok' => true, 'moderationStatus' => 'rejected']), true, ); expect(Campaign::find($this->campaign->id)->status)->toBe(Campaign::STATUS_LAUNCHED); });