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

requestCheckoutDataIncludesShipmentMethodsRelationship()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 45
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
dl 0
loc 45
c 1
b 0
f 0
rs 9.456
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
namespace PyzTest\Glue\Checkout\RestApi;
9
10
use Codeception\Util\HttpCode;
11
use PyzTest\Glue\Checkout\CheckoutApiTester;
12
use PyzTest\Glue\Checkout\RestApi\Fixtures\CheckoutDataShipmentRelationshipsFixtures;
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 CheckoutDataRelationshipsCest
24
 * Add your own group annotations below this line
25
 */
26
class CheckoutDataRelationshipsCest
27
{
28
    /**
29
     * @var \PyzTest\Glue\Checkout\RestApi\Fixtures\CheckoutDataShipmentRelationshipsFixtures
30
     */
31
    protected CheckoutDataShipmentRelationshipsFixtures $checkoutDataShipmentRelationshipsFixtures;
32
33
    /**
34
     * @param \PyzTest\Glue\Checkout\CheckoutApiTester $I
35
     *
36
     * @return void
37
     */
38
    public function loadShipmentFixtures(CheckoutApiTester $I): void
39
    {
40
        /** @var \PyzTest\Glue\Checkout\RestApi\Fixtures\CheckoutDataShipmentRelationshipsFixtures $fixtures */
41
        $fixtures = $I->loadFixtures(CheckoutDataShipmentRelationshipsFixtures::class);
42
        $this->checkoutDataShipmentRelationshipsFixtures = $fixtures;
43
    }
44
45
    /**
46
     * @depends loadShipmentFixtures
47
     *
48
     * @param \PyzTest\Glue\Checkout\CheckoutApiTester $I
49
     *
50
     * @return void
51
     */
52
    public function requestCheckoutDataIncludesShipmentsRelationship(CheckoutApiTester $I): void
53
    {
54
        // Arrange
55
        $I->authorizeCustomerToGlue($this->checkoutDataShipmentRelationshipsFixtures->getCustomerTransfer());
56
57
        $url = $I->buildCheckoutDataUrl([
58
            ShipmentsRestApiConfig::RESOURCE_SHIPMENTS,
59
        ]);
60
        $requestPayload = [
61
            'data' => [
62
                'type' => CheckoutRestApiConfig::RESOURCE_CHECKOUT_DATA,
63
                'attributes' => [
64
                    'idCart' => $this->checkoutDataShipmentRelationshipsFixtures->getQuoteTransfer()->getUuid(),
65
                ],
66
            ],
67
        ];
68
69
        $shipmentMethodTransfer = $this->checkoutDataShipmentRelationshipsFixtures->getShipmentMethodTransfer();
70
71
        // Act
72
        $I->sendPOST($url, $requestPayload);
73
74
        // Assert
75
        $I->seeResponseCodeIs(HttpCode::OK);
76
        $I->seeResponseIsJson();
77
        $I->seeResponseMatchesOpenApiSchema();
78
79
        $I->amSure('The response contains included shipments')
80
            ->whenI()
81
            ->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

81
            ->/** @scrutinizer ignore-call */ seeIncludesContainResourceOfType(ShipmentsRestApiConfig::RESOURCE_SHIPMENTS);
Loading history...
82
83
        $jsonPath = sprintf('$..included[?(@.type == \'%s\')]', 'shipments');
84
        $shipments = $I->getDataFromResponseByJsonPath($jsonPath)[0];
85
86
        $I->amSure('The included shipments resource contains correct attributes')
87
            ->whenI()
88
            ->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

88
            ->/** @scrutinizer ignore-call */ assertSame(
Loading history...
89
                [$this->checkoutDataShipmentRelationshipsFixtures->getQuoteTransfer()->getItems()->offsetGet(0)->getGroupKey()],
90
                $shipments['attributes']['items'],
91
            );
92
        $I->amSure('The included shipments resource contains correct attributes')
93
            ->whenI()
94
            ->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

94
            ->/** @scrutinizer ignore-call */ assertArraySubset(
Loading history...
95
                [
96
                    'id' => $shipmentMethodTransfer->getIdShipmentMethod(),
97
                    'name' => $shipmentMethodTransfer->getName(),
98
                    'carrierName' => $shipmentMethodTransfer->getCarrierName(),
99
                ],
100
                $shipments['attributes']['selectedShipmentMethod'],
101
            );
102
    }
103
104
    /**
105
     * @depends loadShipmentFixtures
106
     *
107
     * @param \PyzTest\Glue\Checkout\CheckoutApiTester $I
108
     *
109
     * @return void
110
     */
111
    public function requestCheckoutDataIncludesShipmentMethodsRelationship(CheckoutApiTester $I): void
112
    {
113
        // Arrange
114
        $I->authorizeCustomerToGlue($this->checkoutDataShipmentRelationshipsFixtures->getCustomerTransfer());
115
116
        $url = $I->buildCheckoutDataUrl([
117
            ShipmentsRestApiConfig::RESOURCE_SHIPMENTS,
118
            ShipmentsRestApiConfig::RESOURCE_SHIPMENT_METHODS,
119
        ]);
120
        $requestPayload = [
121
            'data' => [
122
                'type' => CheckoutRestApiConfig::RESOURCE_CHECKOUT_DATA,
123
                'attributes' => [
124
                    'idCart' => $this->checkoutDataShipmentRelationshipsFixtures->getQuoteTransfer()->getUuid(),
125
                ],
126
            ],
127
        ];
128
129
        $shipmentMethodTransfer = $this->checkoutDataShipmentRelationshipsFixtures->getShipmentMethodTransfer();
130
131
        // Act
132
        $I->sendPOST($url, $requestPayload);
133
134
        // Assert
135
        $I->seeResponseCodeIs(HttpCode::OK);
136
        $I->seeResponseIsJson();
137
        $I->seeResponseMatchesOpenApiSchema();
138
139
        $I->amSure('The response contains included shipment methods')
140
            ->whenI()
141
            ->seeIncludesContainResourceOfType(ShipmentsRestApiConfig::RESOURCE_SHIPMENT_METHODS);
142
        $I->amSure('The response contains includes expected shipment-methods resource')
143
            ->whenI()
144
            ->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

144
            ->/** @scrutinizer ignore-call */ seeIncludesContainsResourceByTypeAndId(
Loading history...
145
                ShipmentsRestApiConfig::RESOURCE_SHIPMENT_METHODS,
146
                $shipmentMethodTransfer->getIdShipmentMethod(),
147
            );
148
        $I->amSure('The included shipment-methods resource contains correct attributes')
149
            ->whenI()
150
            ->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

150
            ->/** @scrutinizer ignore-call */ seeIncludedResourceByTypeAndIdContainsAttributes(
Loading history...
151
                ShipmentsRestApiConfig::RESOURCE_SHIPMENT_METHODS,
152
                $shipmentMethodTransfer->getIdShipmentMethodOrFail(),
153
                [
154
                    'name' => $shipmentMethodTransfer->getNameOrFail(),
155
                    'carrierName' => $shipmentMethodTransfer->getCarrierNameOrFail(),
156
                ],
157
            );
158
    }
159
}
160