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