- 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>
539 lines
25 KiB
PHP
539 lines
25 KiB
PHP
<?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;
|
|
|
|
uses(TestCase::class, RefreshDatabase::class);
|
|
|
|
const MARYKER_UNPROCESSED = '/api/v1/maryker/order/unprocessed';
|
|
const MARYKER_SET_PROCESSED = '/api/v1/maryker/order/setProcessed';
|
|
|
|
function maryKerUser(Supplier $supplier, array $abilities = ['maryker:orders']): User
|
|
{
|
|
$user = User::factory()->create(['supplier_id' => $supplier->id]);
|
|
Sanctum::actingAs($user, $abilities);
|
|
|
|
return $user;
|
|
}
|
|
|
|
function maryKerOrder(Supplier $supplier, array $attributes = []): OrderArchive
|
|
{
|
|
static $sequence = 0;
|
|
$sequence++;
|
|
|
|
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 () {
|
|
it('401-et ad token nélkül, JSON Accept fejléccel és anélkül is', function () {
|
|
$this->getJson(MARYKER_UNPROCESSED)->assertUnauthorized();
|
|
$this->get(MARYKER_UNPROCESSED)->assertUnauthorized();
|
|
$this->patchJson(MARYKER_SET_PROCESSED, ['APICallBackId' => ['x']])->assertUnauthorized();
|
|
});
|
|
|
|
it('403-at ad, ha a token nem a maryker:orders ability-t hordozza', function () {
|
|
maryKerUser($this->mary, ['api:read']);
|
|
|
|
$this->getJson(MARYKER_UNPROCESSED)->assertForbidden();
|
|
$this->patchJson(MARYKER_SET_PROCESSED, ['APICallBackId' => ['x']])->assertForbidden();
|
|
});
|
|
|
|
it('403-at ad, ha a token tulajdonosa nincs beszállítóhoz kötve', function () {
|
|
Sanctum::actingAs(User::factory()->create(), ['maryker:orders']);
|
|
|
|
$this->getJson(MARYKER_UNPROCESSED)->assertForbidden();
|
|
$this->patchJson(MARYKER_SET_PROCESSED, ['APICallBackId' => ['x']])->assertForbidden();
|
|
});
|
|
|
|
it('valódi bearer tokennel is működik', function () {
|
|
$user = User::factory()->create(['supplier_id' => $this->mary->id]);
|
|
$token = $user->createToken('teszt', ['maryker:orders'])->plainTextToken;
|
|
maryKerOrder($this->mary);
|
|
|
|
$this->withToken($token)->getJson(MARYKER_UNPROCESSED)->assertOk()->assertJsonCount(1, 'data');
|
|
});
|
|
});
|
|
|
|
describe('unprocessed', function () {
|
|
it('csak a Mary-Ker megerősített, még nem visszaigazolt rendeléseit adja', function () {
|
|
maryKerUser($this->mary);
|
|
$own = maryKerOrder($this->mary);
|
|
maryKerOrder($this->other);
|
|
maryKerOrder($this->mary, ['confirmed' => null]);
|
|
maryKerOrder($this->mary, ['APIConfirmed' => '2026-10-21 08:00:00']);
|
|
|
|
$response = $this->getJson(MARYKER_UNPROCESSED)->assertOk();
|
|
|
|
$response->assertJsonCount(1, 'data')
|
|
->assertJsonPath('data.0.orderId', $own->humanId)
|
|
->assertJsonPath('data.0.confirmedAt', '2026-10-20 10:15:00')
|
|
->assertJsonPath('data.0.orderSum', 1234.5)
|
|
->assertJsonPath('data.0.orderDeliveryDate', '2026-10-22')
|
|
->assertJsonPath('data.0.orderDescription', 'megjegyzés')
|
|
->assertJsonPath('status', 200)
|
|
->assertJsonPath('success', true)
|
|
->assertJsonPath('apiVersion', '1')
|
|
->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);
|
|
|
|
$this->getJson(MARYKER_UNPROCESSED)->assertOk()->assertJsonCount(0, 'data')->assertJsonPath('pagination.total', 0);
|
|
});
|
|
|
|
it('a lapozás a konfigurált méretet követi, régi elöl', function () {
|
|
config(['maryker.per_page' => 2]);
|
|
maryKerUser($this->mary);
|
|
$orders = collect(range(1, 5))->map(fn () => maryKerOrder($this->mary));
|
|
|
|
$first = $this->getJson(MARYKER_UNPROCESSED)->assertOk();
|
|
$first->assertJsonCount(2, 'data')
|
|
->assertJsonPath('pagination.perPage', 2)
|
|
->assertJsonPath('pagination.total', 5)
|
|
->assertJsonPath('pagination.totalPages', 3)
|
|
->assertJsonPath('data.0.orderId', $orders[0]->humanId)
|
|
->assertJsonPath('data.1.orderId', $orders[1]->humanId);
|
|
|
|
$this->getJson(MARYKER_UNPROCESSED . '?page=3')->assertOk()
|
|
->assertJsonCount(1, 'data')
|
|
->assertJsonPath('data.0.orderId', $orders[4]->humanId);
|
|
});
|
|
|
|
it('nem szivárogtat updated_by / updated_at mezőt, és nem módosítja a rendelés audit mezőit', function () {
|
|
$order = maryKerOrder($this->mary);
|
|
$updatedBy = $order->fresh()->updated_by;
|
|
$updatedAt = $order->fresh()->updated_at;
|
|
maryKerUser($this->mary);
|
|
|
|
$this->travel(5)->minutes();
|
|
$response = $this->getJson(MARYKER_UNPROCESSED)->assertOk();
|
|
|
|
expect(array_keys($response->json('data.0')))
|
|
->toBe(['orderId', 'APICallBackId', 'confirmedAt', 'orderSum', 'orderDeliveryDate', 'orderDescription', 'profitCenter'])
|
|
->and($response->getContent())->not->toContain('updated_by')->not->toContain('updated_at');
|
|
|
|
$fresh = $order->fresh();
|
|
expect($fresh->updated_by)->toBe($updatedBy)
|
|
->and($fresh->updated_at->equalTo($updatedAt))->toBeTrue();
|
|
});
|
|
|
|
it('idempotens: ugyanazt adja, az APICallBackId stabil, az APILastGetting beáll', function () {
|
|
maryKerUser($this->mary);
|
|
$order = maryKerOrder($this->mary);
|
|
expect($order->fresh()->APILastGetting)->toBeNull();
|
|
|
|
$first = $this->getJson(MARYKER_UNPROCESSED)->assertOk()->json('data');
|
|
$second = $this->getJson(MARYKER_UNPROCESSED)->assertOk()->json('data');
|
|
|
|
expect($second)->toBe($first)
|
|
->and($first[0]['APICallBackId'])->toBeUuid()
|
|
->and($order->fresh()->APICallBackId)->toBe($first[0]['APICallBackId'])
|
|
->and($order->fresh()->APILastGetting)->not->toBeNull();
|
|
});
|
|
|
|
it('nem nyúl a más beszállító rendeléseihez', function () {
|
|
maryKerUser($this->mary);
|
|
maryKerOrder($this->mary);
|
|
$foreign = maryKerOrder($this->other);
|
|
|
|
$this->getJson(MARYKER_UNPROCESSED)->assertOk();
|
|
|
|
expect($foreign->fresh()->APICallBackId)->toBeNull()->and($foreign->fresh()->APILastGetting)->toBeNull();
|
|
});
|
|
});
|
|
|
|
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
|
|
{
|
|
return test()->getJson(MARYKER_UNPROCESSED)->assertOk()->json('data.0.APICallBackId');
|
|
}
|
|
|
|
it('visszaigazolja a lekért rendelést, és utána nem szerepel a listán', function () {
|
|
maryKerUser($this->mary);
|
|
$order = maryKerOrder($this->mary);
|
|
$id = fetchCallbackId();
|
|
|
|
$this->patchJson(MARYKER_SET_PROCESSED, ['APICallBackId' => [$id]])
|
|
->assertOk()
|
|
->assertJsonPath('success', true)
|
|
->assertJsonPath("data.$id", 'updated');
|
|
|
|
expect($order->fresh()->APIConfirmed)->not->toBeNull();
|
|
$this->getJson(MARYKER_UNPROCESSED)->assertOk()->assertJsonCount(0, 'data');
|
|
});
|
|
|
|
it('a másodszori visszaigazolás és az ismeretlen azonosító "invalid Id"', function () {
|
|
maryKerUser($this->mary);
|
|
maryKerOrder($this->mary);
|
|
$id = fetchCallbackId();
|
|
$unknown = '00000000-0000-0000-0000-000000000000';
|
|
|
|
$this->patchJson(MARYKER_SET_PROCESSED, ['APICallBackId' => [$id]])->assertOk();
|
|
$this->patchJson(MARYKER_SET_PROCESSED, ['APICallBackId' => [$id, $unknown]])->assertOk()
|
|
->assertJsonPath("data.$id", 'invalid Id')
|
|
->assertJsonPath("data.$unknown", 'invalid Id');
|
|
});
|
|
|
|
it('más beszállító rendelését nem igazolja vissza', function () {
|
|
maryKerUser($this->mary);
|
|
$foreign = maryKerOrder($this->other, ['APICallBackId' => 'aaaaaaaa-0000-0000-0000-000000000001', 'APILastGetting' => now()]);
|
|
|
|
$this->patchJson(MARYKER_SET_PROCESSED, ['APICallBackId' => [$foreign->APICallBackId]])->assertOk()
|
|
->assertJsonPath("data.$foreign->APICallBackId", 'invalid Id');
|
|
|
|
expect($foreign->fresh()->APIConfirmed)->toBeNull();
|
|
});
|
|
|
|
it('a még le nem kért rendelést nem lehet kézzel visszaigazolni', function () {
|
|
maryKerUser($this->mary);
|
|
$order = maryKerOrder($this->mary, ['APICallBackId' => 'bbbbbbbb-0000-0000-0000-000000000002']);
|
|
|
|
$this->patchJson(MARYKER_SET_PROCESSED, ['APICallBackId' => [$order->APICallBackId]])->assertOk()
|
|
->assertJsonPath("data.$order->APICallBackId", 'invalid Id');
|
|
|
|
expect($order->fresh()->APIConfirmed)->toBeNull();
|
|
});
|
|
|
|
it('a megerősítetlen (confirmed null) rendelést sem igazolja vissza', function () {
|
|
maryKerUser($this->mary);
|
|
$order = maryKerOrder($this->mary, [
|
|
'confirmed' => null, 'APICallBackId' => 'cccccccc-0000-0000-0000-000000000003', 'APILastGetting' => now(),
|
|
]);
|
|
|
|
$this->patchJson(MARYKER_SET_PROCESSED, ['APICallBackId' => [$order->APICallBackId]])->assertOk()
|
|
->assertJsonPath("data.$order->APICallBackId", 'invalid Id');
|
|
});
|
|
|
|
it('422-t ad, ha a bemenet nem érvényes tömb', function (mixed $payload) {
|
|
maryKerUser($this->mary);
|
|
$order = maryKerOrder($this->mary);
|
|
|
|
$this->patchJson(MARYKER_SET_PROCESSED, $payload)
|
|
->assertStatus(422)
|
|
->assertJsonPath('success', false)
|
|
->assertJsonPath('error.code', 'invalid data');
|
|
|
|
expect($order->fresh()->APIConfirmed)->toBeNull();
|
|
})->with([
|
|
'egyetlen string, nem tömb' => [['APICallBackId' => '987f3001-6364-4d7c-8b0c-daf29dbd38ec']],
|
|
'hiányzó kulcs' => [['orderIds' => ['x']]],
|
|
'üres tömb' => [['APICallBackId' => []]],
|
|
'beágyazott tömb' => [['APICallBackId' => [['x']]]],
|
|
'ismétlődő elem' => [['APICallBackId' => ['x', 'x']]],
|
|
'üres törzs' => [[]],
|
|
]);
|
|
|
|
it('422-t ad, ha a törzs nem JSON, vagy túl sok azonosítót tartalmaz', function () {
|
|
maryKerUser($this->mary);
|
|
|
|
$this->call('PATCH', MARYKER_SET_PROCESSED, [], [], [], ['HTTP_ACCEPT' => 'application/json'], 'nem json')->assertStatus(422);
|
|
|
|
config(['maryker.set_processed_max' => 2]);
|
|
$this->patchJson(MARYKER_SET_PROCESSED, ['APICallBackId' => ['a', 'b', 'c']])->assertStatus(422);
|
|
});
|
|
|
|
it('JSON Content-Type nélkül küldött törzset is feldolgoz', function () {
|
|
maryKerUser($this->mary);
|
|
maryKerOrder($this->mary);
|
|
$id = fetchCallbackId();
|
|
|
|
$this->call('PATCH', MARYKER_SET_PROCESSED, [], [], [], ['HTTP_ACCEPT' => 'application/json'], json_encode(['APICallBackId' => [$id]]))
|
|
->assertOk()->assertJsonPath("data.$id", 'updated');
|
|
});
|
|
});
|
|
|
|
describe('maryker:api-token', function () {
|
|
it('beszállítóhoz kötött, szerepkör nélküli felhasználóhoz ad ki tokent, ami működik', function () {
|
|
maryKerOrder($this->mary);
|
|
|
|
$this->artisan('maryker:api-token')->assertSuccessful();
|
|
|
|
$user = User::where('email', config('maryker.api_user_email'))->first();
|
|
expect($user->supplier_id)->toBe($this->mary->id)
|
|
->and($user->roles)->toHaveCount(0)
|
|
->and($user->tokens)->toHaveCount(1)
|
|
->and($user->tokens->first()->abilities)->toBe(['maryker:orders']);
|
|
});
|
|
|
|
it('a kiadott token a Mary-Ker rendeléseit látja, mást nem', function () {
|
|
maryKerOrder($this->mary);
|
|
maryKerOrder($this->other);
|
|
|
|
$this->artisan('maryker:api-token')->assertSuccessful();
|
|
$token = User::where('email', config('maryker.api_user_email'))->first()->tokens()->first();
|
|
// a nyers token csak a parancs kimenetében van meg, ezért újat adunk ki ugyanazzal a felhasználóval
|
|
$plain = $token->tokenable->createToken('teszt', ['maryker:orders'])->plainTextToken;
|
|
|
|
$this->withToken($plain)->getJson(MARYKER_UNPROCESSED)->assertOk()->assertJsonCount(1, 'data');
|
|
});
|
|
|
|
it('--rotate visszavonja a régi tokeneket, nélküle nem', function () {
|
|
$this->artisan('maryker:api-token')->assertSuccessful();
|
|
$this->artisan('maryker:api-token')->assertSuccessful();
|
|
$user = User::where('email', config('maryker.api_user_email'))->first();
|
|
expect($user->tokens()->count())->toBe(2);
|
|
|
|
$this->artisan('maryker:api-token', ['--rotate' => true])->assertSuccessful();
|
|
expect($user->tokens()->count())->toBe(1);
|
|
expect(User::where('email', config('maryker.api_user_email'))->count())->toBe(1);
|
|
});
|
|
|
|
it('hibával áll le, ha nincs ilyen beszállító', function () {
|
|
config(['maryker.supplier_name_id' => 'NINCS']);
|
|
|
|
$this->artisan('maryker:api-token')->assertFailed();
|
|
expect(User::where('email', config('maryker.api_user_email'))->exists())->toBeFalse();
|
|
});
|
|
|
|
it('nem ad tokent olyan felhasználónak, aki más beszállítóhoz van kötve', function () {
|
|
User::factory()->create(['email' => config('maryker.api_user_email'), 'supplier_id' => $this->other->id]);
|
|
|
|
$this->artisan('maryker:api-token')->assertFailed();
|
|
expect(User::where('email', config('maryker.api_user_email'))->first()->tokens)->toHaveCount(0);
|
|
});
|
|
});
|