Passed
Push — master ( 73bf48...047dc7 )
by Ilya
05:56 queued 16s
created

assertResponseContainsAmendmentOrderReference()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 6
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
/**
4
 * This file is part of the Spryker Commerce OS.
5
 * For full license information, please view the LICENSE file that was distributed with this source code.
6
 */
7
8
declare(strict_types = 1);
9
10
namespace PyzTest\Glue\OrderAmendments;
11
12
use Generated\Shared\Transfer\CustomerTransfer;
13
use Generated\Shared\Transfer\MoneyValueTransfer;
14
use Generated\Shared\Transfer\PriceProductTransfer;
15
use Generated\Shared\Transfer\ProductConcreteTransfer;
16
use Generated\Shared\Transfer\StockProductTransfer;
17
use Generated\Shared\Transfer\StoreTransfer;
18
use Spryker\Glue\CartReorderRestApi\CartReorderRestApiConfig;
19
use SprykerTest\Glue\Testify\Tester\ApiEndToEndTester;
20
21
/**
22
 * Inherited Methods
23
 *
24
 * @method void wantTo($text)
25
 * @method void wantToTest($text)
26
 * @method void execute($callable)
27
 * @method void expectTo($prediction)
28
 * @method void expect($prediction)
29
 * @method void amGoingTo($argumentation)
30
 * @method void am($role)
31
 * @method void lookForwardTo($achieveValue)
32
 * @method void comment($description)
33
 * @method void pause($vars = [])
34
 *
35
 * @SuppressWarnings(PHPMD)
36
 */
37
class OrderAmendmentsApiTester extends ApiEndToEndTester
38
{
39
    use _generated\OrderAmendmentsApiTesterActions;
40
41
    /**
42
     * @param \Generated\Shared\Transfer\CustomerTransfer $customerTransfer
43
     *
44
     * @return void
45
     */
46
    public function authorizeCustomerToGlue(CustomerTransfer $customerTransfer): void
47
    {
48
        $oauthResponseTransfer = $this->haveAuthorizationToGlue($customerTransfer);
49
        $this->amBearerAuthenticated($oauthResponseTransfer->getAccessToken());
50
    }
51
52
    /**
53
     * @param string $orderReference
54
     *
55
     * @return void
56
     */
57
    public function assertResponseContainsAmendmentOrderReference(string $orderReference): void
58
    {
59
        $attributes = $this->getDataFromResponseByJsonPath('$.data.attributes');
60
61
        $this->assertArrayHasKey('amendmentOrderReference', $attributes);
62
        $this->assertSame($orderReference, $attributes['amendmentOrderReference']);
63
    }
64
65
    /**
66
     * @param string $quoteName
67
     *
68
     * @return void
69
     */
70
    public function assertResponseContainsCorrectCartName(string $quoteName): void
71
    {
72
        $attributes = $this->getDataFromResponseByJsonPath('$.data.attributes');
73
74
        $this->assertArrayHasKey('name', $attributes);
75
        $this->assertSame($quoteName, $attributes['name']);
76
    }
77
78
    /**
79
     * @return string
80
     */
81
    public function getCartReorderUrl(): string
82
    {
83
        return $this->formatUrl('{cartReorderResource}?include=items', [
84
            'cartReorderResource' => CartReorderRestApiConfig::RESOURCE_CART_REORDER,
85
        ]);
86
    }
87
88
    /**
89
     * @param string $sku
90
     *
91
     * @return string
92
     */
93
    public function getConcreteProductPricesUrl(string $sku): string
94
    {
95
        return $this->formatUrl('concrete-products/{sku}/concrete-product-prices', ['sku' => $sku]);
96
    }
97
98
    /**
99
     * @param string $productOfferReference
100
     *
101
     * @return string
102
     */
103
    public function getProductOfferPricesUrl(string $productOfferReference): string
104
    {
105
        return $this->formatUrl('product-offers/{productOfferId}/product-offer-prices', ['productOfferId' => $productOfferReference]);
106
    }
107
108
    /**
109
     * @return \Generated\Shared\Transfer\StoreTransfer
110
     */
111
    public function getCurrentStore(): StoreTransfer
112
    {
113
        return $this->getLocator()->store()->facade()->getCurrentStore();
114
    }
115
116
    /**
117
     * @param int|null $unitPrice
118
     *
119
     * @return \Generated\Shared\Transfer\ProductConcreteTransfer
120
     */
121
    public function haveProductWithPriceAndStock(?int $unitPrice = 10000): ProductConcreteTransfer
122
    {
123
        $storeTransfer = $this->getLocator()->store()->facade()->getCurrentStore();
124
        $productConcreteTransfer = $this->haveFullProduct();
125
        $this->haveProductInStockForStore($storeTransfer, [
126
            StockProductTransfer::SKU => $productConcreteTransfer->getSku(),
127
            StockProductTransfer::IS_NEVER_OUT_OF_STOCK => 1,
128
        ]);
129
130
        $priceProductTransfer = $this->havePriceProduct([
131
            PriceProductTransfer::SKU_PRODUCT_ABSTRACT => $productConcreteTransfer->getAbstractSku(),
132
            PriceProductTransfer::SKU_PRODUCT => $productConcreteTransfer->getSku(),
133
            PriceProductTransfer::ID_PRODUCT => $productConcreteTransfer->getIdProductConcrete(),
134
            PriceProductTransfer::PRICE_TYPE_NAME => 'DEFAULT',
135
            PriceProductTransfer::MONEY_VALUE => [
136
                MoneyValueTransfer::NET_AMOUNT => $unitPrice,
137
                MoneyValueTransfer::GROSS_AMOUNT => $unitPrice,
138
            ],
139
        ]);
140
141
        $productConcreteTransfer->addPrice($priceProductTransfer);
142
143
        return $productConcreteTransfer;
144
    }
145
}
146