diff --git a/js-jest/src/gilded_rose.js b/js-jest/src/gilded_rose.js index 48746965..0fac2b1e 100644 --- a/js-jest/src/gilded_rose.js +++ b/js-jest/src/gilded_rose.js @@ -1,16 +1,35 @@ class Item { - constructor(name, sellIn, quality){ + constructor(name, sellIn, quality) { this.name = name; this.sellIn = sellIn; this.quality = quality; } } +class Rules { + constructor(dailyQualityChangeValue, maxQuality, minQuality, tenDayChange, fiveDayChange, + isZeroDayQualityDrop, zeroDayQualityValue) { + this.dailyQualityChangeValue = dailyQualityChangeValue; + this.maxQuality = maxQuality; + this.minQuality = minQuality; + this.tenDayChange = tenDayChange; + this.fiveDayChange = fiveDayChange; + this.isZeroDayQualityDrop = isZeroDayQualityDrop; + this.zeroDayQualityValue = zeroDayQualityValue; + } +} + class Shop { - constructor(items=[]){ + constructor(items = []) { this.items = items; } + + updateQuality() { + const rules = { + 'Aged Brie': new Rules(1, 50, 0, 1, 1), + 'Backstage passes to a TAFKAL80ETC concert': new Rules(1, 50, 0) + } 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) { diff --git a/js-jest/test/gilded_rose.test.js b/js-jest/test/gilded_rose.test.js index c8e0e3d7..efc04800 100644 --- a/js-jest/test/gilded_rose.test.js +++ b/js-jest/test/gilded_rose.test.js @@ -1,9 +1,23 @@ -const {Shop, Item} = require("../src/gilded_rose"); +const { Shop, Item } = require("../src/gilded_rose"); -describe("Gilded Rose", function() { - it("should foo", function() { +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"); + expect(items[0].name).toBe("foo"); + }); + + it("Aged Brie test", function () { + const items = [ + new Item("Aged Brie", 2, 0), + ]; + const gildedRose = new Shop(items); + for (let day = 0; day < 4; day++) { + console.log(`\n-------- day ${day} --------`); + console.log("name, sellIn, quality"); + items.forEach(item => console.log(`${item.name}, ${item.sellIn}, ${item.quality}`)); + gildedRose.updateQuality(); + } + expect(items[0].name).toBe("Aged Brie"); }); });