You will find here a simple Cart
+ Discount
models which we will use to explore and implement BDD with cucumber.
We are going to iterate the solution through several steps. For each step we have created a branch called stepX
where X
represents the number of the step. If at any point you feel lost or want to check our proposed solution, consult the code there.
-
- Install intelliJ community edition
- Enable cucumber plugin
- Enabling Annotation Processing for
Lombok
- Preferences | Build, Execution, Deployment | Compiler | Annotation Processors
- Enable annotation processing box is checked
- Obtain processors from project classpath option is selected
- Preferences | Build, Execution, Deployment | Compiler | Annotation Processors
- Install intelliJ community edition
-
-
make dependencies
-
make test
-
-
- Feature steps implementation π₯
- We have provided a basic cucumber structure with partially implemented steps. Now is time to make them work.
- Feature steps implementation π₯
-
- Code refactor β»οΈ
- Our Cart logic is quite basic, what if now that we have tests πͺ we do some refactor?
- Code refactor β»οΈ
-
- New feature: discounts with promo code π
- Our currents discounts are pretty simple and our business department has been working in a new functionality.
- As a Rohlik customer I want to apply discounts by code to my π so that I can save some π°
- Our team has processed a bit more the task and, we believe that a possible implementation could be:
- endpoint:
[POST] /carts/{id}/discounts
[payload] {"code": "XYZ"}
- Add a new column
code
ondiscount
model - Extend logic on
Cart
model to process new discounts - Mininum price does no apply on discounts by code, if you have the code, the discount applies always.
- The acceptance criteria is quite generic, will be our job to find good examples and translate them to feature scenarios.
- endpoint:
- Our currents discounts are pretty simple and our business department has been working in a new functionality.
- New feature: discounts with promo code π
-
- Update requirement: discounts by % π€
- Now that we have a powerful discount system, our business department wants to change it π, we will apply discounts by % (important! we will only support discounts by %). They gave us an examples:
- Given there is a cart discount of "10%" for carts with a value greater than 20 euros with code "SUPER-DISCOUNT"
- And I have a cart with products for a value of 21 euros
- When I apply the "SUPER-DISCOUNT" discount to my cart
- Then the cart's total cost should be of 18.90
- Our team thinks it shouldn't be hard to implement but maybe some refactor will help. Also, we believe, this is a good candidate to use examples
- Now that we have a powerful discount system, our business department wants to change it π, we will apply discounts by % (important! we will only support discounts by %). They gave us an examples:
- Update requirement: discounts by % π€
-
- New feature: cart checkout π
- Is time to finish our cart and send it to the warehouse π.
- As a Rohlik customer I want to check out my π for a concrete date so that I can receive the goodies π₯
- Our team thinks it will be complicated to test an external API call but let see what we can do.
- Warehouse microservice endpoint:
[POST] https://internal-warehouse-microservice.rohlik/orders
[payload] {"cart_id": 123, "customer_id": 123, "delivery_at": "2022-06-15T16:30:00Z", "products": [{"sku": "001"}, {"sku": "002"}]}
[response-status] 201
- In branch
step5
you will find a step implementation that could helpMockedServerSteps
- Warehouse microservice endpoint:
- Is time to finish our cart and send it to the warehouse π.
- New feature: cart checkout π
-
- Contract API testing βοΈ
- In our experience having a low level request/response API test can be used as and endpoint documentation π. Lets try with add to cart.
- Given I have a cart
- When I send a "POST" request to
/carts/{id}/lines
with body:""" {"sku": "001", "quantity": 2} """
- Then the response status should be "200" with body:
""" {"id":1,"total":5.0,"lines":[{"sku":"001","name":"potatoes","quantity":2}],"discounts":[]} """
- In branch
step6
you will find a step implementation that could helpHttpSteps
- In our experience having a low level request/response API test can be used as and endpoint documentation π. Lets try with add to cart.
- Contract API testing βοΈ