Skip to content

Commit ec5275a

Browse files
committed
Initial setup
1 parent aeabb5b commit ec5275a

File tree

11 files changed

+8921
-1
lines changed

11 files changed

+8921
-1
lines changed

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 2
6+
end_of_line = lf
7+
charset = utf-8
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.DS_Store
2+
.idea
3+
node_modules
4+
typings
5+
app/**/*.js
6+
app/**/*.js.map
7+
test/**/*.js
8+
test/**/*.js.map
9+
coverage
10+
.nyc_output
11+
jest/__snapshots__

.nycrc.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
extension: [
3+
".ts"
4+
],
5+
exclude: [
6+
"**/*.d.ts",
7+
"test/**",
8+
"/*.js"
9+
],
10+
require: [
11+
"ts-node/register"
12+
],
13+
reporter: [
14+
"html",
15+
"text"
16+
]
17+
}

README.md

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,92 @@
11
# workshop-soft-eng
2-
Hands-on workshop on good practices in software engineering
2+
3+
Hands-on workshop on good practices in software engineering. We're going to have a look at TDD, Unit Testing, Refactoring
4+
and CI/CD.
5+
6+
# Gilded Rose Refactoring Kata
7+
8+
Today's workshop is based on a popular refactoring exercise you can find out more about [here](https://github.com/emilybache/GildedRose-Refactoring-Kata/tree/main).
9+
10+
# Setup
11+
12+
We recommend using [Intellij](https://www.jetbrains.com/idea/download/) as the IDE.
13+
14+
You will have to install [Node](https://nodejs.org/en/download/package-manager) v18.20. This should also install `npm`,
15+
which is a Node packet manager
16+
17+
You might also have to install [ts-node](https://www.npmjs.com/package/ts-node#installation), after you get Node.
18+
19+
```
20+
# Locally in your project.
21+
npm install -D typescript
22+
23+
npm install -D ts-node
24+
```
25+
26+
# Getting started
27+
28+
**First, fork this repository and clone it on your device.**
29+
30+
Then, install dependencies
31+
32+
```npm install```
33+
34+
# Run the unit tests from the Command-Line
35+
36+
We are using jest as a testing framework.
37+
38+
To run tests:
39+
40+
```npm run test:jest```
41+
42+
To run all tests in watch mode:
43+
44+
```npm run test:jest:watch```
45+
46+
# Running the app
47+
48+
You can run the application seeing how the `updateQuality()` function works:
49+
50+
```npx ts-node test/golden-master-text-test.ts```
51+
52+
Or with the number of days as args:
53+
54+
```npx ts-node test/golde-master-text-test.ts 10```
55+
56+
# Gilded Rose Requirements Specification
57+
58+
Hi and welcome to team Gilded Rose. As you know, we are a small inn with a prime location in a
59+
prominent city ran by a friendly innkeeper named Allison. We also buy and sell only the finest goods.
60+
Unfortunately, our goods are constantly degrading in `Quality` as they approach their sell by date.
61+
62+
We have a system in place that updates our inventory for us. It was developed by a no-nonsense type named
63+
Leeroy, who has moved on to new adventures. Your task is to add the new feature to our system so that
64+
we can begin selling a new category of items. First an introduction to our system:
65+
66+
- All `items` have a `SellIn` value which denotes the number of days we have to sell the `items`
67+
- All `items` have a `Quality` value which denotes how valuable the item is
68+
- At the end of each day our system lowers both values for every item
69+
70+
Pretty simple, right? Well this is where it gets interesting:
71+
72+
- Once the sell by date has passed, `Quality` degrades twice as fast
73+
- The `Quality` of an item is never negative
74+
- __"Aged Brie"__ actually increases in `Quality` the older it gets
75+
- The `Quality` of an item is never more than `50`
76+
- __"Sulfuras"__, being a legendary item, never has to be sold or decreases in `Quality`
77+
- __"Backstage passes"__, like aged brie, increases in `Quality` as its `SellIn` value approaches;
78+
- `Quality` increases by `2` when there are `10` days or less and by `3` when there are `5` days or less but
79+
- `Quality` drops to `0` after the concert
80+
81+
We have recently signed a supplier of conjured items. This requires an update to our system:
82+
83+
- __"Conjured"__ items degrade in `Quality` twice as fast as normal items
84+
85+
Feel free to make any changes to the `UpdateQuality` method and add any new code as long as everything
86+
still works correctly. However, do not alter the `Item` class or `Items` property as those belong to the
87+
goblin in the corner who will insta-rage and one-shot you as he doesn't believe in shared code
88+
ownership (you can make the `UpdateQuality` method and `Items` property static if you like, we'll cover
89+
for you).
90+
91+
Just for clarification, an item can never have its `Quality` increase above `50`, however __"Sulfuras"__ is a
92+
legendary item and as such its `Quality` is `80` and it never alters.

app/gilded-rose.ts

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
export class Item {
2+
name: string;
3+
sellIn: number;
4+
quality: number;
5+
6+
constructor(name, sellIn, quality) {
7+
this.name = name;
8+
this.sellIn = sellIn;
9+
this.quality = quality;
10+
}
11+
}
12+
13+
export class GildedRose {
14+
items: Array<Item>;
15+
16+
constructor(items = [] as Array<Item>) {
17+
this.items = items;
18+
}
19+
20+
updateQuality() {
21+
for (let i = 0; i < this.items.length; i++) {
22+
if (this.items[i].name != 'Aged Brie' && this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
23+
if (this.items[i].quality > 0) {
24+
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
25+
this.items[i].quality = this.items[i].quality - 1
26+
}
27+
}
28+
} else {
29+
if (this.items[i].quality < 50) {
30+
this.items[i].quality = this.items[i].quality + 1
31+
if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') {
32+
if (this.items[i].sellIn < 11) {
33+
if (this.items[i].quality < 50) {
34+
this.items[i].quality = this.items[i].quality + 1
35+
}
36+
}
37+
if (this.items[i].sellIn < 6) {
38+
if (this.items[i].quality < 50) {
39+
this.items[i].quality = this.items[i].quality + 1
40+
}
41+
}
42+
}
43+
}
44+
}
45+
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
46+
this.items[i].sellIn = this.items[i].sellIn - 1;
47+
}
48+
if (this.items[i].sellIn < 0) {
49+
if (this.items[i].name != 'Aged Brie') {
50+
if (this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
51+
if (this.items[i].quality > 0) {
52+
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
53+
this.items[i].quality = this.items[i].quality - 1
54+
}
55+
}
56+
} else {
57+
this.items[i].quality = this.items[i].quality - this.items[i].quality
58+
}
59+
} else {
60+
if (this.items[i].quality < 50) {
61+
this.items[i].quality = this.items[i].quality + 1
62+
}
63+
}
64+
}
65+
}
66+
67+
return this.items;
68+
}
69+
}

jest.config.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { pathsToModuleNameMapper } from "ts-jest/utils";
2+
const { compilerOptions } = require("./tsconfig");
3+
4+
export default {
5+
roots: ['<rootDir>/app', '<rootDir>/test/jest'],
6+
collectCoverage: true,
7+
coverageDirectory: 'coverage',
8+
coverageProvider: 'v8',
9+
transform: {
10+
'^.+\\.tsx?$': 'ts-jest',
11+
},
12+
moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, { prefix: '<rootDir>/' } ),
13+
14+
testPathIgnorePatterns: [
15+
'/node_modules/',
16+
'/dist/', // Ignore the output directory
17+
'/build/', // Ignore any build directory if used
18+
'\\.js$', // Ignore .js test files if they are in the same directories as .ts tests
19+
],
20+
21+
// Optionally specify testMatch to explicitly look for only TypeScript files
22+
testMatch: ["**/?(*.)+(spec|test).ts?(x)"], // Only `.ts` and `.tsx` files
23+
};

0 commit comments

Comments
 (0)