Files
portal/app/tests/Unit/Advertising/YandexDirectClientTest.php
T
Дмитрий 27ab44ba37 refactor(реклама показы): удалён мёртвый клик-код клиента Директа и легаси-поля модели
Задача 8c. После перевода запуска на медийную кампанию за показы удалены
неиспользуемые методы клиента YandexDirectClient: addCampaign TextCampaign,
addAdGroup, addAudienceTarget с ContextBid, addTextAd прод-вызовов нет.
Из модели AdCampaign убраны легаси клик-поля weekly_budget_rub и click_bid_rub
из fillable и casts колонки в БД не тронуты.

uploadAdImage и текстовые объявления оставлены живыми они ещё используются.
Тесты клиента и модели обновлены. Реклама-модуль 188/188 зелёный.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-27 08:48:08 +03:00

37 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
use App\Services\Advertising\YandexDirectClient;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
uses(TestCase::class);
it('adds a retargeting list referencing an audience segment', function () {
Http::fake([
'*/json/v5/retargetinglists' => Http::response(['result' => ['AddResults' => [['Id' => 777]]]], 200),
]);
$client = new YandexDirectClient('https://api-sandbox.direct.yandex.com', 'TESTTOKEN');
$id = $client->addRetargetingList('Лидерра кампания #5', 58034825);
expect($id)->toBe(777);
Http::assertSent(function ($req) {
$body = $req->data();
return str_ends_with($req->url(), '/json/v5/retargetinglists')
&& $req->hasHeader('Authorization', 'Bearer TESTTOKEN')
&& $body['method'] === 'add'
&& $body['params']['RetargetingLists'][0]['Type'] === 'AUDIENCE'
&& $body['params']['RetargetingLists'][0]['Rules'][0]['Operator'] === 'ALL'
&& $body['params']['RetargetingLists'][0]['Rules'][0]['Arguments'][0]['ExternalId'] === 58034825;
});
});
it('surfaces an API error as RuntimeException', function () {
Http::fake(['*/json/v5/campaigns' => Http::response(['error' => ['error_string' => 'Нет доступа к API', 'error_code' => 53]], 200)]);
$client = new YandexDirectClient('https://api-sandbox.direct.yandex.com', 'T');
expect(fn () => $client->addCpmBannerCampaign('C', '2026-08-01', '2026-08-14', 72000000, 90000000, 3, 14))->toThrow(RuntimeException::class);
});