Skip to content

TestCase for order create API to ensure accuracy of discount and tax calculation  #237

@MySecondLanguage

Description

@MySecondLanguage

PR to be reviewed: #266

Write Test Cases for Order Create API

Purpose

We need to ensure the robustness and correctness of the Order Create API by covering scenarios involving tax calculations, and promotional discounts. The goal is to validate the behavior of the API across different currencies and complex combinations of products, promo codes, and discounts.

File Name

All test cases should be implemented in the file:
nxtbn/order/tests/test_order_create_tax_discount_rate_sc.py


Requirements

1. Product Setup

  • Create 6 products with varying properties.
  • Ensure that one product is assigned a tax class with 15% VAT.

2. Promo Code Setup

Create 7 promo codes with the following rules:

A. General Discount:

  • Code: 20ALL
  • Offers 20% discount on the total order.

B. Flat Discount:

  • Code: FLAT200ALL
  • Offers a flat discount of:
    • 200 USD, 300 JPY, or 300 KWD, depending on the selected currency.

C. Customer-Specific Discount:

  • Code: GOLDCUSTOMER5
  • Offers a 5% discount, restricted to specific customers only.

D. Minimum Purchase Restriction:

  • Code: SELL5
  • Requires a minimum purchase amount and is valid only within a specified purchase period.

E. Product-Specific Discount:

  • Code: CLEARANCE20
  • Offers a 20% discount but is restricted to one of the six products created earlier.

3. Order Placement

Write test cases to simulate the creation of 7 orders:

  1. Use each of the 6 promo codes in separate orders.
  2. For the 7th order, apply a custom discount of:
    • 500 USD, 500 JPY, or 700 KWD, based on the selected currency.
  • Each order should include all 6 product variants.

4. Currency Validation

  • Run the test cases by switching the settings.BASE_CURRENCY to:
    • USD, KWD, and JPY.
  • Ensure that:
    • Input values are correctly transformed for the respective currency.
    • Expected outputs (total amount, tax, discounts, etc.) match the calculated results for each currency.

Expected Behavior

  • The API should correctly calculate the order total, including:
    • Product prices, taxes,
    • Promo code discounts or custom discounts.
  • The tests should pass successfully for all three currencies.

Reference

Refer to the existing implementation for testing the Order Create API:

You can check order/tests/** we have implemented a few text case already

You can get ideas from there


Acceptance Criteria

1. Test Implementation

  • All scenarios (products, promo codes, and orders tax) should be covered in the file test_order_create_tax_discount_rate_sc.py.
  • The tests validate both input and output values.

2. Currency Handling

  • Tests successfully execute for all configured currencies (USD, KWD, JPY). You can check, we have already implemented 2 test case for order

3. Error Handling

  • If any test fails due to issues in the API, identify and resolve them to comply with the expected behavior. make sure existing test should not be broken

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions