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
Itemclass represents an item with properties likename,sellIn, andquality. -
The
IUpdateBehaviorinterface defines the contract for item update behaviors. Which is basically anupdatemethod that takes anItemand returns an updatedItem. Each specific item type has its own implementation of this interface, such asAgedBrieBehavior,BackstagePassBehavior, etc. You can find these implementations in theapp/update-behaviors/implementationsdirectory. -
The
getUpdateBehaviorFor(item)function checks the item name and returns the correct instantiated behavior class. This is done in theapp/update-behaviors/behavior-resolver.tsfile. -
The
GildedRoseclass is responsible for managing the items. It has anupdateQualitymethod that iterates through the items, retrieves the appropriate update behavior for each item via the resolver, and calls itsupdatemethod.
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