Skip to content

Commit 81a290e

Browse files
committed
MC-16922: Create an end-to-end test SetPaymentMethodOnCart for the authorize.net payment method
- review comments
1 parent 936830f commit 81a290e

File tree

5 files changed

+57
-17
lines changed

5 files changed

+57
-17
lines changed

dev/tests/integration/testsuite/Magento/AuthorizenetGraphQl/Model/Resolver/Customer/PlaceOrderWithAuthorizeNetTest.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,6 @@ class PlaceOrderWithAuthorizeNetTest extends TestCase
4141
/** @var GetMaskedQuoteIdByReservedOrderId */
4242
private $getMaskedQuoteIdByReservedOrderId;
4343

44-
/** @var GraphQl */
45-
private $graphql;
46-
4744
/** @var SerializerInterface */
4845
private $jsonSerializer;
4946

@@ -65,7 +62,6 @@ class PlaceOrderWithAuthorizeNetTest extends TestCase
6562
protected function setUp() : void
6663
{
6764
$this->objectManager = Bootstrap::getObjectManager();
68-
$this->graphql = $this->objectManager->get(\Magento\GraphQl\Controller\GraphQl::class);
6965
$this->jsonSerializer = $this->objectManager->get(SerializerInterface::class);
7066
$this->request = $this->objectManager->get(Http::class);
7167
$this->getMaskedQuoteIdByReservedOrderId = $this->objectManager->get(GetMaskedQuoteIdByReservedOrderId::class);
@@ -92,7 +88,7 @@ protected function setUp() : void
9288
* @magentoConfigFixture default_store payment/authorizenet_acceptjs/trans_signature_key abc
9389
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
9490
* @magentoDataFixture Magento/Customer/_files/customer.php
95-
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product_authorizenet.php
91+
* @magentoDataFixture Magento/AuthorizenetGraphQl/_files/simple_product_authorizenet.php
9692
* @magentoDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
9793
* @magentoDataFixture Magento/AuthorizenetGraphQl/_files/set_new_shipping_address_authorizenet.php
9894
* @magentoDataFixture Magento/AuthorizenetGraphQl/_files/set_new_billing_address_authorizenet.php
@@ -140,13 +136,11 @@ public function testDispatchToPlaceOrderWithRegisteredCustomer(): void
140136
$this->request->setContent($this->jsonSerializer->serialize($postData));
141137
$customerToken = $this->customerTokenService->createCustomerAccessToken('[email protected]', 'password');
142138
$bearerCustomerToken = 'Bearer ' . $customerToken;
143-
$contentType ='application/json';
144139
$webApiRequest = $this->objectManager->get(Request::class);
145-
$webApiRequest->getHeaders()->addHeaderLine('Content-Type', $contentType)
146-
->addHeaderLine('Accept', $contentType)
140+
$webApiRequest->getHeaders()->addHeaderLine('Content-Type', 'application/json')
141+
->addHeaderLine('Accept', 'application/json')
147142
->addHeaderLine('Authorization', $bearerCustomerToken);
148143
$this->request->setHeaders($webApiRequest->getHeaders());
149-
150144
$graphql = $this->objectManager->get(\Magento\GraphQl\Controller\GraphQl::class);
151145

152146
$expectedRequest = include __DIR__ . '/../../../_files/request_authorize_customer.php';
@@ -160,7 +154,7 @@ public function testDispatchToPlaceOrderWithRegisteredCustomer(): void
160154
$response = $graphql->dispatch($this->request);
161155
$responseData = $this->jsonSerializer->unserialize($response->getContent());
162156

163-
$this->assertArrayNotHasKey('errors', $responseData, 'Response has errors');
157+
$this->assertArrayNotHasKey('errors', $responseData, 'Response has errors');
164158
$this->assertTrue(
165159
isset($responseData['data']['setPaymentMethodOnCart']['cart']['selected_payment_method']['code'])
166160
);
@@ -182,7 +176,6 @@ public function testDispatchToPlaceOrderWithRegisteredCustomer(): void
182176
protected function tearDown()
183177
{
184178
$this->objectManager->removeSharedInstance(ZendClientFactory::class);
185-
include __DIR__ . '/../../../../../Magento/Customer/_files/customer_rollback.php';
186179
parent::tearDown();
187180
}
188181
}

dev/tests/integration/testsuite/Magento/AuthorizenetGraphQl/Model/Resolver/Customer/SetAuthorizeNetPaymentMethodOnCartTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ class SetAuthorizenetPaymentMethodOnCartTest extends TestCase
3838
/** @var CustomerTokenServiceInterface */
3939
private $customerTokenService;
4040

41-
/**
42-
* @var \Magento\Framework\App\Cache */
43-
private $appCache;
44-
4541
/** @var Http */
4642
private $request;
4743

dev/tests/integration/testsuite/Magento/AuthorizenetGraphQl/Model/Resolver/Guest/PlaceOrderWithAuthorizeNetTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected function setUp() : void
8585
* @magentoConfigFixture default_store payment/authorizenet_acceptjs/trans_key somepassword
8686
* @magentoConfigFixture default_store payment/authorizenet_acceptjs/trans_signature_key abc
8787
* @magentoDataFixture Magento/Sales/_files/default_rollback.php
88-
* @magentoDataFixture Magento/GraphQl/Catalog/_files/simple_product_authorizenet.php
88+
* @magentoDataFixture Magento/AuthorizenetGraphQl/_files/simple_product_authorizenet.php
8989
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
9090
* @magentoDataFixture Magento/GraphQl/Quote/_files/guest/set_guest_email.php
9191
* @magentoDataFixture Magento/AuthorizenetGraphQl/_files/set_new_shipping_address_authorizenet.php
@@ -169,7 +169,6 @@ public function testDispatchToPlaceAnOrderWithAuthorizenet(): void
169169
protected function tearDown()
170170
{
171171
$this->objectManager->removeSharedInstance(ZendClientFactory::class);
172-
include __DIR__ . '/../../../../../Magento/Customer/_files/not_logged_in_customer_rollback.php';
173172
parent::tearDown();
174173
}
175174
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Catalog\Api\Data\ProductInterfaceFactory;
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
12+
use Magento\Catalog\Model\Product\Type;
13+
use Magento\Catalog\Model\Product\Visibility;
14+
use Magento\Framework\Api\DataObjectHelper;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
17+
$objectManager = Bootstrap::getObjectManager();
18+
/** @var ProductInterfaceFactory $productFactory */
19+
$productFactory = $objectManager->get(ProductInterfaceFactory::class);
20+
/** @var DataObjectHelper $dataObjectHelper */
21+
$dataObjectHelper = Bootstrap::getObjectManager()->get(DataObjectHelper::class);
22+
/** @var ProductRepositoryInterface $productRepository */
23+
$productRepository = $objectManager->get(ProductRepositoryInterface::class);
24+
25+
$product = $productFactory->create();
26+
$productData = [
27+
ProductInterface::TYPE_ID => Type::TYPE_SIMPLE,
28+
ProductInterface::ATTRIBUTE_SET_ID => 4,
29+
ProductInterface::SKU => 'simple_product',
30+
ProductInterface::NAME => 'Simple Product',
31+
ProductInterface::PRICE => 20,
32+
ProductInterface::VISIBILITY => Visibility::VISIBILITY_BOTH,
33+
ProductInterface::STATUS => Status::STATUS_ENABLED,
34+
];
35+
$dataObjectHelper->populateWithArray($product, $productData, ProductInterface::class);
36+
/** Out of interface */
37+
$product
38+
->setWebsiteIds([1])
39+
->setStockData([
40+
'qty' => 85.5,
41+
'is_in_stock' => true,
42+
'manage_stock' => true,
43+
'is_qty_decimal' => true
44+
]);
45+
$productRepository->save($product);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
require __DIR__ . '/../../GraphQl/Catalog/_files/simple_product_rollback.php';

0 commit comments

Comments
 (0)