gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-merchant] branch master updated: update using template for test c


From: gnunet
Subject: [taler-merchant] branch master updated: update using template for test case
Date: Wed, 29 Mar 2023 21:18:29 +0200

This is an automated email from the git hooks/post-receive script.

priscilla-huang pushed a commit to branch master
in repository merchant.

The following commit(s) were added to refs/heads/master by this push:
     new 12c4693a update using template for test case
12c4693a is described below

commit 12c4693a67b7e993e7d6504777e4fbbb76f43dda
Author: priscilla <priscilla.huang@efrei.net>
AuthorDate: Wed Mar 29 15:18:06 2023 -0400

    update using template for test case
---
 src/include/taler_merchant_testing_lib.h           | 16 ++--
 src/testing/test_merchant_api.c                    | 18 ++++
 src/testing/testing_api_cmd_post_using_templates.c | 95 ++++++++++++++++++++--
 3 files changed, 117 insertions(+), 12 deletions(-)

diff --git a/src/include/taler_merchant_testing_lib.h 
b/src/include/taler_merchant_testing_lib.h
index 886b052b..0071e677 100644
--- a/src/include/taler_merchant_testing_lib.h
+++ b/src/include/taler_merchant_testing_lib.h
@@ -1630,12 +1630,16 @@ TALER_TESTING_cmd_merchant_delete_template (const char 
*label,
  * @return the command.
  */
 struct TALER_TESTING_Command
-TALER_TESTING_cmd_merchant_post_using_templates (const char *label,
-                                                 const char *template_ref,
-                                                 const char *merchant_url,
-                                                 const char *summary,
-                                                 const char *amount,
-                                                 unsigned int http_status);
+TALER_TESTING_cmd_merchant_post_using_templates (
+  const char *label,
+  const char *template_ref,
+  const char *merchant_url,
+  const char *using_template_id,
+  const char *summary,
+  const char *amount,
+  struct GNUNET_TIME_Timestamp refund_deadline,
+  struct GNUNET_TIME_Timestamp pay_deadline,
+  unsigned int http_status);
 
 
 /* ****** Webhooks ******* */
diff --git a/src/testing/test_merchant_api.c b/src/testing/test_merchant_api.c
index 6c8e5abd..d63d54e5 100644
--- a/src/testing/test_merchant_api.c
+++ b/src/testing/test_merchant_api.c
@@ -1409,36 +1409,51 @@ run (void *cls,
       "using-templates-t1",
       "post-templates-t1",
       merchant_url,
+      "1",
       "summary-1",
       "EUR:10",
+      GNUNET_TIME_UNIT_ZERO_TS,
+      GNUNET_TIME_UNIT_FOREVER_TS,
       MHD_HTTP_OK),
     TALER_TESTING_cmd_merchant_post_using_templates (
       "using-templates-t1-amount-missing",
       "post-templates-t1",
       merchant_url,
+      "2",
       "summary-1",
       NULL,
+      GNUNET_TIME_UNIT_ZERO_TS,
+      GNUNET_TIME_UNIT_FOREVER_TS,
       MHD_HTTP_CONFLICT),
     TALER_TESTING_cmd_merchant_post_using_templates (
       "using-templates-t1-summary-missing",
       "post-templates-t1",
       merchant_url,
+      "3",
       NULL,
       "EUR:10",
+      GNUNET_TIME_UNIT_ZERO_TS,
+      GNUNET_TIME_UNIT_FOREVER_TS,
       MHD_HTTP_CONFLICT),
     TALER_TESTING_cmd_merchant_post_using_templates (
       "using-templates-t1-amount-conflict",
       "post-templates-t3-amount",
       merchant_url,
+      "4",
       "summary-1",
       "EUR:10",
+      GNUNET_TIME_UNIT_ZERO_TS,
+      GNUNET_TIME_UNIT_FOREVER_TS,
       MHD_HTTP_CONFLICT),
     TALER_TESTING_cmd_merchant_post_using_templates (
       "using-templates-t1-amount-duplicate",
       "post-templates-t3-amount",
       merchant_url,
+      "4",
       "summary-1",
       "EUR:4",
+      GNUNET_TIME_UNIT_ZERO_TS,
+      GNUNET_TIME_UNIT_FOREVER_TS,
       MHD_HTTP_CONFLICT),
     TALER_TESTING_cmd_merchant_pay_order ("pay-100",
                                           merchant_url,
@@ -1460,8 +1475,11 @@ run (void *cls,
       "post-templates-t1-deleted",
       "post-templates-t1",
       merchant_url,
+      "0",
       "summary-1",
       "EUR:5",
+      GNUNET_TIME_UNIT_ZERO_TS,
+      GNUNET_TIME_UNIT_FOREVER_TS,
       MHD_HTTP_NOT_FOUND),
     TALER_TESTING_cmd_end ()
   };
diff --git a/src/testing/testing_api_cmd_post_using_templates.c 
b/src/testing/testing_api_cmd_post_using_templates.c
index 88fe9f9b..a68ea8fe 100644
--- a/src/testing/testing_api_cmd_post_using_templates.c
+++ b/src/testing/testing_api_cmd_post_using_templates.c
@@ -27,6 +27,8 @@
 #include "taler_merchant_service.h"
 #include "taler_merchant_testing_lib.h"
 
+
+
 /**
  * State of a "POST /templates" CMD.
  */
@@ -55,6 +57,11 @@ struct PostUsingTemplatesState
    */
   const char *merchant_url;
 
+  /**
+   * ID of the using template to run.
+   */
+  const char *using_template_id;
+
   /**
    * Summary given by the customer.
    */
@@ -144,8 +151,8 @@ struct PostUsingTemplatesState
 };
 
 /**
- * Used to fill the "orders" CMD state with backend-provided
- * values.  Also double-checks that the order was correctly
+ * Used to fill the "using_template" CMD state with backend-provided
+ * values.  Also double-checks that the using_template was correctly
  * created.
  *
  * @param cls closure
@@ -155,7 +162,7 @@ struct PostUsingTemplatesState
  * @param hash hash over the contract
  */
 static void
-orders_claim_cb (void *cls,
+using_claim_cb (void *cls,
                  const struct TALER_MERCHANT_HttpResponse *hr,
                  const json_t *contract_terms,
                  const struct TALER_MerchantSignatureP *sig,
@@ -324,7 +331,7 @@ post_using_templates_cb (void *cls,
                                              tis->order_id,
                                              &tis->nonce,
                                              &tis->claim_token,
-                                             &orders_claim_cb,
+                                             &using_claim_cb,
                                              tis)))
     TALER_TESTING_FAIL (tis->is);
 }
@@ -404,8 +411,8 @@ post_using_templates_traits (void *cls,
     TALER_TESTING_make_trait_merchant_pub (&pts->merchant_pub),
     TALER_TESTING_make_trait_claim_nonce (&pts->nonce),
     TALER_TESTING_make_trait_claim_token (&pts->claim_token),
-    TALER_TESTING_make_trait_template_pos_key (&pts->template_pos_key), // 
extract from template creation CMD
-    TALER_TESTING_make_trait_template_pos_alg (&pts->template_pos_alg),
+    TALER_TESTING_make_trait_template_pos_key (pts->template_pos_key), // 
extract from template creation CMD
+    TALER_TESTING_make_trait_template_pos_alg (pts->template_pos_alg),
     TALER_TESTING_trait_end (),
   };
 
@@ -440,13 +447,83 @@ post_using_templates_cleanup (void *cls,
 }
 
 
+/**
+ * Mark part of the contract terms as possible to forget.
+ *
+ * @param cls pointer to the result of the forget operation.
+ * @param object_id name of the object to forget.
+ * @param parent parent of the object at @e object_id.
+ */
+static void
+mark_forgettable (void *cls,
+                  const char *object_id,
+                  json_t *parent)
+{
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_JSON_contract_mark_forgettable (parent,
+                                                       object_id));
+}
+
+
+/**
+ * Constructs the json for a POST using template request.
+ *
+ * @param using_template_id the name of the using_template to add, can be NULL.
+ * @param refund_deadline the deadline for refunds on this using template.
+ * @param pay_deadline the deadline for payment on this using template.
+ * @param amount the amount this using template is for.
+ * @param[out] using_template where to write the json string.
+ */
+static void
+make_order_json (const char *using_template_id,
+                 struct GNUNET_TIME_Timestamp refund_deadline,
+                 struct GNUNET_TIME_Timestamp pay_deadline,
+                 const char *amount,
+                 json_t **using_template)
+{
+  struct GNUNET_TIME_Timestamp refund = refund_deadline;
+  struct GNUNET_TIME_Timestamp pay = pay_deadline;
+  json_t *contract_terms;
+
+  /* Include required fields and some dummy objects to test forgetting. */
+  contract_terms = json_pack (
+    "{s:s, s:s?, s:s, s:s, s:o, s:o, s:s, s:[{s:s}, {s:s}, {s:s}]}",
+    "summary", "merchant-lib testcase",
+    "using_template_id", using_template_id,
+    "amount", amount,
+    "fulfillment_url", "https://example.com";,
+    "refund_deadline", GNUNET_JSON_from_timestamp (refund),
+    "pay_deadline", GNUNET_JSON_from_timestamp (pay),
+    "dummy_obj", "EUR:1.0",
+    "dummy_array", /* For testing forgetting parts of arrays */
+    "item", "speakers",
+    "item", "headphones",
+    "item", "earbuds"
+    );
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_JSON_expand_path (contract_terms,
+                                         "$.dummy_obj",
+                                         &mark_forgettable,
+                                         NULL));
+  GNUNET_assert (GNUNET_OK ==
+                 TALER_JSON_expand_path (contract_terms,
+                                         "$.dummy_array[*].item",
+                                         &mark_forgettable,
+                                         NULL));
+  *using_template = contract_terms;
+}
+
+
 struct TALER_TESTING_Command
 TALER_TESTING_cmd_merchant_post_using_templates (
   const char *label,
   const char *template_ref,
   const char *merchant_url,
+  const char *using_template_id,
   const char *summary,
   const char *amount,
+  struct GNUNET_TIME_Timestamp refund_deadline,
+  struct GNUNET_TIME_Timestamp pay_deadline,
   unsigned int http_status)
 {
   struct PostUsingTemplatesState *tis;
@@ -454,8 +531,14 @@ TALER_TESTING_cmd_merchant_post_using_templates (
   tis = GNUNET_new (struct PostUsingTemplatesState);
   tis->template_ref = template_ref;
   tis->merchant_url = merchant_url;
+  tis->using_template_id = using_template_id;
   tis->http_status = http_status;
   tis->summary = summary;
+  make_order_json (using_template_id,
+                   refund_deadline,
+                   pay_deadline,
+                   amount,
+                   &tis->order_terms);
   if (NULL != amount)
     GNUNET_assert (GNUNET_OK ==
                    TALER_string_to_amount (amount,

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]