From 396af1bd0201d91c88e0965efaf9e881460e41d9 Mon Sep 17 00:00:00 2001 From: blossom2017 Date: Sun, 13 Sep 2020 00:50:19 +0530 Subject: [PATCH] Adds dredd tests for calculate-amount API --- docs/api/blueprint/order/orders.apib | 87 ++++++++++++++++++++++++++++ tests/hook_main.py | 17 +++++- 2 files changed, 102 insertions(+), 2 deletions(-) diff --git a/docs/api/blueprint/order/orders.apib b/docs/api/blueprint/order/orders.apib index bfc52e74a5..228062450a 100644 --- a/docs/api/blueprint/order/orders.apib +++ b/docs/api/blueprint/order/orders.apib @@ -735,3 +735,90 @@ Create paypal payment "payment_id": "example", "error": null } + +## Calculate Order Amount [/v1/orders/calculate-amount] + +### Calculate Order Amount [POST] +Calculates the order amount + ++ Request (application/json) + + + Headers + + Accept: application/json + + Authorization: JWT + + + Body + + { + "tickets": [ + {"id": 1, "quantity": 2}, + {"id": 2, "quantity": 4}, + {"id": 3, "quantity": 3, "price": 789.7}, + {"id": 4, "quantity": 3} + ], + "discount_code": "1" + } + ++ Response 200 (application/json) + + { + "discount": 419.43, + "sub_total": 4021.87, + "tax": { + "amount": 723.94, + "included": false, + "name": "GST", + "percent": 18 + }, + "tickets": [ + { + "discount": null, + "id": 1, + "name": "example", + "price": 123.5, + "quantity": 2, + "sub_total": 247, + "ticket_fee": 0 + }, + { + "discount": { + "amount": 45.63, + "code": "example", + "percent": 10, + "total": 182.52 + }, + "id": 2, + "name": "example", + "price": 456.3, + "quantity": 4, + "sub_total": 1642.68, + "ticket_fee": 0 + }, + { + "discount": { + "amount": 78.97, + "code": "example", + "percent": 10, + "total": 236.91 + }, + "id": 3, + "name": "example", + "price": 789.7, + "quantity": 3, + "sub_total": 2132.19, + "ticket_fee": 0 + }, + { + "discount": null, + "id": 4, + "name": "example", + "price": 0, + "quantity": 3, + "sub_total": 0, + "ticket_fee": 0 + } + ], + "total": 4745.81 + } \ No newline at end of file diff --git a/tests/hook_main.py b/tests/hook_main.py index 0b1b0b6f85..fd3377c5c1 100644 --- a/tests/hook_main.py +++ b/tests/hook_main.py @@ -4226,9 +4226,22 @@ def create_order(transaction): discount_code = DiscountCodeTicketSubFactory( type='percent', value=10.0, tickets=[] ) - tickets_dict = _create_taxed_tickets( - db, tax_included=False, discount_code=discount_code + _create_taxed_tickets(db, tax_included=False, discount_code=discount_code) + db.session.commit() + + +@hooks.before("Orders > Calculate Order Amount > Calculate Order Amount") +def calculate_amount(transaction): + """ + POST /orders/calculate-amount + :param transaction: + :return: + """ + with stash['app'].app_context(): + discount_code = DiscountCodeTicketSubFactory( + type='percent', value=10.0, tickets=[] ) + _create_taxed_tickets(db, tax_included=False, discount_code=discount_code) db.session.commit()