summaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_merchant_get_order.c
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-26 13:47:16 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-26 13:47:16 -0400
commit60df7253dd77348b05d0b60bba4b12565afa26ed (patch)
tree382f5acd973b6205b3c2186b583a8265660e64b3 /src/testing/testing_api_cmd_merchant_get_order.c
parent057ac0fa95c29421b3868f43696023af3ec4cdd6 (diff)
downloadmerchant-60df7253dd77348b05d0b60bba4b12565afa26ed.tar.gz
merchant-60df7253dd77348b05d0b60bba4b12565afa26ed.tar.bz2
merchant-60df7253dd77348b05d0b60bba4b12565afa26ed.zip
deeper checks for merchant get order
Diffstat (limited to 'src/testing/testing_api_cmd_merchant_get_order.c')
-rw-r--r--src/testing/testing_api_cmd_merchant_get_order.c138
1 files changed, 137 insertions, 1 deletions
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,