Skip to content

Commit

Permalink
add_payment.feature behat tests
Browse files Browse the repository at this point in the history
2 tests are failing because of the possible bug:

it should not be allowed to add payments with negative amount?
And if it's added then total_sum should not be negative?
  • Loading branch information
tdavidsonas88 committed Nov 28, 2019
1 parent c2231d2 commit 234506c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -317,12 +317,12 @@ private function getCarrierIdFromMap(string $carrier)
}

/**
* @When I add payment to order with id :orderId with the following properties:
* @When I add payment to order id :orderId with the following properties:
*
* @param int $orderId
* @param TableNode $table
*/
public function iAddPaymentToOrderWithIdWithTheFollowingProperties(int $orderId, TableNode $table)
public function iAddPaymentToOrderIdTheFollowingProperties(int $orderId, TableNode $table)
{
/** @var array $hash */
$hash = $table->getHash();
Expand Down Expand Up @@ -383,12 +383,35 @@ public function iAddPaymentToOrderIdExceptionIsThrownWithTheFollowingProperties(
}

/**
* @Then if I query order with id :orderId payments I should get an Order with properties:
* @Then if I query order id :orderId payments I should get :numberOfPayments payments
*/
public function ifIQueryOrderIdPaymentsIShouldGetOrders(int $orderId, int $numberOfPayments)
{
/** @var OrderForViewing $orderForViewing */
$orderForViewing = $this->getQueryBus()->handle(new GetOrderForViewing($orderId));
/** @var OrderPaymentsForViewing $orderPaymentsForViewing */
$orderPaymentsForViewing = $orderForViewing->getPayments();
/** @var OrderPaymentForViewing[] $orderPaymentForViewingArray */
$orderPaymentForViewingArray = $orderPaymentsForViewing->getPayments();

$countOfOrderPaymentsFromDb = count($orderPaymentForViewingArray);
if (count($orderPaymentForViewingArray) !== $numberOfPayments) {
throw new RuntimeException(sprintf(
'Order "%s" number of payments "%s" is wrong , but "%s" was expected',
$orderId,
$countOfOrderPaymentsFromDb,
$numberOfPayments
));
}
}

/**
* @Then if I query order id :orderId payments I should get an Order with properties:
*
* @param int $orderId
* @param TableNode $table
*/
public function ifIQueryOrderWithIdPaymentsIShouldGetAnOrderWithProperties(int $orderId, TableNode $table)
public function ifIQueryOrderIdPaymentsIShouldGetAnOrderWithProperties(int $orderId, TableNode $table)
{
/** @var OrderForViewing $orderForViewing */
$orderForViewing = $this->getQueryBus()->handle(new GetOrderForViewing($orderId));
Expand All @@ -406,7 +429,7 @@ public function ifIQueryOrderWithIdPaymentsIShouldGetAnOrderWithProperties(int $

/** @var array $hash */
$hash = $table->getHash();
if (count($hash) != 1) {
if (count($hash) == 0) {
throw new RuntimeException('Payment details are invalid');
}
/** @var array $data */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,23 @@ Feature: Order payment from Back Office
Given there is existing order with id 1
# todo: invoice is needed to be created and id_invoice should be not just 0

Scenario: add order payment with negative amount to get exception Property Order->total_paid_real is not valid
When I add payment to order id 1 exception is thrown with the following properties:
| date | payment_method | transaction_id | id_currency | amount | id_invoice |
| 2019-11-26 13:56:22 | Payments by check | test!@#$%%^^&* OR 1=1 _ | 1 | -5.548 | 0 |
Then if I query order id 1 payments I should get 0 payments

Scenario: add order payment
When I add payment to order with id 1 with the following properties:
When I add payment to order id 1 with the following properties:
| date | payment_method | transaction_id | id_currency | amount | id_invoice |
| 2019-11-26 13:56:22 | Payments by check | test123 | 1 | 5.54 | 0 |
Then if I query order with id 1 payments I should get an Order with properties:
| 2019-11-26 13:56:23 | Payments by check | test123 | 1 | 6 | 0 |
Then if I query order id 1 payments I should get an Order with properties:
| date | payment_method | transaction_id | amount | id_invoice |
| 2019-11-26 13:56:22 | Payments by check | test123 | $5.54 | |
# todo: finish the tests below not to fail or fail with the reason
When I add payment to order id 1 exception is thrown with the following properties:
| 2019-11-26 13:56:23 | Payments by check | test123 | $6 | |
When I add payment to order id 1 with the following properties:
| date | payment_method | transaction_id | id_currency | amount | id_invoice |
| 2019-11-26 13:56:23 | Payments by check | test!@#$%%^^&* OR 1=1 _ | 1 | -5.548 | 0 |
Then if I query order with id 1 payments I should get an Order with properties:
| 2019-11-26 13:56:24 | Payments by check | test!@#$%%^^&* OR 1=1 _ | 1 | 100.00 | 0 |
Then if I query order id 1 payments I should get an Order with properties:
| date | payment_method | transaction_id | amount | id_invoice |
| 2019-11-26 13:56:22 | Payments by check | test123 | $5.54 | |
# When I add payment to order with id 1 with the following properties:
# | date | payment_method | transaction_id | id_currency | amount | id_invoice |
# | 2019-11-26 13:56:24 | Bank transfer | SELECT id, login FROM users | 1 | 0.00 | 0 |
# Then if I query order with id 1 payments I should get an Order with properties:
# | 2019-11-26 13:56:22 | Payments by check | test123 | $5.54 | |
# | 2019-11-26 13:56:23 | Payments by check | test!@#$%%^^&* OR 1=1 _ | -$5.548 | |
# | 2019-11-26 13:56:24 | Bank transfer | SELECT id, login FROM users | $0.00 | |
| 2019-11-26 13:56:23 | Payments by check | test123 | $6 | |
| 2019-11-26 13:56:22 | Payments by check | test!@#$%%^^&* OR 1=1 _ | 100.00 | |

0 comments on commit 234506c

Please sign in to comment.