diff options
author | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-07-11 19:55:28 -0400 |
---|---|---|
committer | Jonathan Buchanan <jonathan.russ.buchanan@gmail.com> | 2020-07-11 19:55:28 -0400 |
commit | ecb3a2afa27257816b34e4e959d98424ef123033 (patch) | |
tree | 7c75fe2d6e4a11357d26b24f0a3e70ba0ee4f0ce /src/testing | |
parent | d299f7e7d288309dc696962edd9ce257d2c1a926 (diff) | |
download | merchant-ecb3a2afa27257816b34e4e959d98424ef123033.tar.gz merchant-ecb3a2afa27257816b34e4e959d98424ef123033.tar.bz2 merchant-ecb3a2afa27257816b34e4e959d98424ef123033.zip |
clean up testing post orders cmd
Diffstat (limited to 'src/testing')
-rw-r--r-- | src/testing/test_merchant_api.c | 143 | ||||
-rw-r--r-- | src/testing/test_merchant_api_twisted.c | 50 | ||||
-rw-r--r-- | src/testing/testing_api_cmd_post_orders.c | 101 |
3 files changed, 151 insertions, 143 deletions
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c index 7f418c99..f01f93fb 100644 --- a/src/testing/test_merchant_api.c +++ b/src/testing/test_merchant_api.c @@ -212,15 +212,10 @@ run (void *cls, TALER_TESTING_cmd_merchant_post_orders ("create-proposal-1", merchant_url, MHD_HTTP_OK, - "{\"max_fee\":\"EUR:0.5\",\ - \"order_id\":\"1\",\ - \"refund_deadline\": {\"t_ms\": 0},\ - \"pay_deadline\": {\"t_ms\": \"never\" },\ - \"amount\":\"EUR:5.0\",\ - \"summary\": \"merchant-lib testcase\",\ - \"fulfillment_url\": \"https://example.com/\",\ - \"products\": [ {\"description\":\"ice cream\",\ - \"value\":\"{EUR:5}\"} ] }"), + "1", + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + "EUR:5.0"), TALER_TESTING_cmd_poll_orders_conclude ("poll-orders-1-conclude", MHD_HTTP_OK, "poll-orders-1-start"), @@ -334,30 +329,20 @@ run (void *cls, TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-p3-wm-nx", merchant_url, MHD_HTTP_NOT_FOUND, - "{\"max_fee\":\"EUR:0.5\",\ - \"order_id\":\"order-p3\",\ - \"refund_deadline\": {\"t_ms\": 0},\ - \"pay_deadline\": {\"t_ms\": \"never\" },\ - \"amount\":\"EUR:5.0\",\ - \"summary\": \"merchant-lib testcase\",\ - \"fulfillment_url\": \"https://example.com/\",\ - \"products\": [ {\"description\":\"ice cream\",\ - \"value\":\"{EUR:5}\"} ] }", + "order-p3", + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + "EUR:5.0", "unsupported-wire-method", "product-3/2", ""), TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-p3-pd-nx", merchant_url, MHD_HTTP_NOT_FOUND, - "{\"max_fee\":\"EUR:0.5\",\ - \"order_id\":\"order-p3\",\ - \"refund_deadline\": {\"t_ms\": 0},\ - \"pay_deadline\": {\"t_ms\": \"never\" },\ - \"amount\":\"EUR:5.0\",\ - \"summary\": \"merchant-lib testcase\",\ - \"fulfillment_url\": \"https://example.com/\",\ - \"products\": [ {\"description\":\"ice cream\",\ - \"value\":\"{EUR:5}\"} ] }", + "order-p3", + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + "EUR:5.0", "x-taler-bank", "unknown-product/2", ""), @@ -365,30 +350,20 @@ run (void *cls, "create-proposal-p3-not-enough-stock", merchant_url, MHD_HTTP_GONE, - "{\"max_fee\":\"EUR:0.5\",\ - \"order_id\":\"order-p3\",\ - \"refund_deadline\": {\"t_ms\": 0},\ - \"pay_deadline\": {\"t_ms\": \"never\" },\ - \"amount\":\"EUR:5.0\",\ - \"summary\": \"merchant-lib testcase\",\ - \"fulfillment_url\": \"https://example.com/\",\ - \"products\": [ {\"description\":\"ice cream\",\ - \"value\":\"{EUR:5}\"} ] }", + "order-p3", + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + "EUR:5.0", "x-taler-bank", "product-3/24", ""), TALER_TESTING_cmd_merchant_post_orders2 ("create-proposal-p3", merchant_url, MHD_HTTP_OK, - "{\"max_fee\":\"EUR:0.5\",\ - \"order_id\":\"order-p3\",\ - \"refund_deadline\": {\"t_ms\": 0},\ - \"pay_deadline\": {\"t_ms\": \"never\" },\ - \"amount\":\"EUR:5.0\",\ - \"summary\": \"merchant-lib testcase\",\ - \"fulfillment_url\": \"https://example.com/\",\ - \"products\": [ {\"description\":\"ice cream\",\ - \"value\":\"{EUR:5}\"} ] }", + "order-p3", + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + "EUR:5.0", "x-taler-bank", "product-3/3", "lock-product-p3"), @@ -404,15 +379,10 @@ run (void *cls, TALER_TESTING_cmd_merchant_post_orders ("create-proposal-2", merchant_url, MHD_HTTP_OK, - "{\"max_fee\":\"EUR:0.5\",\ - \"order_id\":\"2\",\ - \"refund_deadline\": {\"t_ms\": 0},\ - \"pay_deadline\": {\"t_ms\": \"never\" },\ - \"amount\":\"EUR:5.0\",\ - \"summary\": \"useful product\",\ - \"fulfillment_url\": \"https://example.com/\",\ - \"products\": [ {\"description\":\"ice cream\",\ - \"value\":\"{EUR:5}\"} ] }"), + "2", + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + "EUR:5.0"), TALER_TESTING_cmd_merchant_claim_order ("fetch-proposal-2", merchant_url, MHD_HTTP_OK, @@ -479,15 +449,10 @@ run (void *cls, TALER_TESTING_cmd_merchant_post_orders ("create-proposal-1r", merchant_url, MHD_HTTP_OK, - "{\"max_fee\":\"EUR:0.5\",\ - \"order_id\":\"1r\",\ - \"refund_deadline\": {\"t_ms\": 0},\ - \"pay_deadline\": {\"t_ms\": \"never\" },\ - \"amount\":\"EUR:5.0\",\ - \"summary\": \"merchant-lib testcase\",\ - \"fulfillment_url\": \"https://example.com/\",\ - \"products\": [ {\"description\":\"ice cream\",\ - \"value\":\"{EUR:5}\"} ] }"), + "1r", + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + "EUR:5.0"), TALER_TESTING_cmd_merchant_pay_order ("pay-for-refund-1r", merchant_url, MHD_HTTP_OK, @@ -558,15 +523,10 @@ run (void *cls, TALER_TESTING_cmd_merchant_post_orders ("create-proposal-not-to-be-paid", merchant_url, MHD_HTTP_OK, - "{\"max_fee\":\"EUR:0.5\",\ - \"order_id\":\"1-unpaid\",\ - \"refund_deadline\":{\"t_ms\":0},\ - \"pay_deadline\":{\"t_ms\":\"never\"},\ - \"amount\":\"EUR:5.0\",\ - \"summary\": \"useful product\",\ - \"fulfillment_url\": \"https://example.com/\",\ - \"products\": [ {\"description\":\"ice cream\",\ - \"value\":\"{EUR:5}\"} ] }"), + "1-unpaid", + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + "EUR:5.0"), /* Try to increase a non paid proposal. */ TALER_TESTING_cmd_merchant_order_refund ("refund-increase-unpaid-proposal", merchant_url, @@ -606,15 +566,10 @@ run (void *cls, "create-proposal-unincreased-refund", merchant_url, MHD_HTTP_OK, - "{\"max_fee\":\"EUR:0.5\",\ - \"order_id\":\"unincreased-proposal\",\ - \"refund_deadline\":{\"t_ms\":0},\ - \"pay_deadline\":{\"t_ms\":\"never\"},\ - \"amount\":\"EUR:5.0\",\ - \"summary\": \"merchant-lib testcase\",\ - \"fulfillment_url\": \"https://example.com/\",\ - \"products\": [ {\"description\":\"ice cream\",\ - \"value\":\"{EUR:5}\"} ] }"), + "unincreased-proposal", + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + "EUR:5.0"), TALER_TESTING_cmd_merchant_pay_order ("pay-unincreased-proposal", merchant_url, MHD_HTTP_OK, @@ -868,15 +823,10 @@ run (void *cls, TALER_TESTING_cmd_merchant_post_orders ("create-proposal-10", merchant_url, MHD_HTTP_OK, - "{\"max_fee\":\"EUR:0.5\",\ - \"order_id\":\"10\",\ - \"refund_deadline\":{\"t_ms\":0},\ - \"pay_deadline\":{\"t_ms\":\"never\"},\ - \"amount\":\"EUR:10.0\",\ - \"summary\": \"merchant-lib testcase\",\ - \"fulfillment_url\": \"https://example.com/\",\ - \"products\": [ {\"description\":\"ice cream\",\ - \"value\":\"{EUR:10}\"} ] }"), + "10", + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + "EUR:10.0"), TALER_TESTING_cmd_merchant_pay_order ("pay-fail-partial-double-10", merchant_url, MHD_HTTP_CONFLICT, @@ -925,15 +875,10 @@ run (void *cls, TALER_TESTING_cmd_merchant_post_orders ("create-proposal-11", merchant_url, MHD_HTTP_OK, - "{\"max_fee\":\"EUR:0.5\",\ - \"order_id\":\"11\",\ - \"refund_deadline\":{\"t_ms\":0},\ - \"pay_deadline\":{\"t_ms\":\"never\"},\ - \"amount\":\"EUR:10.0\",\ - \"summary\": \"merchant-lib testcase\",\ - \"fulfillment_url\": \"https://example.com/\",\ - \"products\": [ {\"description\":\"ice cream\",\ - \"value\":\"{EUR:10}\"} ] }"), + "11", + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + "EUR:10.0"), TALER_TESTING_cmd_merchant_pay_order ("pay-fail-partial-double-11-good", merchant_url, MHD_HTTP_NOT_ACCEPTABLE, diff --git a/src/testing/test_merchant_api_twisted.c b/src/testing/test_merchant_api_twisted.c index 8f94ac17..baf025d3 100644 --- a/src/testing/test_merchant_api_twisted.c +++ b/src/testing/test_merchant_api_twisted.c @@ -222,15 +222,10 @@ run (void *cls, TALER_TESTING_cmd_merchant_post_orders ("create-proposal-abort-1", twister_merchant_url, MHD_HTTP_OK, - "{\"max_fee\":\"EUR:0.5\",\ - \"order_id\":\"abort-one\",\ - \"refund_deadline\":{\"t_ms\":0},\ - \"pay_deadline\":{\"t_ms\":\"never\"},\ - \"fulfillment_url\": \"https://example.com/\",\ - \"amount\":\"EUR:3.0\",\ - \"summary\": \"merchant-lib testcase\",\ - \"products\": [ {\"description\":\"ice cream\",\ - \"value\":\"{EUR:3}\"} ] }"), + "abort-one", + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + "EUR:3.0"), /* Will only pay _half_ the supposed price, * so we'll then have the right to abort. */ TALER_TESTING_cmd_merchant_pay_order ("deposit-simple-for-abort", @@ -283,25 +278,17 @@ run (void *cls, TALER_TESTING_cmd_merchant_post_orders ("create-proposal-double-spend", twister_merchant_url, MHD_HTTP_OK, - "{\"max_fee\":\"EUR:0.5\",\ - \"order_id\":\"DS-1\",\ - \"refund_deadline\":{\"t_ms\":0},\ - \"pay_deadline\":{\"t_ms\":\"never\"},\ - \"fulfillment_url\": \"https://example.com/\",\ - \"amount\":\"EUR:1.0\",\ - \"summary\": \"merchant-lib testcase\",\ - \"products\": [ {\"description\": \"will succeed\"}] }"), + "DS-1", + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + "EUR:1.0"), TALER_TESTING_cmd_merchant_post_orders ("create-proposal-double-spend-1", twister_merchant_url, MHD_HTTP_OK, - "{\"max_fee\":\"EUR:0.5\",\ - \"order_id\":\"DS-2\",\ - \"refund_deadline\":{\"t_ms\":0},\ - \"pay_deadline\":{\"t_ms\":\"never\"},\ - \"fulfillment_url\": \"https://example.com/\",\ - \"amount\":\"EUR:1.0\",\ - \"summary\": \"merchant-lib testcase\",\ - \"products\": [ {\"description\": \"will fail\"}] }"), + "DS-2", + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + "EUR:3.0"), TALER_TESTING_cmd_withdraw_amount ("withdraw-coin-double-spend", "create-reserve-double-spend", @@ -367,15 +354,10 @@ run (void *cls, TALER_TESTING_cmd_merchant_post_orders ("create-proposal-1", merchant_url, MHD_HTTP_OK, - "{\"max_fee\":\"EUR:0.5\",\ - \"order_id\":\"1\",\ - \"refund_deadline\": {\"t_ms\": 0},\ - \"pay_deadline\": {\"t_ms\": \"never\" },\ - \"amount\":\"EUR:5.0\",\ - \"summary\": \"merchant-lib testcase\",\ - \"fulfillment_url\": \"https://example.com/\",\ - \"products\": [ {\"description\":\"ice cream\",\ - \"value\":\"{EUR:5}\"} ] }"), + "1", + GNUNET_TIME_UNIT_ZERO_ABS, + GNUNET_TIME_UNIT_FOREVER_ABS, + "EUR:5.0"), TALER_TESTING_cmd_malform_response ("malform-exchange-reponse-1", PROXY_EXCHANGE_CONFIG_FILE), TALER_TESTING_cmd_merchant_pay_order ("deposit-simple", diff --git a/src/testing/testing_api_cmd_post_orders.c b/src/testing/testing_api_cmd_post_orders.c index 0e4f47af..3a489026 100644 --- a/src/testing/testing_api_cmd_post_orders.c +++ b/src/testing/testing_api_cmd_post_orders.c @@ -38,7 +38,7 @@ struct OrdersState /** * The order. */ - const char *order; + char *order; /** * Expected status code. @@ -505,32 +505,101 @@ orders_cleanup (void *cls, } json_decref (ps->contract_terms); + GNUNET_free (ps->order); GNUNET_free_nz ((void *) ps->order_id); GNUNET_free (ps); } /** - * Make the "orders" command. + * Constructs the json for a POST order request. + * + * @param order_id the name of the order to add. + * @param refund_deadline the deadline for refunds on this order. + * @param pay_deadline the deadline for payment on this order. + * @param amount the amount this order is for. + * @param order[out] where to write the json string. + */ +static void +make_order_json (const char *order_id, + struct GNUNET_TIME_Absolute refund_deadline, + struct GNUNET_TIME_Absolute pay_deadline, + const char *amount, + char **order) +{ + struct GNUNET_TIME_Absolute refund_deadline_round = refund_deadline; + char rd_str[64]; + + struct GNUNET_TIME_Absolute pay_deadline_round = pay_deadline; + char pd_str[64]; + + GNUNET_TIME_round_abs (&refund_deadline_round); + GNUNET_TIME_round_abs (&pay_deadline_round); + + GNUNET_snprintf (rd_str, + 64, + "{\"t_ms\":%llu}", + refund_deadline_round.abs_value_us / 1000LL); + if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us == pay_deadline.abs_value_us) + { + GNUNET_snprintf (pd_str, + 64, + "{\"t_ms\":\"never\"}"); + } + else + { + GNUNET_snprintf (pd_str, + 64, + "{\"t_ms\":%llu}", + pay_deadline_round.abs_value_us / 1000LL); + } + GNUNET_asprintf (order, + "{\"max_fee\":\"EUR:0.5\",\ + \"order_id\":\"%s\",\ + \"refund_deadline\":%s,\ + \"pay_deadline\":%s,\ + \"amount\":\"%s\",\ + \"summary\":\"merchant-lib testcase\",\ + \"fulfillment_url\":\"https://example.com/\"}", + order_id, + rd_str, + pd_str, + amount); +} + + +/** + * Make the "proposal" command. * * @param label command label * @param merchant_url base URL of the merchant serving - * the orders request. + * the proposal request. * @param http_status expected HTTP status. - * @param order the order to PUT to the merchant. - * + * @param order_id the name of the order to add. + * @param refund_deadline the deadline for refunds on this order. + * @param pay_deadline the deadline for payment on this order. + * @param amount the amount this order is for. * @return the command */ struct TALER_TESTING_Command TALER_TESTING_cmd_merchant_post_orders (const char *label, const char *merchant_url, unsigned int http_status, - const char *order) + const char *order_id, + struct GNUNET_TIME_Absolute + refund_deadline, + struct GNUNET_TIME_Absolute + pay_deadline, + const char *amount) { struct OrdersState *ps; ps = GNUNET_new (struct OrdersState); - ps->order = order; + make_order_json (order_id, + refund_deadline, + pay_deadline, + amount, + &ps->order); ps->http_status = http_status; ps->merchant_url = merchant_url; { @@ -554,7 +623,10 @@ TALER_TESTING_cmd_merchant_post_orders (const char *label, * @param merchant_url base URL of the merchant serving * the proposal request. * @param http_status expected HTTP status. - * @param order the order to PUT to the merchant. + * @param order_id the name of the order to add. + * @param refund_deadline the deadline for refunds on this order. + * @param pay_deadline the deadline for payment on this order. + * @param amount the amount this order is for. * @param payment_target payment target for the order. * @param products a string indicating the products this order will be * purchasing. Should be formatted as @@ -567,7 +639,12 @@ struct TALER_TESTING_Command TALER_TESTING_cmd_merchant_post_orders2 (const char *label, const char *merchant_url, unsigned int http_status, - const char *order, + const char *order_id, + struct GNUNET_TIME_Absolute + refund_deadline, + struct GNUNET_TIME_Absolute + pay_deadline, + const char *amount, const char *payment_target, const char *products, const char *locks) @@ -575,7 +652,11 @@ TALER_TESTING_cmd_merchant_post_orders2 (const char *label, struct OrdersState *ps; ps = GNUNET_new (struct OrdersState); - ps->order = order; + make_order_json (order_id, + refund_deadline, + pay_deadline, + amount, + &ps->order); ps->http_status = http_status; ps->merchant_url = merchant_url; ps->payment_target = payment_target; |