2026-05-18 17:36:27 +03:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
|
|
use App\Services\Supplier\SupplierPortalClient;
|
2026-05-19 07:42:12 +03:00
|
|
|
|
use Illuminate\Http\Client\Request;
|
2026-05-18 17:36:27 +03:00
|
|
|
|
use Illuminate\Support\Carbon;
|
|
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
|
use Illuminate\Support\Facades\Http;
|
|
|
|
|
|
|
|
|
|
|
|
beforeEach(function (): void {
|
|
|
|
|
|
config(['services.supplier.portal_url' => 'https://crm.bp-gr.ru']);
|
|
|
|
|
|
Cache::store('redis')->put('supplier:session', ['phpsessid' => 'test', 'csrf' => 'test'], now()->addHour());
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-05-19 07:42:12 +03:00
|
|
|
|
// Реальные endpoint'ы verified discovery T3 2026-05-19 через Playwright MCP:
|
|
|
|
|
|
// POST /admin/report/save-report (JSON body, response "OK" — text, не JSON)
|
|
|
|
|
|
// GET /admin/report/load-reports (array — каждая запись {id,title,status:"0"|"1",...})
|
|
|
|
|
|
// GET /admin/report/getfile?id=N (raw CSV body)
|
|
|
|
|
|
|
|
|
|
|
|
it('requestNumbersReport posts save-report and resolves id via load-reports by title match', function (): void {
|
2026-05-18 17:36:27 +03:00
|
|
|
|
Http::fake([
|
2026-05-19 07:42:12 +03:00
|
|
|
|
'crm.bp-gr.ru/admin/report/save-report' => Http::response('OK', 200),
|
|
|
|
|
|
'crm.bp-gr.ru/admin/report/load-reports' => Http::response([
|
|
|
|
|
|
['id' => '509196', 'title' => 'Запрос номеров с 2026-05-17 по 2026-05-18', 'status' => '0'],
|
|
|
|
|
|
['id' => '508346', 'title' => 'Запрос номеров с 2026-04-01 по 2026-04-30', 'status' => '1'],
|
|
|
|
|
|
], 200),
|
2026-05-18 17:36:27 +03:00
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$client = app(SupplierPortalClient::class);
|
|
|
|
|
|
$id = $client->requestNumbersReport(Carbon::parse('2026-05-17'), Carbon::parse('2026-05-18'));
|
|
|
|
|
|
|
2026-05-19 07:42:12 +03:00
|
|
|
|
expect($id)->toBe(509196);
|
|
|
|
|
|
|
|
|
|
|
|
Http::assertSent(function (Request $r): bool {
|
|
|
|
|
|
if (! str_ends_with($r->url(), '/admin/report/save-report')) {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($r->method() !== 'POST') {
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
$body = $r->data();
|
|
|
|
|
|
|
|
|
|
|
|
return ($body['reportForm']['selectType'] ?? null) === 49
|
|
|
|
|
|
&& ($body['reportFilter']['dateFrom'] ?? null) === '2026-05-17'
|
|
|
|
|
|
&& ($body['reportFilter']['dateTo'] ?? null) === '2026-05-18'
|
|
|
|
|
|
&& ($body['reportFilter']['types'] ?? null) === ['phones']
|
|
|
|
|
|
&& ($body['reportFilter']['prophones'] ?? null) === 'curr'
|
|
|
|
|
|
&& ($body['reportFilter']['gck_tech'] ?? null) === 'gck';
|
|
|
|
|
|
});
|
2026-05-18 17:36:27 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-05-19 07:42:12 +03:00
|
|
|
|
it('waitReportReady polls load-reports until our entry has status "1"', function (): void {
|
|
|
|
|
|
Http::fakeSequence('crm.bp-gr.ru/admin/report/load-reports')
|
|
|
|
|
|
->push([
|
|
|
|
|
|
['id' => '509196', 'title' => 'Запрос номеров с 2026-05-17 по 2026-05-18', 'status' => '0'],
|
|
|
|
|
|
], 200)
|
|
|
|
|
|
->push([
|
|
|
|
|
|
['id' => '509196', 'title' => 'Запрос номеров с 2026-05-17 по 2026-05-18', 'status' => '1'],
|
|
|
|
|
|
], 200);
|
2026-05-18 17:36:27 +03:00
|
|
|
|
|
|
|
|
|
|
$client = app(SupplierPortalClient::class);
|
2026-05-19 07:42:12 +03:00
|
|
|
|
$client->waitReportReady(509196);
|
2026-05-18 17:36:27 +03:00
|
|
|
|
|
2026-05-19 07:42:12 +03:00
|
|
|
|
expect(true)->toBeTrue();
|
2026-05-18 17:36:27 +03:00
|
|
|
|
});
|
|
|
|
|
|
|
2026-05-19 07:42:12 +03:00
|
|
|
|
it('downloadReport returns raw CSV body from getfile', function (): void {
|
2026-05-18 17:36:27 +03:00
|
|
|
|
Http::fake([
|
|
|
|
|
|
'crm.bp-gr.ru/admin/report/getfile*' => Http::response("Name;Tag;Phone\nB1_a.com;t;79991234567\n", 200),
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
$client = app(SupplierPortalClient::class);
|
2026-05-19 07:42:12 +03:00
|
|
|
|
$csv = $client->downloadReport(509196);
|
2026-05-18 17:36:27 +03:00
|
|
|
|
|
|
|
|
|
|
expect($csv)->toContain('Name;Tag;Phone');
|
|
|
|
|
|
});
|