From a84dbc0e60adbc27f4f98a024c469dd51df8f817 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 24 Feb 2024 13:13:31 +0100 Subject: add (working) test for repurchase detection --- src/testing/testing_api_cmd_merchant_get_order.c | 127 ++++++++++++++++++----- 1 file changed, 99 insertions(+), 28 deletions(-) (limited to 'src/testing/testing_api_cmd_merchant_get_order.c') diff --git a/src/testing/testing_api_cmd_merchant_get_order.c b/src/testing/testing_api_cmd_merchant_get_order.c index f30c43ad..1b235c93 100644 --- a/src/testing/testing_api_cmd_merchant_get_order.c +++ b/src/testing/testing_api_cmd_merchant_get_order.c @@ -93,6 +93,23 @@ struct MerchantGetOrderState */ unsigned int forgets_length; + /** + * Set to a session ID, if we should pass one as part + * of the request. + */ + const char *session_id; + + /** + * Set if we expect to be referred to another equivalent order which was + * already paid by the wallet under this @e session_id. + */ + const char *repurchase_order_ref; + + /** + * True if we should pass the 'allow_refunded_for_repurchase' flag. + */ + bool allow_refunded_for_repurchase; + /** * Whether the order was refunded or not. */ @@ -413,6 +430,31 @@ merchant_get_order_cb ( const char *order_id; const struct TALER_ClaimTokenP *claim_token; + if (NULL != gos->repurchase_order_ref) + { + const struct TALER_TESTING_Command *rep_cmd; + const char *rep_id; + const char *ri; + + rep_cmd = TALER_TESTING_interpreter_lookup_command ( + gos->is, + gos->repurchase_order_ref); + if (GNUNET_OK != + TALER_TESTING_get_trait_order_id (rep_cmd, + &rep_id)) + { + TALER_TESTING_FAIL (gos->is); + } + ri = osr->details.ok.details.unpaid.already_paid_order_id; + if ( (NULL == ri) || + (0 != + strcmp (ri, + rep_id)) ) + { + TALER_TESTING_FAIL (gos->is); + } + } + if (GNUNET_OK != TALER_MERCHANT_parse_pay_uri ( osr->details.ok.details.unpaid.taler_pay_uri, @@ -535,7 +577,7 @@ merchant_get_order_run (void *cls, TALER_TESTING_interpreter_get_context (is), gos->merchant_url, order_id, - NULL, + gos->session_id, GNUNET_TIME_UNIT_ZERO, &merchant_get_order_cb, gos); @@ -574,13 +616,14 @@ merchant_get_order_cleanup (void *cls, struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_get_order (const char *label, - const char *merchant_url, - const char *order_reference, - enum TALER_MERCHANT_OrderStatusCode osc, - bool refunded, - unsigned int http_status, - ...) +TALER_TESTING_cmd_merchant_get_order ( + const char *label, + const char *merchant_url, + const char *order_reference, + enum TALER_MERCHANT_OrderStatusCode osc, + bool refunded, + unsigned int http_status, + ...) { struct MerchantGetOrderState *gos; @@ -618,16 +661,17 @@ TALER_TESTING_cmd_merchant_get_order (const char *label, struct TALER_TESTING_Command -TALER_TESTING_cmd_merchant_get_order2 (const char *label, - const char *merchant_url, - const char *order_reference, - enum TALER_MERCHANT_OrderStatusCode osc, - bool wired, - const char **transfers, - bool refunded, - const char **refunds, - const char **forgets, - unsigned int http_status) +TALER_TESTING_cmd_merchant_get_order2 ( + const char *label, + const char *merchant_url, + const char *order_reference, + enum TALER_MERCHANT_OrderStatusCode osc, + bool wired, + const char **transfers, + bool refunded, + const char **refunds, + const char **forgets, + unsigned int http_status) { struct MerchantGetOrderState *gos; @@ -678,6 +722,38 @@ TALER_TESTING_cmd_merchant_get_order2 (const char *label, } +struct TALER_TESTING_Command +TALER_TESTING_cmd_merchant_get_order3 ( + const char *label, + const char *merchant_url, + const char *order_reference, + enum TALER_MERCHANT_OrderStatusCode osc, + const char *session_id, + const char *repurchase_order_ref, + unsigned int expected_http_status) +{ + struct MerchantGetOrderState *gos; + + gos = GNUNET_new (struct MerchantGetOrderState); + gos->merchant_url = merchant_url; + gos->order_reference = order_reference; + gos->osc = osc; + gos->session_id = session_id; + gos->repurchase_order_ref = repurchase_order_ref; + gos->http_status = expected_http_status; + { + struct TALER_TESTING_Command cmd = { + .cls = gos, + .label = label, + .run = &merchant_get_order_run, + .cleanup = &merchant_get_order_cleanup + }; + + return cmd; + } +} + + struct MerchantPollOrderConcludeState { /** @@ -892,14 +968,12 @@ merchant_poll_order_start_cleanup (void *cls, } -/** - * Start a long poll for GET /private/orders/$ORDER_ID. - */ struct TALER_TESTING_Command -TALER_TESTING_cmd_poll_order_start (const char *label, - const char *merchant_url, - const char *order_id, - struct GNUNET_TIME_Relative timeout) +TALER_TESTING_cmd_poll_order_start ( + const char *label, + const char *merchant_url, + const char *order_id, + struct GNUNET_TIME_Relative timeout) { struct MerchantPollOrderStartState *pos; @@ -987,9 +1061,6 @@ merchant_poll_order_conclude_cleanup (void *cls, } -/** - * Complete a long poll for GET /private/orders/$ORDER_ID. - */ struct TALER_TESTING_Command TALER_TESTING_cmd_poll_order_conclude (const char *label, unsigned int http_status, -- cgit v1.2.3