Home

Awesome

Promotion Text Kata

Why this Kata?

The Promotion Text Kata offers an hour-long hands-on practice on readable and maintainable programming. When practicing alone, it improves a developer's craft. When practicing as a team, it educates and aligns the team on a standard set of best practices and coding styles.

Users' goal is to improve the readability of the PromotionTextDecorator class without breaking its functionalities.

This Kata does not aim to improve OOP and design pattern skills.

While heavily rewritten, it's inspired by an example (HtmlUtil.java) in Chapter 3 of the book "Clean Code: A Handbook of Agile Software Craftsmanship" by Robert C. Martin.

How to use this Kata

PromotionTextDecorator Requirements

Given a product, PromotionTextDecorator.decorate should generate a promotion description:

Examples:

const product = {
  promoted: true,
  hideDiscount: false,
  oldCentPrice: 10000,
  centPrice: 9000,
  freeShipping: true,
  description: "Pre-owned vase",
  promotionText: "Some old text",
};

becomes

const product = {
  promoted: true,
  hideDiscount: false,
  oldCentPrice: 10000,
  centPrice: 9000,
  freeShipping: true,
  description: 'Pre-owned vase',
  promotionText: 'Don't miss the deal, $X off!\nFree shipping!\nPre-owned vase\nFree shipping!\nDon't miss the deal, $X off!',
}

Please see the unit tests for more details.

Solution

There is a solution provided in after-refactor/. It is one of the many ways to improve the code. It follows the practices mentioned in the Clean Code book, to name a few: