CompanyBusinessUnitAddressCheckoutDataRestApiCest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 54
dl 0
loc 121
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A loadFixtures() 0 4 1
A requestCheckoutDataReturnsCompanyBusinessUnitAddressesInIncludes() 0 30 1
A requestCheckoutDataReturnsShipmentsWithMappedCompanyBusinessUnitAddressId() 0 37 1
A requestCheckoutDataShouldAcceptCompanyBusinessUnitAddressForBillingAddress() 0 23 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\Checkout\RestApi;
11
12
use Codeception\Util\HttpCode;
13
use PyzTest\Glue\Checkout\CheckoutApiTester;
14
use PyzTest\Glue\Checkout\RestApi\Fixtures\CompanyBusinessUnitAddressCheckoutDataRestApiFixtures;
15
use Spryker\Glue\CheckoutRestApi\CheckoutRestApiConfig;
16
17
/**
18
 * Auto-generated group annotations
19
 *
20
 * @group PyzTest
21
 * @group Glue
22
 * @group Checkout
23
 * @group RestApi
24
 * @group CompanyBusinessUnitAddressCheckoutDataRestApiCest
25
 * Add your own group annotations below this line
26
 * @group EndToEnd
27
 */
28
class CompanyBusinessUnitAddressCheckoutDataRestApiCest
29
{
30
    protected CompanyBusinessUnitAddressCheckoutDataRestApiFixtures $fixtures;
31
32
    public function loadFixtures(CheckoutApiTester $I): void
33
    {
34
        $fixtures = $I->loadFixtures(CompanyBusinessUnitAddressCheckoutDataRestApiFixtures::class);
35
        $this->fixtures = $fixtures;
36
    }
37
38
    /**
39
     * @depends loadFixtures
40
     *
41
     * @param \PyzTest\Glue\Checkout\CheckoutApiTester $I
42
     */
43
    public function requestCheckoutDataReturnsCompanyBusinessUnitAddressesInIncludes(CheckoutApiTester $I): void
44
    {
45
        // Arrange
46
        $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer());
47
        $quoteTransfer = $this->fixtures->getQuoteTransfer();
48
49
        $requestPayload = [
50
            'data' => [
51
                'type' => CheckoutRestApiConfig::RESOURCE_CHECKOUT_DATA,
52
                'attributes' => [
53
                    'idCart' => $quoteTransfer->getUuid(),
54
                ],
55
            ],
56
        ];
57
58
        // Act
59
        $I->sendPOST($I->buildCheckoutDataUrl(['company-business-unit-addresses']), $requestPayload);
60
61
        // Assert
62
        $I->seeResponseCodeIs(HttpCode::OK);
63
        $jsonPath = sprintf('$..included[?(@.type == \'%s\')]', 'company-business-unit-addresses');
64
        $companyBusinessUnitAddresses = $I->getDataFromResponseByJsonPath($jsonPath)[0];
65
66
        $I->amSure('The response contains includes expected company-business-unit-addresses resource')
67
            ->whenI()
68
            ->assertNotNull($companyBusinessUnitAddresses);
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

68
            ->/** @scrutinizer ignore-call */ assertNotNull($companyBusinessUnitAddresses);
Loading history...
69
70
        $I->assertSame(
71
            $this->fixtures->getCompanyUnitAddressTransfer()->getUuid(),
72
            $companyBusinessUnitAddresses['id'],
73
        );
74
    }
75
76
    /**
77
     * @depends loadFixtures
78
     *
79
     * @param \PyzTest\Glue\Checkout\CheckoutApiTester $I
80
     */
81
    public function requestCheckoutDataReturnsShipmentsWithMappedCompanyBusinessUnitAddressId(CheckoutApiTester $I): void
82
    {
83
        // Arrange
84
        $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer());
85
        $quoteTransfer = $this->fixtures->getQuoteTransfer();
86
87
        $requestPayload = [
88
            'data' => [
89
                'type' => CheckoutRestApiConfig::RESOURCE_CHECKOUT_DATA,
90
                'attributes' => [
91
                    'customer' =>
92
                        array_merge(
93
                            $this->fixtures->getCustomerTransfer()->toArray(),
94
                            ['idCompanyUser' => $this->fixtures->getCompanyUserTransfer()->getIdCompanyUser()],
95
                        ),
96
                    'idCart' => $quoteTransfer->getUuid(),
97
                    'shipments' => [
98
                        $I->getSplitShipmentRequestPayloadWithCompanyBusinessUnitAddress(
99
                            $quoteTransfer->getItems()->offsetGet(0),
100
                            $this->fixtures->getCompanyUnitAddressTransfer(),
101
                        ),
102
                    ],
103
                ],
104
            ],
105
        ];
106
107
        // Act
108
        $I->sendPOST($I->buildCheckoutDataUrl(['shipments']), $requestPayload);
109
110
        // Assert
111
        $I->seeResponseCodeIs(HttpCode::OK);
112
        $jsonPath = sprintf('$..included[?(@.type == \'%s\')]', 'shipments');
113
        $shipments = $I->getDataFromResponseByJsonPath($jsonPath)[0];
114
115
        $I->assertSame(
116
            $this->fixtures->getCompanyUnitAddressTransfer()->getUuid(),
117
            $shipments['attributes']['shippingAddress']['idCompanyBusinessUnitAddress'],
118
        );
119
    }
120
121
    /**
122
     * @depends loadFixtures
123
     *
124
     * @param \PyzTest\Glue\Checkout\CheckoutApiTester $I
125
     */
126
    public function requestCheckoutDataShouldAcceptCompanyBusinessUnitAddressForBillingAddress(CheckoutApiTester $I): void
127
    {
128
        // Arrange
129
        $I->authorizeCustomerToGlue($this->fixtures->getCustomerTransfer());
130
        $quoteTransfer = $this->fixtures->getQuoteTransfer();
131
132
        $requestPayload = [
133
            'data' => [
134
                'type' => CheckoutRestApiConfig::RESOURCE_CHECKOUT_DATA,
135
                'attributes' => [
136
                    'idCart' => $quoteTransfer->getUuid(),
137
                    'billingAddress' => [
138
                        'idCompanyBusinessUnitAddress' => $this->fixtures->getCompanyUnitAddressTransfer()->getUuid(),
139
                    ],
140
                ],
141
            ],
142
        ];
143
144
        // Act
145
        $I->sendPOST($I->buildCheckoutDataUrl(), $requestPayload);
146
147
        // Assert
148
        $I->seeResponseCodeIs(HttpCode::OK);
149
    }
150
}
151