mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
Merge pull request #126 from jsstrn/master
Add Gilded Rose kata for JavaScript with Jest
This commit is contained in:
commit
f322e6eb1b
1
js-jest/.gitignore
vendored
Normal file
1
js-jest/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
/node_modules/
|
||||||
31
js-jest/README.md
Normal file
31
js-jest/README.md
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
# Gilded Rose
|
||||||
|
|
||||||
|
This is the Gilded Rose kata in JavaScript with Jest
|
||||||
|
|
||||||
|
## Getting started
|
||||||
|
|
||||||
|
Install dependencies
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
## Running tests
|
||||||
|
|
||||||
|
To run all tests
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm test
|
||||||
|
```
|
||||||
|
|
||||||
|
To run all tests in watch mode
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run test:watch
|
||||||
|
```
|
||||||
|
|
||||||
|
To generate test coverage report
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm run test:coverage
|
||||||
|
```
|
||||||
4879
js-jest/package-lock.json
generated
Normal file
4879
js-jest/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
28
js-jest/package.json
Normal file
28
js-jest/package.json
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
{
|
||||||
|
"name": "gilded-rose-kata",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Gilded Rose kata in JavaScript with Jest",
|
||||||
|
"scripts": {
|
||||||
|
"test": "jest",
|
||||||
|
"test:watch": "jest --watch",
|
||||||
|
"test:coverage": "jest --coverage"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/emilybache/GildedRose-Refactoring-Kata.git"
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"kata",
|
||||||
|
"refactor",
|
||||||
|
"gilded-rose"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"private": true,
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/emilybache/GildedRose-Refactoring-Kata/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/emilybache/GildedRose-Refactoring-Kata",
|
||||||
|
"devDependencies": {
|
||||||
|
"jest": "^24.9.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
67
js-jest/src/gilded_rose.js
Normal file
67
js-jest/src/gilded_rose.js
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
class Item {
|
||||||
|
constructor(name, sellIn, quality){
|
||||||
|
this.name = name;
|
||||||
|
this.sellIn = sellIn;
|
||||||
|
this.quality = quality;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Shop {
|
||||||
|
constructor(items=[]){
|
||||||
|
this.items = items;
|
||||||
|
}
|
||||||
|
updateQuality() {
|
||||||
|
for (let i = 0; i < this.items.length; i++) {
|
||||||
|
if (this.items[i].name != 'Aged Brie' && this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||||
|
if (this.items[i].quality > 0) {
|
||||||
|
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
|
||||||
|
this.items[i].quality = this.items[i].quality - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.items[i].quality < 50) {
|
||||||
|
this.items[i].quality = this.items[i].quality + 1;
|
||||||
|
if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') {
|
||||||
|
if (this.items[i].sellIn < 11) {
|
||||||
|
if (this.items[i].quality < 50) {
|
||||||
|
this.items[i].quality = this.items[i].quality + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.items[i].sellIn < 6) {
|
||||||
|
if (this.items[i].quality < 50) {
|
||||||
|
this.items[i].quality = this.items[i].quality + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
|
||||||
|
this.items[i].sellIn = this.items[i].sellIn - 1;
|
||||||
|
}
|
||||||
|
if (this.items[i].sellIn < 0) {
|
||||||
|
if (this.items[i].name != 'Aged Brie') {
|
||||||
|
if (this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||||
|
if (this.items[i].quality > 0) {
|
||||||
|
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
|
||||||
|
this.items[i].quality = this.items[i].quality - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.items[i].quality = this.items[i].quality - this.items[i].quality;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (this.items[i].quality < 50) {
|
||||||
|
this.items[i].quality = this.items[i].quality + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.items;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
Item,
|
||||||
|
Shop
|
||||||
|
}
|
||||||
9
js-jest/test/gilded_rose.test.js
Normal file
9
js-jest/test/gilded_rose.test.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
const {Shop, Item} = require("../src/gilded_rose");
|
||||||
|
|
||||||
|
describe("Gilded Rose", function() {
|
||||||
|
it("should foo", function() {
|
||||||
|
const gildedRose = new Shop([new Item("foo", 0, 0)]);
|
||||||
|
const items = gildedRose.updateQuality();
|
||||||
|
expect(items[0].name).toBe("fixme");
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user