testing_api_cmd_delete_order.c (4670B)
1 /* 2 This file is part of TALER 3 Copyright (C) 2020 Taler Systems SA 4 5 TALER is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as 7 published by the Free Software Foundation; either version 3, or 8 (at your option) any later version. 9 10 TALER is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public 16 License along with TALER; see the file COPYING. If not, see 17 <http://www.gnu.org/licenses/> 18 */ 19 /** 20 * @file testing_api_cmd_delete_order.c 21 * @brief command to test DELETE /orders/$ORDER_ID 22 * @author Jonathan Buchanan 23 */ 24 #include "taler/platform.h" 25 #include <taler/taler_exchange_service.h> 26 #include <taler/taler_testing_lib.h> 27 #include "taler/taler_merchant_service.h" 28 #include "taler/taler_merchant_testing_lib.h" 29 #include <taler/taler-merchant/delete-private-orders-ORDER_ID.h> 30 31 32 /** 33 * State of a "DELETE /order/$ORDER_ID" CMD. 34 */ 35 struct DeleteOrderState 36 { 37 38 /** 39 * Handle for a "DELETE order" request. 40 */ 41 struct TALER_MERCHANT_DeletePrivateOrderHandle *odh; 42 43 /** 44 * The interpreter state. 45 */ 46 struct TALER_TESTING_Interpreter *is; 47 48 /** 49 * Base URL of the merchant serving the request. 50 */ 51 const char *merchant_url; 52 53 /** 54 * ID of the order to run DELETE for. 55 */ 56 const char *order_id; 57 58 /** 59 * Expected HTTP response code. 60 */ 61 unsigned int http_status; 62 63 }; 64 65 66 /** 67 * Callback for a DELETE /orders/$ID operation. 68 * 69 * @param cls closure for this function 70 * @param hr response being processed 71 */ 72 static void 73 delete_order_cb (void *cls, 74 const struct TALER_MERCHANT_DeletePrivateOrderResponse *dor) 75 { 76 struct DeleteOrderState *dos = cls; 77 78 dos->odh = NULL; 79 if (dos->http_status != dor->hr.http_status) 80 { 81 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 82 "Unexpected response code %u (%d) to command %s\n", 83 dor->hr.http_status, 84 (int) dor->hr.ec, 85 TALER_TESTING_interpreter_get_current_label (dos->is)); 86 TALER_TESTING_interpreter_fail (dos->is); 87 return; 88 } 89 switch (dor->hr.http_status) 90 { 91 case MHD_HTTP_NO_CONTENT: 92 break; 93 case MHD_HTTP_UNAUTHORIZED: 94 break; 95 case MHD_HTTP_NOT_FOUND: 96 break; 97 case MHD_HTTP_CONFLICT: 98 break; 99 default: 100 GNUNET_break (0); 101 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 102 "Unhandled HTTP status %u for DELETE order.\n", 103 dor->hr.http_status); 104 } 105 TALER_TESTING_interpreter_next (dos->is); 106 } 107 108 109 /** 110 * Run the "DELETE order" CMD. 111 * 112 * 113 * @param cls closure. 114 * @param cmd command being run now. 115 * @param is interpreter state. 116 */ 117 static void 118 delete_order_run (void *cls, 119 const struct TALER_TESTING_Command *cmd, 120 struct TALER_TESTING_Interpreter *is) 121 { 122 struct DeleteOrderState *dos = cls; 123 124 dos->is = is; 125 dos->odh = TALER_MERCHANT_delete_private_order_create ( 126 TALER_TESTING_interpreter_get_context (is), 127 dos->merchant_url, 128 dos->order_id); 129 { 130 enum TALER_ErrorCode ec; 131 132 ec = TALER_MERCHANT_delete_private_order_start (dos->odh, 133 &delete_order_cb, 134 dos); 135 GNUNET_assert (TALER_EC_NONE == ec); 136 } 137 } 138 139 140 /** 141 * Free the state of a "DELETE order" CMD, and possibly 142 * cancel a pending operation thereof. 143 * 144 * @param cls closure. 145 * @param cmd command being run. 146 */ 147 static void 148 delete_order_cleanup (void *cls, 149 const struct TALER_TESTING_Command *cmd) 150 { 151 struct DeleteOrderState *dos = cls; 152 153 if (NULL != dos->odh) 154 { 155 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 156 "DELETE /orders/$ORDER_ID operation did not complete\n"); 157 TALER_MERCHANT_delete_private_order_cancel (dos->odh); 158 } 159 GNUNET_free (dos); 160 } 161 162 163 struct TALER_TESTING_Command 164 TALER_TESTING_cmd_merchant_delete_order (const char *label, 165 const char *merchant_url, 166 const char *order_id, 167 unsigned int http_status) 168 { 169 struct DeleteOrderState *dos; 170 171 dos = GNUNET_new (struct DeleteOrderState); 172 dos->merchant_url = merchant_url; 173 dos->order_id = order_id; 174 dos->http_status = http_status; 175 { 176 struct TALER_TESTING_Command cmd = { 177 .cls = dos, 178 .label = label, 179 .run = &delete_order_run, 180 .cleanup = &delete_order_cleanup 181 }; 182 183 return cmd; 184 } 185 }