Skip to content

Commit

Permalink
ENGCOM-5043: Prevent Error When Getting Payment Method Before Setting m…
Browse files Browse the repository at this point in the history
  • Loading branch information
naydav authored May 8, 2019
2 parents 7a231da + 8a5e967 commit cec0a61
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ public function resolve(Field $field, $context, ResolveInfo $info, array $value
return [];
}

try {
$methodTitle = $payment->getMethodInstance()->getTitle();
} catch (LocalizedException $e) {
$methodTitle = '';
}

return [
'code' => $payment->getMethod(),
'title' => $payment->getMethodInstance()->getTitle(),
'code' => $payment->getMethod() ?? '',
'title' => $methodTitle,
'purchase_order_number' => $payment->getPoNumber(),
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ public function testGetSelectedPaymentMethod()
$this->assertEquals('checkmo', $response['cart']['selected_payment_method']['code']);
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_payment_methods.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/customer/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
*/
public function testGetSelectedPaymentMethodBeforeSet()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

$query = $this->getQuery($maskedQuoteId);
$response = $this->graphQlQuery($query, [], '', $this->getHeaderMap());

$this->assertArrayHasKey('cart', $response);
$this->assertArrayHasKey('selected_payment_method', $response['cart']);
$this->assertArrayHasKey('code', $response['cart']['selected_payment_method']);
$this->assertEquals('', $response['cart']['selected_payment_method']['code']);
}

/**
* @magentoApiDataFixture Magento/Customer/_files/customer.php
* @expectedException \Exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ public function testGetSelectedPaymentMethod()
$this->assertEquals('checkmo', $response['cart']['selected_payment_method']['code']);
}

/**
* @magentoApiDataFixture Magento/GraphQl/Catalog/_files/simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/guest/create_empty_cart.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/enable_offline_payment_methods.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/add_simple_product.php
* @magentoApiDataFixture Magento/GraphQl/Quote/_files/set_new_shipping_address.php
*/
public function testGetSelectedPaymentMethodBeforeSet()
{
$maskedQuoteId = $this->getMaskedQuoteIdByReservedOrderId->execute('test_quote');

$query = $this->getQuery($maskedQuoteId);
$response = $this->graphQlQuery($query);

$this->assertArrayHasKey('cart', $response);
$this->assertArrayHasKey('selected_payment_method', $response['cart']);
$this->assertArrayHasKey('code', $response['cart']['selected_payment_method']);
$this->assertEquals('', $response['cart']['selected_payment_method']['code']);
}

/**
* @expectedException \Exception
*/
Expand Down

0 comments on commit cec0a61

Please sign in to comment.