Passed
Pull Request — master (#365)
by Dmitry
21:01
created

GuestCheckoutDataRelationshipsCest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 144
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 71
dl 0
loc 144
c 1
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A requestCheckoutDataIncludesShipmentsRelationship() 0 55 1
A requestCheckoutDataIncludesShipmentMethodsRelationship() 0 48 1
A loadShipmentFixtures() 0 5 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
namespace PyzTest\Glue\Checkout\RestApi;
9
10
use Codeception\Util\HttpCode;
11
use PyzTest\Glue\Checkout\CheckoutApiTester;
12
use PyzTest\Glue\Checkout\RestApi\Fixtures\GuestCheckoutDataShipmentRelationshipsFixtures;
13
use Spryker\Glue\CheckoutRestApi\CheckoutRestApiConfig;
14
use Spryker\Glue\ShipmentsRestApi\ShipmentsRestApiConfig;
15
16
/**
17
 * Auto-generated group annotations
18
 *
19
 * @group PyzTest
20
 * @group Glue
21
 * @group Checkout
22
 * @group RestApi
23
 * @group GuestCheckoutDataRelationshipsCest
24
 * Add your own group annotations below this line
25
 */
26
class GuestCheckoutDataRelationshipsCest
27
{
28
    /**
29
     * @var string
30
     */
31
    protected const HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID = 'X-Anonymous-Customer-Unique-Id';
32
33
    /**
34
     * @var \PyzTest\Glue\Checkout\RestApi\Fixtures\GuestCheckoutDataShipmentRelationshipsFixtures
35
     */
36
    protected GuestCheckoutDataShipmentRelationshipsFixtures $guestCheckoutDataShipmentRelationshipsFixtures;
37
38
    /**
39
     * @param \PyzTest\Glue\Checkout\CheckoutApiTester $I
40
     *
41
     * @return void
42
     */
43
    public function loadShipmentFixtures(CheckoutApiTester $I): void
44
    {
45
        /** @var \PyzTest\Glue\Checkout\RestApi\Fixtures\GuestCheckoutDataShipmentRelationshipsFixtures $fixtures */
46
        $fixtures = $I->loadFixtures(GuestCheckoutDataShipmentRelationshipsFixtures::class);
47
        $this->guestCheckoutDataShipmentRelationshipsFixtures = $fixtures;
48
    }
49
50
    /**
51
     * @depends loadShipmentFixtures
52
     *
53
     * @param \PyzTest\Glue\Checkout\CheckoutApiTester $I
54
     *
55
     * @return void
56
     */
57
    public function requestCheckoutDataIncludesShipmentsRelationship(CheckoutApiTester $I): void
58
    {
59
        // Arrange
60
        $I->haveHttpHeader(
61
            static::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
62
            $this->guestCheckoutDataShipmentRelationshipsFixtures->getGuestCustomerReference(),
63
        );
64
65
        $url = $I->buildCheckoutDataUrl([
66
            ShipmentsRestApiConfig::RESOURCE_SHIPMENTS,
67
        ]);
68
        $requestPayload = [
69
            'data' => [
70
                'type' => CheckoutRestApiConfig::RESOURCE_CHECKOUT_DATA,
71
                'attributes' => [
72
                    'idCart' => $this->guestCheckoutDataShipmentRelationshipsFixtures->getGuestQuoteTransfer()->getUuid(),
73
                ],
74
            ],
75
        ];
76
77
        $shipmentMethodTransfer = $this->guestCheckoutDataShipmentRelationshipsFixtures->getShipmentMethodTransfer();
78
79
        // Act
80
        $I->sendPOST($url, $requestPayload);
81
82
        // Assert
83
        $I->seeResponseCodeIs(HttpCode::OK);
84
        $I->seeResponseIsJson();
85
        $I->seeResponseMatchesOpenApiSchema();
86
87
        $I->amSure('The response contains included shipments')
88
            ->whenI()
89
            ->seeIncludesContainResourceOfType(ShipmentsRestApiConfig::RESOURCE_SHIPMENTS);
0 ignored issues
show
Bug introduced by
It seems like seeIncludesContainResourceOfType() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

89
            ->/** @scrutinizer ignore-call */ seeIncludesContainResourceOfType(ShipmentsRestApiConfig::RESOURCE_SHIPMENTS);
Loading history...
90
91
        $jsonPath = sprintf('$..included[?(@.type == \'%s\')]', 'shipments');
92
        $shipments = $I->getDataFromResponseByJsonPath($jsonPath)[0];
93
94
        $I->amSure('The response contains includes expected shipments resource')
95
            ->whenI()
96
            ->assertNotNull($shipments);
0 ignored issues
show
Bug introduced by
It seems like assertNotNull() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

96
            ->/** @scrutinizer ignore-call */ assertNotNull($shipments);
Loading history...
97
        $I->amSure('The included shipments resource contains correct attributes')
98
            ->whenI()
99
            ->assertSame(
0 ignored issues
show
Bug introduced by
It seems like assertSame() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

99
            ->/** @scrutinizer ignore-call */ assertSame(
Loading history...
100
                [$this->guestCheckoutDataShipmentRelationshipsFixtures->getGuestQuoteTransfer()->getItems()->offsetGet(0)->getGroupKey()],
101
                $shipments['attributes']['items'],
102
            );
103
        $I->amSure('The included shipments resource contains correct attributes')
104
            ->whenI()
105
            ->assertArraySubset(
0 ignored issues
show
Bug introduced by
It seems like assertArraySubset() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

105
            ->/** @scrutinizer ignore-call */ assertArraySubset(
Loading history...
106
                [
107
                    'id' => $shipmentMethodTransfer->getIdShipmentMethod(),
108
                    'name' => $shipmentMethodTransfer->getName(),
109
                    'carrierName' => $shipmentMethodTransfer->getCarrierName(),
110
                ],
111
                $shipments['attributes']['selectedShipmentMethod'],
112
            );
113
    }
114
115
    /**
116
     * @depends loadShipmentFixtures
117
     *
118
     * @param \PyzTest\Glue\Checkout\CheckoutApiTester $I
119
     *
120
     * @return void
121
     */
122
    public function requestCheckoutDataIncludesShipmentMethodsRelationship(CheckoutApiTester $I): void
123
    {
124
        // Arrange
125
        $I->haveHttpHeader(
126
            static::HEADER_ANONYMOUS_CUSTOMER_UNIQUE_ID,
127
            $this->guestCheckoutDataShipmentRelationshipsFixtures->getGuestCustomerReference(),
128
        );
129
130
        $url = $I->buildCheckoutDataUrl([
131
            ShipmentsRestApiConfig::RESOURCE_SHIPMENTS,
132
            ShipmentsRestApiConfig::RESOURCE_SHIPMENT_METHODS,
133
        ]);
134
        $requestPayload = [
135
            'data' => [
136
                'type' => CheckoutRestApiConfig::RESOURCE_CHECKOUT_DATA,
137
                'attributes' => [
138
                    'idCart' => $this->guestCheckoutDataShipmentRelationshipsFixtures->getGuestQuoteTransfer()->getUuid(),
139
                ],
140
            ],
141
        ];
142
143
        $shipmentMethodTransfer = $this->guestCheckoutDataShipmentRelationshipsFixtures->getShipmentMethodTransfer();
144
145
        // Act
146
        $I->sendPOST($url, $requestPayload);
147
148
        // Assert
149
        $I->seeResponseCodeIs(HttpCode::OK);
150
        $I->seeResponseIsJson();
151
        $I->seeResponseMatchesOpenApiSchema();
152
153
        $I->amSure('The response contains included shipment methods')
154
            ->whenI()
155
            ->seeIncludesContainResourceOfType(ShipmentsRestApiConfig::RESOURCE_SHIPMENT_METHODS);
156
        $I->amSure('The response contains includes expected shipment-methods resource')
157
            ->whenI()
158
            ->seeIncludesContainsResourceByTypeAndId(
0 ignored issues
show
Bug introduced by
It seems like seeIncludesContainsResourceByTypeAndId() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

158
            ->/** @scrutinizer ignore-call */ seeIncludesContainsResourceByTypeAndId(
Loading history...
159
                ShipmentsRestApiConfig::RESOURCE_SHIPMENT_METHODS,
160
                $shipmentMethodTransfer->getIdShipmentMethod(),
161
            );
162
        $I->amSure('The included shipment-methods resource contains correct attributes')
163
            ->whenI()
164
            ->seeIncludedResourceByTypeAndIdContainsAttributes(
0 ignored issues
show
Bug introduced by
It seems like seeIncludedResourceByTypeAndIdContainsAttributes() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

164
            ->/** @scrutinizer ignore-call */ seeIncludedResourceByTypeAndIdContainsAttributes(
Loading history...
165
                ShipmentsRestApiConfig::RESOURCE_SHIPMENT_METHODS,
166
                $shipmentMethodTransfer->getIdShipmentMethodOrFail(),
167
                [
168
                    'name' => $shipmentMethodTransfer->getNameOrFail(),
169
                    'carrierName' => $shipmentMethodTransfer->getCarrierNameOrFail(),
170
                ],
171
            );
172
    }
173
}
174