Skip to content

Instantly share code, notes, and snippets.

@felixcarpena
Last active June 3, 2022 09:27
Show Gist options
  • Save felixcarpena/c692e21f1f8382d8e5e311af114bf482 to your computer and use it in GitHub Desktop.
Save felixcarpena/c692e21f1f8382d8e5e311af114bf482 to your computer and use it in GitHub Desktop.

Rohlik BDD workshop

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.

Setup

  • Requirements

  • IDE

    • 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
  • Lifecycle:

    • Dependencies

      • make dependencies
    • test

      • make test

Iterations

  • step1

    • Feature steps implementation πŸ₯’
      • We have provided a basic cucumber structure with partially implemented steps. Now is time to make them work.
  • step2

    • Code refactor ♻️
      • Our Cart logic is quite basic, what if now that we have tests πŸ’ͺ we do some refactor?
  • step3

    • 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 on discount 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.
  • step4

    • 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
  • step5

    • 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 help MockedServerSteps
  • step6 (extra step)

    • 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 help HttpSteps

Made with β™₯ by

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment