GildedRose-Refactoring-Kata/TypeScript/README.md

1.3 KiB

Gilded Rose

This is the Gilded Rose kata in TypeScript.

Architecture

The update logic is encapsulated in behaviors that define how different types of items are updated.

  • The Item class represents an item with properties like name, sellIn, and quality.

  • The IUpdateBehavior interface defines the contract for item update behaviors. Which is basically an update method that takes an Item and returns an updated Item. Each specific item type has its own implementation of this interface, such as AgedBrieBehavior, BackstagePassBehavior, etc. You can find these implementations in the app/update-behaviors/implementations directory.

  • The getUpdateBehaviorFor(item) function checks the item name and returns the correct instantiated behavior class. This is done in the app/update-behaviors/behavior-resolver.ts file.

  • The GildedRose class is responsible for managing the items. It has an updateQuality method that iterates through the items, retrieves the appropriate update behavior for each item via the resolver, and calls its update method.

Getting started

Install dependencies

npm install

Run the unit tests from the Command-Line

I chose to use Jest for unit tests and snapshot tests.

npm run test

To run all tests in watch mode

npm run test:watch