Skip to content

Commit

Permalink
chore(docs): Adds dredd tests for calculate-amount API (#7263)
Browse files Browse the repository at this point in the history
  • Loading branch information
blossom2017 authored Sep 13, 2020
1 parent 9da9543 commit 2bafec0
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 2 deletions.
87 changes: 87 additions & 0 deletions docs/api/blueprint/order/orders.apib
Original file line number Diff line number Diff line change
Expand Up @@ -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 <Auth Key>

+ 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
}
17 changes: 15 additions & 2 deletions tests/hook_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down

0 comments on commit 2bafec0

Please sign in to comment.