ADD EV3-461 Mary-Ker API: orderSum 4 tizedesjegy, profitCenter blokk, vevőkód nélküli rendelések kizárása, maryker napló
- orderSum legfeljebb 4 tizedesjegyre kerekítve (lebegőpontos zaj nélkül) - profitCenter blokk: sellerProfitCenterId (vevőkód), név, cím és kontaktadatok a megrendelés pillanatképéből - a pillanatkép-cím szerkezetét az élő rekord adja, ha egyezik; különben bontás + figyelmeztetés - a vevőkód nélküli telephely rendelése kimarad az unprocessed listából, hibaként naplózva - saját maryker naplócsatorna (MaryKerLogger), ismétlődő események óránként egyszer Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c35e86f633
commit
759c5f5b52
@ -4,10 +4,12 @@
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\OrderArchive;
|
||||
use App\Services\MaryKerLogger;
|
||||
use App\Services\MaryKerOrderMapper;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
@ -22,12 +24,20 @@
|
||||
*/
|
||||
class MaryKerOrderController extends Controller
|
||||
{
|
||||
/** A válaszban szereplő számok tizedesjegyeinek maximuma. */
|
||||
private const DECIMALS = 4;
|
||||
|
||||
public function __construct(private readonly MaryKerOrderMapper $mapper) {}
|
||||
|
||||
/**
|
||||
* Feldolgozatlan rendelések (confirmed nem null, APIConfirmed null), régi elöl, lapozva.
|
||||
*
|
||||
* Idempotens a találati halmaz szempontjából: a lista csak az APIConfirmed-től függ, ezért ugyanazt
|
||||
* adja, amíg a setProcessed meg nem történik. Az APICallBackId-t csak az első lekérésnél generálja,
|
||||
* utána stabil. Az egyetlen mellékhatás az APILastGetting bélyeg.
|
||||
* Idempotens a találati halmaz szempontjából: a lista csak az APIConfirmed-től és a vevőkód meglététől függ,
|
||||
* ezért ugyanazt adja, amíg a setProcessed meg nem történik. Az APICallBackId-t csak az első lekérésnél
|
||||
* generálja, utána stabil. Az egyetlen mellékhatás az APILastGetting bélyeg.
|
||||
*
|
||||
* Az a rendelés, amelynek telephelyéhez nincs beszállítói vevőkód, kimarad a listából (Apolló nem tudná
|
||||
* párosítani), és hibaként bekerül a maryker naplóba, amíg a kódot rögzítik.
|
||||
*/
|
||||
public function unProcessed(Request $request): JsonResponse
|
||||
{
|
||||
@ -39,30 +49,35 @@ public function unProcessed(Request $request): JsonResponse
|
||||
return $this->forbidden($header);
|
||||
}
|
||||
|
||||
$page = OrderArchive::query()
|
||||
->select(['id', 'humanId', 'confirmed', 'sumPrice', 'deliveryDate', 'note'])
|
||||
->where('supplier_id', $supplierId)
|
||||
->whereNotNull('confirmed')
|
||||
->whereNull('APIConfirmed')
|
||||
$this->logOrdersWithoutCustomerCode($supplierId);
|
||||
|
||||
$page = $this->pending($supplierId)
|
||||
->whereExists($this->customerCode($supplierId))
|
||||
->select([
|
||||
'id', 'humanId', 'confirmed', 'sumPrice', 'deliveryDate', 'note', 'profit_center_id', 'contactName',
|
||||
'profit_center_name', 'deliveryAddressId', 'deliveryAddressName', 'deliveryAddress',
|
||||
])
|
||||
->orderBy('id')
|
||||
->paginate(max(1, (int) config('maryker.per_page')));
|
||||
|
||||
$ids = $page->getCollection()->pluck('id');
|
||||
$callbackIds = $this->ensureCallbackIds($ids->all());
|
||||
$profitCenters = $this->mapper->profitCenterBlocks($page->getCollection(), $supplierId);
|
||||
|
||||
OrderArchive::query()->toBase()->whereIn('id', $ids)->update(['APILastGetting' => $updateDate]);
|
||||
|
||||
// TODO 1.2: profitCenter (sellerProfitCenterId, szállítási alegység, cím) és items (sellerItemNumber, sumPrice ...)
|
||||
// TODO 1.2: items (sellerItemNumber, packMultiplier, packName, price, sumPrice ...)
|
||||
$page->setCollection($page->getCollection()->map(fn (OrderArchive $order) => [
|
||||
'orderId' => $order->humanId,
|
||||
'APICallBackId' => $callbackIds[$order->id],
|
||||
'confirmedAt' => $order->confirmed,
|
||||
'orderSum' => $order->sumPrice,
|
||||
'orderSum' => $this->number($order->sumPrice),
|
||||
'orderDeliveryDate' => $order->deliveryDate,
|
||||
'orderDescription' => (string) $order->note,
|
||||
'profitCenter' => $profitCenters[$order->id],
|
||||
]));
|
||||
|
||||
Log::channel('api')->info('MaryKer unprocessed', [
|
||||
MaryKerLogger::channel()->info('MaryKer unprocessed', [
|
||||
'userId' => $request->user()->id, 'page' => $page->currentPage(), 'orderIds' => $ids->all(),
|
||||
]);
|
||||
|
||||
@ -92,7 +107,7 @@ public function setProcessed(Request $request): JsonResponse
|
||||
]);
|
||||
if (! is_array($body) || $validator->fails()) {
|
||||
$message = is_array($body) ? $validator->errors()->first() : 'A kérés törzse nem érvényes JSON objektum.';
|
||||
Log::channel('api')->warning('MaryKer setProcessed invalid data', ['userId' => $request->user()->id, 'message' => $message]);
|
||||
MaryKerLogger::channel()->warning('MaryKer setProcessed invalid data', ['userId' => $request->user()->id, 'message' => $message]);
|
||||
|
||||
return responder()->error('invalid data', $message)->respond(422, $header);
|
||||
}
|
||||
@ -110,11 +125,47 @@ public function setProcessed(Request $request): JsonResponse
|
||||
$result[$callbackId] = $updated ? 'updated' : 'invalid Id';
|
||||
}
|
||||
|
||||
Log::channel('api')->info('MaryKer setProcessed', ['userId' => $request->user()->id, 'result' => $result]);
|
||||
MaryKerLogger::channel()->info('MaryKer setProcessed', ['userId' => $request->user()->id, 'result' => $result]);
|
||||
|
||||
return responder()->success($result)->respond(null, $header);
|
||||
}
|
||||
|
||||
/** A beszállító megerősített, még nem visszaigazolt rendelései. */
|
||||
private function pending(int $supplierId): Builder
|
||||
{
|
||||
return OrderArchive::query()
|
||||
->where('supplier_id', $supplierId)
|
||||
->whereNotNull('confirmed')
|
||||
->whereNull('APIConfirmed');
|
||||
}
|
||||
|
||||
/** Alkérdés: van-e a rendelés telephelyéhez rögzített, nem üres beszállítói vevőkód. */
|
||||
private function customerCode(int $supplierId): \Closure
|
||||
{
|
||||
return fn ($query) => $query->selectRaw('1')
|
||||
->from('profit_center_supplier_codes')
|
||||
->whereColumn('profit_center_supplier_codes.profit_center_id', 'order_archives.profit_center_id')
|
||||
->where('profit_center_supplier_codes.supplier_id', $supplierId)
|
||||
->whereNotNull('profit_center_supplier_codes.customerCode')
|
||||
->where('profit_center_supplier_codes.customerCode', '<>', '')
|
||||
->whereNull('profit_center_supplier_codes.deleted_at');
|
||||
}
|
||||
|
||||
/** A vevőkód nélküli rendelések kimaradnak a listából: hibaként naplózzuk őket (rendelésenként óránként egyszer). */
|
||||
private function logOrdersWithoutCustomerCode(int $supplierId): void
|
||||
{
|
||||
$this->pending($supplierId)
|
||||
->whereNotExists($this->customerCode($supplierId))
|
||||
->orderBy('id')->limit(500)
|
||||
->get(['id', 'humanId', 'profit_center_id'])
|
||||
->each(fn (OrderArchive $order) => MaryKerLogger::once(
|
||||
'error',
|
||||
"customer-code:{$order->id}",
|
||||
'MaryKer: a rendelés kimarad az unprocessed listából, a telephelyhez nincs beszállítói vevőkód',
|
||||
['orderId' => $order->id, 'humanId' => $order->humanId, 'profitCenterId' => $order->profit_center_id],
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Az üres APICallBackId-kat feltölti (versenyhelyzet-biztosan: csak null-t ír felül), majd visszaadja
|
||||
* az összes megadott rendelés azonosítóját id => uuid alakban.
|
||||
@ -134,6 +185,15 @@ private function ensureCallbackIds(array $orderIds): array
|
||||
return OrderArchive::query()->toBase()->whereIn('id', $orderIds)->pluck('APICallBackId', 'id')->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Pénzösszeg / mennyiség a partnerrel egyeztetett formátumban: legfeljebb 4 tizedesjegy (specifikáció 2. pont).
|
||||
* A tárolt double lebegőpontos zajt hordoz (pl. 258817.12149533), ezért kerekítjük.
|
||||
*/
|
||||
private function number(float|int|string|null $value): ?float
|
||||
{
|
||||
return $value === null ? null : round((float) $value, self::DECIMALS);
|
||||
}
|
||||
|
||||
/** @return array{apiVersion: string, processedTime: string} */
|
||||
private function header(Carbon $time): array
|
||||
{
|
||||
|
||||
33
app/Services/MaryKerLogger.php
Normal file
33
app/Services/MaryKerLogger.php
Normal file
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
/**
|
||||
* A Mary-Ker API (EV3-461) naplója: storage/logs/maryker-*.log (a `maryker` csatorna).
|
||||
*/
|
||||
class MaryKerLogger
|
||||
{
|
||||
/** Egy ismétlődő eseményt (pl. egy rendelés, ami minden lekérésnél kimarad) legfeljebb ennyi másodpercenként naplózunk újra. */
|
||||
public const REPEAT_AFTER = 3600;
|
||||
|
||||
/** @return LoggerInterface */
|
||||
public static function channel()
|
||||
{
|
||||
return Log::channel('maryker');
|
||||
}
|
||||
|
||||
/**
|
||||
* Naplóz, de ugyanazt a kulcsú eseményt csak REPEAT_AFTER másodpercenként: az Apolló rendszeresen lekérdez,
|
||||
* és a hiba addig fennáll, amíg valaki ki nem javítja az adatot — így nem telik meg a napló, de nem is tűnik el.
|
||||
*/
|
||||
public static function once(string $level, string $key, string $message, array $context = []): void
|
||||
{
|
||||
if (Cache::add('maryker:log:' . $key, true, self::REPEAT_AFTER)) {
|
||||
self::channel()->{$level}($message, $context);
|
||||
}
|
||||
}
|
||||
}
|
||||
126
app/Services/MaryKerOrderMapper.php
Normal file
126
app/Services/MaryKerOrderMapper.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Models\Address;
|
||||
use App\Models\OrderArchive;
|
||||
use App\Models\ProfitCenter;
|
||||
use App\Models\ProfitCenterSupplierCode;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
* Az OrderArchive sorokból a Mary-Ker API JSON-blokkjait állítja elő (EV3-461, specifikáció 3. pont).
|
||||
*/
|
||||
class MaryKerOrderMapper
|
||||
{
|
||||
/**
|
||||
* A "profitCenter" blokk rendelésenként. A cím a megrendeléskor rögzített pillanatkép
|
||||
* (order_archives.deliveryAddress / deliveryAddressName), nem az élő törzsadat.
|
||||
*
|
||||
* A pillanatkép egyetlen szöveg ("{irányítószám} {város} {utca}"), az API viszont külön postCode / city / address
|
||||
* mezőt ad. A szerkezetet az élő rekordból vesszük, de csak akkor, ha az pontosan ugyanazt a címet adja ki, mint
|
||||
* a pillanatkép (azaz a cím a rendelés óta nem változott) és az irányítószáma érvényes. Egyébként a szöveget
|
||||
* bontjuk, ami becslés, ezért figyelmeztetést naplózunk.
|
||||
*
|
||||
* TODO 2.4: sellerDeliveryLocationId (szállítási alegység-azonosító) — a 2. szakasz új táblájából.
|
||||
*
|
||||
* @param Collection<int, OrderArchive> $orders
|
||||
* @return array<int, array<string, string>> rendelés id => blokk
|
||||
*/
|
||||
public function profitCenterBlocks(Collection $orders, int $supplierId): array
|
||||
{
|
||||
$profitCenterIds = $orders->pluck('profit_center_id')->filter()->unique()->values();
|
||||
|
||||
$profitCenters = ProfitCenter::withTrashed()
|
||||
->whereIn('id', $profitCenterIds)
|
||||
->with(['address' => fn ($query) => $query->orderBy('id')])
|
||||
->get()->keyBy('id');
|
||||
$customerCodes = ProfitCenterSupplierCode::where('supplier_id', $supplierId)
|
||||
->whereIn('profit_center_id', $profitCenterIds)
|
||||
->pluck('customerCode', 'profit_center_id');
|
||||
$addresses = Address::whereIn('id', $orders->pluck('deliveryAddressId')->filter()->unique())
|
||||
->get()->keyBy('id');
|
||||
|
||||
$blocks = [];
|
||||
foreach ($orders as $order) {
|
||||
$profitCenter = $profitCenters->get($order->profit_center_id);
|
||||
$live = $order->deliveryAddressId
|
||||
? $addresses->get($order->deliveryAddressId)
|
||||
: $this->profitCenterAddress($profitCenter);
|
||||
[$postCode, $city, $street] = $this->splitAddress($order, $live);
|
||||
|
||||
$blocks[$order->id] = [
|
||||
// string marad, a vezető nullák megmaradnak
|
||||
'sellerProfitCenterId' => (string) $customerCodes->get($order->profit_center_id),
|
||||
'name' => (string) ($order->deliveryAddressName ?: $order->profit_center_name ?: $profitCenter?->name),
|
||||
'postCode' => $postCode,
|
||||
'city' => $city,
|
||||
'address' => $street,
|
||||
'contactName' => (string) $order->contactName,
|
||||
'contactEmail' => (string) $profitCenter?->email,
|
||||
'contactPhone' => (string) $profitCenter?->phone,
|
||||
'contactMobil' => (string) $profitCenter?->mobil,
|
||||
];
|
||||
}
|
||||
|
||||
return $blocks;
|
||||
}
|
||||
|
||||
/** Ugyanazt a szabályt követi, mint a megrendelő felület (OrderController::getProfitCenterAddress). */
|
||||
private function profitCenterAddress(?ProfitCenter $profitCenter): ProfitCenter|Address|null
|
||||
{
|
||||
if (! $profitCenter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int) $profitCenter->addressEqual ? $profitCenter : $profitCenter->address->first();
|
||||
}
|
||||
|
||||
/** @return array{0: string, 1: string, 2: string} [irányítószám, város, utca] */
|
||||
private function splitAddress(OrderArchive $order, ProfitCenter|Address|null $live): array
|
||||
{
|
||||
$snapshot = $this->normalize($order->deliveryAddress);
|
||||
|
||||
if ($live && $this->validPostCode($live->postCode)
|
||||
&& ($snapshot === '' || $this->normalize($live->fullAddress) === $snapshot)) {
|
||||
return [trim($live->postCode), trim((string) $live->city), trim((string) $live->street)];
|
||||
}
|
||||
|
||||
if ($snapshot === '') {
|
||||
$this->warn($order, 'nincs pillanatkép-cím, és az élő cím sem használható');
|
||||
|
||||
return ['', '', ''];
|
||||
}
|
||||
|
||||
if (preg_match('/^(\d{4})\s+(\S+)\s*(.*)$/u', $snapshot, $parts)) {
|
||||
$this->warn($order, 'a pillanatkép nem azonos az élő címmel (vagy az élő cím hibás), a bontás becslés', $snapshot);
|
||||
|
||||
return [$parts[1], rtrim($parts[2], ',;'), $parts[3]];
|
||||
}
|
||||
|
||||
$this->warn($order, 'a pillanatkép-cím nem bontható irányítószámra, városra és utcára', $snapshot);
|
||||
|
||||
return ['', '', $snapshot];
|
||||
}
|
||||
|
||||
private function warn(OrderArchive $order, string $reason, ?string $snapshot = null): void
|
||||
{
|
||||
MaryKerLogger::once('warning', "address:{$order->id}", 'MaryKer: címadat-eltérés a rendelésen: ' . $reason, [
|
||||
'orderId' => $order->id,
|
||||
'humanId' => $order->humanId,
|
||||
'profitCenterId' => $order->profit_center_id,
|
||||
'deliveryAddressId' => $order->deliveryAddressId,
|
||||
'snapshot' => $snapshot ?? $order->deliveryAddress,
|
||||
]);
|
||||
}
|
||||
|
||||
private function validPostCode(?string $postCode): bool
|
||||
{
|
||||
return (bool) preg_match('/^\d{4}$/', trim((string) $postCode));
|
||||
}
|
||||
|
||||
private function normalize(?string $text): string
|
||||
{
|
||||
return trim((string) preg_replace('/\s+/u', ' ', (string) $text));
|
||||
}
|
||||
}
|
||||
@ -73,6 +73,14 @@
|
||||
// 'formatter'=>\Monolog\Formatter\HtmlFormatter::class,
|
||||
],
|
||||
|
||||
// Mary-Ker API-kapcsolat (EV3-461): kérések, kihagyott rendelések, adatminőségi figyelmeztetések
|
||||
'maryker' => [
|
||||
'driver' => 'daily',
|
||||
'path' => storage_path('logs/maryker.log'),
|
||||
'level' => env('LOG_LEVEL', 'debug'),
|
||||
'days' => 30,
|
||||
],
|
||||
|
||||
'supplierNotifier' => [
|
||||
'driver' => 'daily',
|
||||
'path' => storage_path('logs/supplierNotifier.log'),
|
||||
|
||||
@ -1,9 +1,13 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Address;
|
||||
use App\Models\OrderArchive;
|
||||
use App\Models\ProfitCenter;
|
||||
use App\Models\ProfitCenterSupplierCode;
|
||||
use App\Models\Supplier;
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Laravel\Sanctum\Sanctum;
|
||||
use Tests\TestCase;
|
||||
|
||||
@ -27,17 +31,37 @@ function maryKerOrder(Supplier $supplier, array $attributes = []): OrderArchive
|
||||
|
||||
return OrderArchive::create(array_merge([
|
||||
'supplier_id' => $supplier->id,
|
||||
'profit_center_id' => test()->profitCenter->id,
|
||||
'profit_center_name' => 'Teszt telephely',
|
||||
'humanId' => sprintf('%s/AKG/26/%04d', $supplier->nameId, $sequence),
|
||||
'confirmed' => '2026-10-20 10:15:00',
|
||||
'deliveryDate' => '2026-10-22',
|
||||
'deliveryAddress' => '7623 Pécs Rákóczi út 2.',
|
||||
'contactName' => 'Kiss Anna',
|
||||
'sumPrice' => 1234.5,
|
||||
'note' => 'megjegyzés',
|
||||
], $attributes));
|
||||
}
|
||||
|
||||
function maryKerLogSpy(): Mockery\MockInterface
|
||||
{
|
||||
$spy = Log::spy();
|
||||
$spy->shouldReceive('channel')->andReturnSelf();
|
||||
|
||||
return $spy;
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
$this->mary = Supplier::factory()->create(['nameId' => 'MARY']);
|
||||
$this->other = Supplier::factory()->create(['nameId' => 'IDEGEN']);
|
||||
$this->profitCenter = ProfitCenter::factory()->create([
|
||||
'name' => 'Teszt telephely', 'postCode' => '7623', 'city' => 'Pécs', 'street' => 'Rákóczi út 2.',
|
||||
'addressEqual' => '1', 'multiAddress' => '0',
|
||||
'email' => 'telephely@example.test', 'phone' => '72-111-222', 'mobil' => '30-111-2222',
|
||||
]);
|
||||
// mindkét beszállítóhoz van vevőkód, hogy a kizárás ne az izolációs teszteket torzítsa
|
||||
ProfitCenterSupplierCode::create(['profit_center_id' => $this->profitCenter->id, 'supplier_id' => $this->mary->id, 'customerCode' => '002934']);
|
||||
ProfitCenterSupplierCode::create(['profit_center_id' => $this->profitCenter->id, 'supplier_id' => $this->other->id, 'customerCode' => '777']);
|
||||
});
|
||||
|
||||
describe('hitelesítés', function () {
|
||||
@ -92,6 +116,28 @@ function maryKerOrder(Supplier $supplier, array $attributes = []): OrderArchive
|
||||
->assertJsonStructure(['processedTime', 'pagination' => ['count', 'total', 'perPage', 'currentPage', 'totalPages']]);
|
||||
});
|
||||
|
||||
it('az orderSum-ot legfeljebb 4 tizedesjegyre kerekíti, a lebegőpontos zaj nélkül', function () {
|
||||
maryKerUser($this->mary);
|
||||
maryKerOrder($this->mary, ['sumPrice' => 258817.12149533]);
|
||||
|
||||
$response = $this->getJson(MARYKER_UNPROCESSED)->assertOk();
|
||||
|
||||
expect($response->getContent())->toContain('"orderSum":258817.1215,')
|
||||
->and($response->json('data.0.orderSum'))->toBe(258817.1215);
|
||||
});
|
||||
|
||||
it('az egész összeget és a hiányzó összeget helyesen adja', function () {
|
||||
maryKerUser($this->mary);
|
||||
maryKerOrder($this->mary, ['sumPrice' => 312801]);
|
||||
maryKerOrder($this->mary, ['sumPrice' => null]);
|
||||
|
||||
$data = $this->getJson(MARYKER_UNPROCESSED)->assertOk()->json('data');
|
||||
|
||||
// JSON-ban az egész érték .0 nélkül jelenik meg (312801), ami a kliensnek ugyanaz a szám
|
||||
expect($data[0]['orderSum'])->toEqual(312801)
|
||||
->and($data[1]['orderSum'])->toBeNull();
|
||||
});
|
||||
|
||||
it('a más beszállító rendelése egyáltalán nem látszik, akkor sem, ha nincs Mary-Ker rendelés', function () {
|
||||
maryKerUser($this->mary);
|
||||
maryKerOrder($this->other);
|
||||
@ -127,7 +173,7 @@ function maryKerOrder(Supplier $supplier, array $attributes = []): OrderArchive
|
||||
$response = $this->getJson(MARYKER_UNPROCESSED)->assertOk();
|
||||
|
||||
expect(array_keys($response->json('data.0')))
|
||||
->toBe(['orderId', 'APICallBackId', 'confirmedAt', 'orderSum', 'orderDeliveryDate', 'orderDescription'])
|
||||
->toBe(['orderId', 'APICallBackId', 'confirmedAt', 'orderSum', 'orderDeliveryDate', 'orderDescription', 'profitCenter'])
|
||||
->and($response->getContent())->not->toContain('updated_by')->not->toContain('updated_at');
|
||||
|
||||
$fresh = $order->fresh();
|
||||
@ -160,6 +206,186 @@ function maryKerOrder(Supplier $supplier, array $attributes = []): OrderArchive
|
||||
});
|
||||
});
|
||||
|
||||
describe('profitCenter blokk', function () {
|
||||
function profitCenterBlock(): array
|
||||
{
|
||||
return test()->getJson(MARYKER_UNPROCESSED)->assertOk()->json('data.0.profitCenter');
|
||||
}
|
||||
|
||||
it('a telephely adatait a megrendelés pillanatképéből és a vevőkódból adja', function () {
|
||||
maryKerUser($this->mary);
|
||||
maryKerOrder($this->mary);
|
||||
|
||||
expect(profitCenterBlock())->toBe([
|
||||
'sellerProfitCenterId' => '002934',
|
||||
'name' => 'Teszt telephely',
|
||||
'postCode' => '7623',
|
||||
'city' => 'Pécs',
|
||||
'address' => 'Rákóczi út 2.',
|
||||
'contactName' => 'Kiss Anna',
|
||||
'contactEmail' => 'telephely@example.test',
|
||||
'contactPhone' => '72-111-222',
|
||||
'contactMobil' => '30-111-2222',
|
||||
]);
|
||||
});
|
||||
|
||||
it('a vevőkód string marad, a vezető nullákkal, és a beszállítóé, nem a másiké', function () {
|
||||
maryKerUser($this->mary);
|
||||
maryKerOrder($this->mary);
|
||||
|
||||
$response = $this->getJson(MARYKER_UNPROCESSED)->assertOk();
|
||||
|
||||
expect($response->getContent())->toContain('"sellerProfitCenterId":"002934"')
|
||||
->and($response->json('data.0.profitCenter.sellerProfitCenterId'))->toBeString()->toBe('002934');
|
||||
});
|
||||
|
||||
it('a hiányzó kontaktadatot üres szövegként adja, nem null-ként', function () {
|
||||
maryKerUser($this->mary);
|
||||
$this->profitCenter->update(['email' => null, 'phone' => null, 'mobil' => null]);
|
||||
maryKerOrder($this->mary, ['contactName' => null]);
|
||||
|
||||
expect(profitCenterBlock())->toMatchArray([
|
||||
'contactName' => '', 'contactEmail' => '', 'contactPhone' => '', 'contactMobil' => '',
|
||||
]);
|
||||
});
|
||||
|
||||
it('a kiválasztott szállítási cím pillanatképét adja, a szerkezetet a címrekordból', function () {
|
||||
maryKerUser($this->mary);
|
||||
$address = Address::create([
|
||||
'name' => 'Kórház', 'postCode' => '7624', 'city' => 'Pécs', 'street' => 'Ifjúság útja 13',
|
||||
'attachable_id' => $this->profitCenter->id, 'attachable_type' => ProfitCenter::class,
|
||||
]);
|
||||
maryKerOrder($this->mary, [
|
||||
'deliveryAddressId' => $address->id, 'deliveryAddressName' => 'Kórház', 'deliveryAddress' => '7624 Pécs Ifjúság útja 13',
|
||||
]);
|
||||
|
||||
expect(profitCenterBlock())->toMatchArray([
|
||||
'name' => 'Kórház', 'postCode' => '7624', 'city' => 'Pécs', 'address' => 'Ifjúság útja 13',
|
||||
]);
|
||||
});
|
||||
|
||||
it('több címes telephelynél cím kiválasztása nélkül az első címet használja, mint a megrendelő felület', function () {
|
||||
maryKerUser($this->mary);
|
||||
$this->profitCenter->update(['addressEqual' => '0', 'multiAddress' => '1']);
|
||||
Address::create([
|
||||
'name' => 'Első', 'postCode' => '8200', 'city' => 'Veszprém', 'street' => 'Pápai út 55.',
|
||||
'attachable_id' => $this->profitCenter->id, 'attachable_type' => ProfitCenter::class,
|
||||
]);
|
||||
maryKerOrder($this->mary, ['deliveryAddress' => '8200 Veszprém Pápai út 55.']);
|
||||
|
||||
expect(profitCenterBlock())->toMatchArray(['postCode' => '8200', 'city' => 'Veszprém', 'address' => 'Pápai út 55.']);
|
||||
});
|
||||
|
||||
it('a rendelés óta megváltozott élő címnél a pillanatképet adja, és figyelmeztetést naplóz', function () {
|
||||
$spy = maryKerLogSpy();
|
||||
maryKerUser($this->mary);
|
||||
maryKerOrder($this->mary, ['deliveryAddress' => '7623 Pécs Régi utca 1.']); // az élő cím azóta: Rákóczi út 2.
|
||||
|
||||
expect(profitCenterBlock())->toMatchArray(['postCode' => '7623', 'city' => 'Pécs', 'address' => 'Régi utca 1.']);
|
||||
$spy->shouldHaveReceived('warning')->once()->withArgs(fn ($message) => str_contains($message, 'címadat-eltérés'));
|
||||
});
|
||||
|
||||
it('az oszlopeltolódott (hibás) címrekordból nem ad félrevezető szerkezetet, a teljes szöveget adja és naplóz', function () {
|
||||
$spy = maryKerLogSpy();
|
||||
maryKerUser($this->mary);
|
||||
$address = Address::create([
|
||||
'name' => '', 'postCode' => 'Gloriett Főzőkonyha', 'city' => '1186 Budapest', 'street' => 'Tövishát u. 8.',
|
||||
'attachable_id' => $this->profitCenter->id, 'attachable_type' => ProfitCenter::class,
|
||||
]);
|
||||
maryKerOrder($this->mary, [
|
||||
'deliveryAddressId' => $address->id, 'deliveryAddress' => 'Gloriett Főzőkonyha 1186 Budapest Tövishát u. 8.',
|
||||
]);
|
||||
|
||||
expect(profitCenterBlock())->toMatchArray([
|
||||
'postCode' => '', 'city' => '', 'address' => 'Gloriett Főzőkonyha 1186 Budapest Tövishát u. 8.',
|
||||
]);
|
||||
$spy->shouldHaveReceived('warning')->once();
|
||||
});
|
||||
|
||||
it('az egy mezőbe írt címet (vesszővel) a pillanatképből bontja', function () {
|
||||
maryKerUser($this->mary);
|
||||
$this->profitCenter->update(['postCode' => '', 'city' => '', 'street' => '9700 Szombathely, Puskás Tivadar utca 10.']);
|
||||
maryKerOrder($this->mary, ['deliveryAddress' => '9700 Szombathely, Puskás Tivadar utca 10.']);
|
||||
|
||||
expect(profitCenterBlock())->toMatchArray(['postCode' => '9700', 'city' => 'Szombathely', 'address' => 'Puskás Tivadar utca 10.']);
|
||||
});
|
||||
|
||||
it('a telephely nevét a megrendelés pillanatképéből adja, nem az élő törzsadatból', function () {
|
||||
maryKerUser($this->mary);
|
||||
$this->profitCenter->update(['name' => 'Átnevezett telephely']);
|
||||
maryKerOrder($this->mary, ['profit_center_name' => 'Régi telephelynév']);
|
||||
|
||||
expect(profitCenterBlock()['name'])->toBe('Régi telephelynév');
|
||||
});
|
||||
});
|
||||
|
||||
describe('vevőkód nélküli rendelések', function () {
|
||||
it('kimaradnak a listából és a lapozás összegéből, a vevőkódosak maradnak', function () {
|
||||
maryKerUser($this->mary);
|
||||
$withCode = maryKerOrder($this->mary);
|
||||
$bare = ProfitCenter::factory()->create(['postCode' => '1111']);
|
||||
maryKerOrder($this->mary, ['profit_center_id' => $bare->id]);
|
||||
|
||||
$this->getJson(MARYKER_UNPROCESSED)->assertOk()
|
||||
->assertJsonCount(1, 'data')
|
||||
->assertJsonPath('pagination.total', 1)
|
||||
->assertJsonPath('data.0.orderId', $withCode->humanId);
|
||||
});
|
||||
|
||||
it('az üres, a törölt és a másik beszállítóhoz tartozó vevőkód nem számít vevőkódnak', function (callable $arrange) {
|
||||
maryKerUser($this->mary);
|
||||
$profitCenter = ProfitCenter::factory()->create(['postCode' => '1111']);
|
||||
$arrange($profitCenter, $this);
|
||||
maryKerOrder($this->mary, ['profit_center_id' => $profitCenter->id]);
|
||||
|
||||
$this->getJson(MARYKER_UNPROCESSED)->assertOk()->assertJsonCount(0, 'data');
|
||||
})->with([
|
||||
'üres szöveg' => [fn ($pc, $t) => ProfitCenterSupplierCode::create(['profit_center_id' => $pc->id, 'supplier_id' => $t->mary->id, 'customerCode' => ''])],
|
||||
'null' => [fn ($pc, $t) => ProfitCenterSupplierCode::create(['profit_center_id' => $pc->id, 'supplier_id' => $t->mary->id, 'customerCode' => null])],
|
||||
'törölt rekord' => [fn ($pc, $t) => ProfitCenterSupplierCode::create(['profit_center_id' => $pc->id, 'supplier_id' => $t->mary->id, 'customerCode' => '123'])->delete()],
|
||||
'másik beszállító kódja' => [fn ($pc, $t) => ProfitCenterSupplierCode::create(['profit_center_id' => $pc->id, 'supplier_id' => $t->other->id, 'customerCode' => '123'])],
|
||||
]);
|
||||
|
||||
it('hibaként naplózza a maryker csatornán, rendelésenként csak egyszer az ismétlődő lekéréseknél', function () {
|
||||
$spy = maryKerLogSpy();
|
||||
maryKerUser($this->mary);
|
||||
$bare = ProfitCenter::factory()->create(['postCode' => '1111']);
|
||||
$order = maryKerOrder($this->mary, ['profit_center_id' => $bare->id]);
|
||||
|
||||
$this->getJson(MARYKER_UNPROCESSED)->assertOk();
|
||||
$this->getJson(MARYKER_UNPROCESSED)->assertOk();
|
||||
|
||||
$spy->shouldHaveReceived('channel')->with('maryker');
|
||||
$spy->shouldHaveReceived('error')->once()->withArgs(
|
||||
fn ($message, $context) => str_contains($message, 'vevőkód')
|
||||
&& $context['orderId'] === $order->id && $context['humanId'] === $order->humanId
|
||||
);
|
||||
});
|
||||
|
||||
it('a vevőkód nélküli rendelést nem érinti az APILastGetting és az APICallBackId', function () {
|
||||
maryKerUser($this->mary);
|
||||
$bare = ProfitCenter::factory()->create(['postCode' => '1111']);
|
||||
$order = maryKerOrder($this->mary, ['profit_center_id' => $bare->id]);
|
||||
|
||||
$this->getJson(MARYKER_UNPROCESSED)->assertOk();
|
||||
|
||||
expect($order->fresh()->APICallBackId)->toBeNull()->and($order->fresh()->APILastGetting)->toBeNull();
|
||||
});
|
||||
|
||||
it('a vevőkód rögzítése után a rendelés megjelenik', function () {
|
||||
maryKerUser($this->mary);
|
||||
$bare = ProfitCenter::factory()->create(['postCode' => '1111']);
|
||||
maryKerOrder($this->mary, ['profit_center_id' => $bare->id]);
|
||||
$this->getJson(MARYKER_UNPROCESSED)->assertOk()->assertJsonCount(0, 'data');
|
||||
|
||||
ProfitCenterSupplierCode::create(['profit_center_id' => $bare->id, 'supplier_id' => $this->mary->id, 'customerCode' => '0042']);
|
||||
|
||||
$this->getJson(MARYKER_UNPROCESSED)->assertOk()
|
||||
->assertJsonCount(1, 'data')
|
||||
->assertJsonPath('data.0.profitCenter.sellerProfitCenterId', '0042');
|
||||
});
|
||||
});
|
||||
|
||||
describe('setProcessed', function () {
|
||||
function fetchCallbackId(): string
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user