From 60df7253dd77348b05d0b60bba4b12565afa26ed Mon Sep 17 00:00:00 2001 From: Jonathan Buchanan Date: Fri, 26 Jun 2020 13:47:16 -0400 Subject: deeper checks for merchant get order --- src/backend/taler-merchant-httpd_get-orders-ID.c | 2 +- src/include/taler_merchant_testing_lib.h | 7 +- src/testing/test_merchant_api.c | 8 ++ src/testing/testing_api_cmd_merchant_get_order.c | 138 ++++++++++++++++++++++- src/testing/testing_api_cmd_refund_order.c | 2 + 5 files changed, 154 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/backend/taler-merchant-httpd_get-orders-ID.c b/src/backend/taler-merchant-httpd_get-orders-ID.c index ca5a1a25..f0585eb9 100644 --- a/src/backend/taler-merchant-httpd_get-orders-ID.c +++ b/src/backend/taler-merchant-httpd_get-orders-ID.c @@ -897,7 +897,7 @@ TMH_get_orders_ID (const struct TMH_RequestHandler *rh, /* At this point, we know the contract was paid. Let's check for refunds. First, clear away refunds found from previous invocations. */ - rf_cleanup (); + rf_cleanup (god); GNUNET_assert (GNUNET_OK == TALER_amount_get_zero (TMH_currency, &god->refund_amount)); qs = TMH_db->lookup_refunds_detailed (TMH_db->cls, diff --git a/src/include/taler_merchant_testing_lib.h b/src/include/taler_merchant_testing_lib.h index 31ed45a1..980eb6ea 100644 --- a/src/include/taler_merchant_testing_lib.h +++ b/src/include/taler_merchant_testing_lib.h @@ -489,6 +489,10 @@ TALER_TESTING_cmd_wallet_get_order (const char *label, * @param paid whether the order has been paid for or not. * @param refunded whether the order has been refunded. * @param http_status expected HTTP response code for the request. + * @param ... NULL-terminated list of labels (const char *) of + * refunds (commands) we expect to be aggregated in the transfer + * (assuming @a http_code is #MHD_HTTP_OK). If @e refunded is false, + * this parameter is ignored. */ struct TALER_TESTING_Command TALER_TESTING_cmd_merchant_get_order (const char *label, @@ -496,7 +500,8 @@ TALER_TESTING_cmd_merchant_get_order (const char *label, const char *order_reference, bool paid, bool refunded, - unsigned int http_status); + unsigned int http_status, + ...); /** diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c index b1b518d8..3dd65c60 100644 --- a/src/testing/test_merchant_api.c +++ b/src/testing/test_merchant_api.c @@ -570,6 +570,14 @@ run (void *cls, MHD_HTTP_OK, "refund-increase-1r", NULL), + TALER_TESTING_cmd_merchant_get_order ("get-order-merchant-1r", + merchant_url, + "create-proposal-1r", + true, + true, + MHD_HTTP_OK, + "refund-increase-1r", + NULL), #if 0 TALER_TESTING_cmd_poll_payment_conclude ("poll-payment-refund-conclude-1", MHD_HTTP_OK, diff --git a/src/testing/testing_api_cmd_merchant_get_order.c b/src/testing/testing_api_cmd_merchant_get_order.c index 739e4efa..f3070392 100644 --- a/src/testing/testing_api_cmd_merchant_get_order.c +++ b/src/testing/testing_api_cmd_merchant_get_order.c @@ -67,6 +67,16 @@ struct MerchantGetOrderState * Whether the order was refunded or not. */ bool refunded; + + /** + * A NULL-terminated list of refunds associated with this order. + */ + const char **refunds; + + /** + * The length of @e refunds. + */ + unsigned int refunds_length; }; @@ -114,6 +124,113 @@ merchant_get_order_cb ( TALER_TESTING_interpreter_fail (gos->is); return; } + if (gos->paid) + { + const struct TALER_TESTING_Command *order_cmd; + + order_cmd = TALER_TESTING_interpreter_lookup_command ( + gos->is, + gos->order_reference); + + { + const json_t *expected_contract_terms; + + if (GNUNET_OK != + TALER_TESTING_get_trait_contract_terms (order_cmd, + 0, + &expected_contract_terms)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch order contract terms\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + if (1 != json_equal (expected_contract_terms, + osr->details.paid.contract_terms)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Order contract terms do not match\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + } + + if (gos->refunded != osr->details.paid.refunded) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Order refunded does not match\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + if (gos->refunds_length != osr->details.paid.refunds_len) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Number of refunds found does not match\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + for (unsigned int i = 0; i < gos->refunds_length; ++i) + { + const struct TALER_TESTING_Command *refund_cmd; + + refund_cmd = TALER_TESTING_interpreter_lookup_command ( + gos->is, + gos->refunds[i]); + { + const char *expected_amount_str; + struct TALER_Amount expected_amount; + struct TALER_Amount *amount_found = + &osr->details.paid.refunds[i].refund_amount; + + if (GNUNET_OK != + TALER_TESTING_get_trait_string (refund_cmd, + 0, + &expected_amount_str)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch refund amount\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (expected_amount_str, + &expected_amount)); + if ((GNUNET_OK != + TALER_amount_cmp_currency (&expected_amount, + amount_found)) || + (0 != TALER_amount_cmp (&expected_amount, + amount_found))) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Refund amounts do not match\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + } + { + const char *expected_reason; + + if (GNUNET_OK != + TALER_TESTING_get_trait_string (refund_cmd, + 1, + &expected_reason)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not fetch reason\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + if (0 != strcmp (expected_reason, + osr->details.paid.refunds[i].reason)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Refund reason does not match\n"); + TALER_TESTING_interpreter_fail (gos->is); + return; + } + } + } + } break; default: GNUNET_log (GNUNET_ERROR_TYPE_WARNING, @@ -200,6 +317,10 @@ merchant_get_order_cleanup (void *cls, * @param paid whether the order has been paid for or not. * @param refunded whether the order has been refunded. * @param http_status expected HTTP response code for the request. + * @param ... NULL-terminated list of labels (const char *) of + * refunds (commands) we expect to be aggregated in the transfer + * (assuming @a http_code is #MHD_HTTP_OK). If @e refunded is false, + * this parameter is ignored. */ struct TALER_TESTING_Command TALER_TESTING_cmd_merchant_get_order (const char *label, @@ -207,7 +328,8 @@ TALER_TESTING_cmd_merchant_get_order (const char *label, const char *order_reference, bool paid, bool refunded, - unsigned int http_status) + unsigned int http_status, + ...) { struct MerchantGetOrderState *gos; @@ -217,6 +339,20 @@ TALER_TESTING_cmd_merchant_get_order (const char *label, gos->paid = paid; gos->refunded = refunded; gos->http_status = http_status; + if (refunded) + { + const char *clabel; + va_list ap; + + va_start (ap, http_status); + while (NULL != (clabel = va_arg (ap, const char *))) + { + GNUNET_array_append (gos->refunds, + gos->refunds_length, + clabel); + } + va_end (ap); + } { struct TALER_TESTING_Command cmd = { .cls = gos, diff --git a/src/testing/testing_api_cmd_refund_order.c b/src/testing/testing_api_cmd_refund_order.c index 5bc3717b..ab6f78ac 100644 --- a/src/testing/testing_api_cmd_refund_order.c +++ b/src/testing/testing_api_cmd_refund_order.c @@ -150,6 +150,8 @@ refund_increase_traits (void *cls, struct TALER_TESTING_Trait traits[] = { TALER_TESTING_make_trait_string (0, ris->refund_amount), + TALER_TESTING_make_trait_string (1, + ris->reason), TALER_TESTING_trait_end () }; -- cgit v1.2.3