summaryrefslogtreecommitdiff
path: root/src/testing/testing_api_cmd_tip_authorize.c
diff options
context:
space:
mode:
authorJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-18 20:27:04 -0400
committerJonathan Buchanan <jonathan.russ.buchanan@gmail.com>2020-06-18 20:27:04 -0400
commit566408fa02acf56bbf6063c6d17d739e491e27f2 (patch)
tree35fe5a5be349e908f4fccd1d036d718f15abd221 /src/testing/testing_api_cmd_tip_authorize.c
parent6624576c0cdd81072256d8abbfe6dd1343f956c6 (diff)
downloadmerchant-566408fa02acf56bbf6063c6d17d739e491e27f2.tar.gz
merchant-566408fa02acf56bbf6063c6d17d739e491e27f2.tar.bz2
merchant-566408fa02acf56bbf6063c6d17d739e491e27f2.zip
stricter tests for tips/reserves
Diffstat (limited to 'src/testing/testing_api_cmd_tip_authorize.c')
-rw-r--r--src/testing/testing_api_cmd_tip_authorize.c187
1 files changed, 163 insertions, 24 deletions
diff --git a/src/testing/testing_api_cmd_tip_authorize.c b/src/testing/testing_api_cmd_tip_authorize.c
index e51b70f4..83b472ab 100644
--- a/src/testing/testing_api_cmd_tip_authorize.c
+++ b/src/testing/testing_api_cmd_tip_authorize.c
@@ -47,6 +47,12 @@ struct TipAuthorizeState
unsigned int http_status;
/**
+ * Reference to the reserv to authorize the tip
+ * from (if NULL, the merchant decides).
+ */
+ const char *reserve_reference;
+
+ /**
* Human-readable justification for the
* tip authorization carried on by this CMD.
*/
@@ -55,7 +61,7 @@ struct TipAuthorizeState
/**
* Amount that should be authorized for tipping.
*/
- const char *amount;
+ struct TALER_Amount amount;
/**
* Expected Taler error code for this CMD.
@@ -135,6 +141,7 @@ tip_authorize_cb (void *cls,
{
tas->tip_uri = strdup (taler_tip_uri);
tas->tip_id = *tip_id;
+ tas->tip_expiration = expiration;
}
TALER_TESTING_interpreter_next (tas->is);
}
@@ -157,15 +164,21 @@ tip_authorize_traits (void *cls,
unsigned int index)
{
struct TipAuthorizeState *tas = cls;
- struct TALER_TESTING_Trait traits[] = {
- TALER_TESTING_make_trait_tip_id (0, &tas->tip_id),
- TALER_TESTING_trait_end (),
- };
-
- return TALER_TESTING_get_trait (traits,
- ret,
- trait,
- index);
+
+ {
+ struct TALER_TESTING_Trait traits[] = {
+ TALER_TESTING_make_trait_tip_id (0, &tas->tip_id),
+ TALER_TESTING_make_trait_amount_obj (0, &tas->amount),
+ TALER_TESTING_make_trait_string (0, tas->justification),
+ TALER_TESTING_make_trait_absolute_time (0, &tas->tip_expiration),
+ TALER_TESTING_trait_end (),
+ };
+
+ return TALER_TESTING_get_trait (traits,
+ ret,
+ trait,
+ index);
+ }
}
@@ -182,20 +195,39 @@ tip_authorize_run (void *cls,
struct TALER_TESTING_Interpreter *is)
{
struct TipAuthorizeState *tas = cls;
- struct TALER_Amount amount;
tas->is = is;
- if (GNUNET_OK != TALER_string_to_amount (tas->amount,
- &amount))
- TALER_TESTING_FAIL (is);
-
- tas->tao = TALER_MERCHANT_tip_authorize (is->ctx,
- tas->merchant_url,
- "http://merchant.com/pickup",
- &amount,
- tas->justification,
- &tip_authorize_cb,
- tas);
+ if (NULL == tas->reserve_reference)
+ {
+ tas->tao = TALER_MERCHANT_tip_authorize (is->ctx,
+ tas->merchant_url,
+ "http://merchant.com/pickup",
+ &tas->amount,
+ tas->justification,
+ &tip_authorize_cb,
+ tas);
+ }
+ else
+ {
+ const struct TALER_TESTING_Command *reserve_cmd;
+ const struct TALER_ReservePublicKeyP *reserve_pub;
+
+ reserve_cmd = TALER_TESTING_interpreter_lookup_command (
+ tas->is,
+ tas->reserve_reference);
+ GNUNET_assert (GNUNET_OK ==
+ TALER_TESTING_get_trait_reserve_pub (reserve_cmd,
+ 0,
+ &reserve_pub));
+ tas->tao = TALER_MERCHANT_tip_authorize2 (is->ctx,
+ tas->merchant_url,
+ reserve_pub,
+ "http://merchant.com/pickup",
+ &tas->amount,
+ tas->justification,
+ &tip_authorize_cb,
+ tas);
+ }
GNUNET_assert (NULL != tas->tao);
}
@@ -277,9 +309,65 @@ TALER_TESTING_cmd_tip_authorize_with_ec (const char *label,
tas = GNUNET_new (struct TipAuthorizeState);
tas->merchant_url = merchant_url;
tas->justification = justification;
- tas->amount = amount;
tas->http_status = http_status;
tas->expected_ec = ec;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (amount,
+ &tas->amount));
+ {
+ struct TALER_TESTING_Command cmd = {
+ .label = label,
+ .cls = tas,
+ .run = &tip_authorize_run,
+ .cleanup = &tip_authorize_cleanup,
+ .traits = &tip_authorize_traits
+ };
+
+ return cmd;
+ }
+}
+
+
+/**
+ * Create a /tip-authorize CMD, specifying the Taler error code
+ * that is expected to be returned by the backend.
+ *
+ * @param label this command label
+ * @param merchant_url the base URL of the merchant that will
+ * serve the /tip-authorize request.
+ * @param exchange_url the base URL of the exchange that owns
+ * the reserve from which the tip is going to be gotten.
+ * @param reserve_reference reference to a command that created
+ * a reserve.
+ * @param http_status the HTTP response code which is expected
+ * for this operation.
+ * @param justification human-readable justification for this
+ * tip authorization.
+ * @param amount the amount to authorize for tipping.
+ * @param ec expected Taler-defined error code.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_tip_authorize_from_reserve_with_ec (const char *label,
+ const char *merchant_url,
+ const char *exchange_url,
+ const char *
+ reserve_reference,
+ unsigned int http_status,
+ const char *justification,
+ const char *amount,
+ enum TALER_ErrorCode ec)
+{
+ struct TipAuthorizeState *tas;
+
+ tas = GNUNET_new (struct TipAuthorizeState);
+ tas->merchant_url = merchant_url;
+ tas->justification = justification;
+ tas->http_status = http_status;
+ tas->expected_ec = ec;
+ tas->reserve_reference = reserve_reference;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (amount,
+ &tas->amount));
{
struct TALER_TESTING_Command cmd = {
.label = label,
@@ -321,8 +409,59 @@ TALER_TESTING_cmd_tip_authorize (const char *label,
tas = GNUNET_new (struct TipAuthorizeState);
tas->merchant_url = merchant_url;
tas->justification = justification;
- tas->amount = amount;
tas->http_status = http_status;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (amount,
+ &tas->amount));
+ {
+ struct TALER_TESTING_Command cmd = {
+ .label = label,
+ .cls = tas,
+ .run = &tip_authorize_run,
+ .cleanup = &tip_authorize_cleanup,
+ .traits = &tip_authorize_traits
+ };
+
+ return cmd;
+ }
+}
+
+
+/**
+ * Create a /tip-authorize CMD.
+ *
+ * @param label this command label
+ * @param merchant_url the base URL of the merchant that will
+ * serve the /tip-authorize request.
+ * @param exchange_url the base URL of the exchange that owns
+ * the reserve from which the tip is going to be gotten.
+ * @param reserve_reference reference to a command that created
+ * a reserve.
+ * @param http_status the HTTP response code which is expected
+ * for this operation.
+ * @param justification human-readable justification for this
+ * tip authorization.
+ * @param amount the amount to authorize for tipping.
+ */
+struct TALER_TESTING_Command
+TALER_TESTING_cmd_tip_authorize_from_reserve (const char *label,
+ const char *merchant_url,
+ const char *exchange_url,
+ const char *reserve_refernce,
+ unsigned int http_status,
+ const char *justification,
+ const char *amount)
+{
+ struct TipAuthorizeState *tas;
+
+ tas = GNUNET_new (struct TipAuthorizeState);
+ tas->merchant_url = merchant_url;
+ tas->reserve_reference = reserve_refernce;
+ tas->justification = justification;
+ tas->http_status = http_status;
+ GNUNET_assert (GNUNET_OK ==
+ TALER_string_to_amount (amount,
+ &tas->amount));
{
struct TALER_TESTING_Command cmd = {
.label = label,