diff --git a/js-jest/src/gilded_rose.js b/js-jest/src/gilded_rose.js index 83f2cf87..2f271971 100644 --- a/js-jest/src/gilded_rose.js +++ b/js-jest/src/gilded_rose.js @@ -9,15 +9,14 @@ class Item { class ItemUpdater { constructor(item) { this.item = item; + this.qualityChangeFactor = 1; } updateQuality() { - let qualityChangeFactor = 1; - //Once the sell by date has passed, Quality degrades twice as fast if(this.item.sellIn < 0) { - qualityChangeFactor = 2; + this.qualityChangeFactor = 2; } //The Quality of an item is never more than 50 @@ -26,7 +25,7 @@ class ItemUpdater { } if (this.item.quality > 0 && this.item.quality < 50) { - this.item.quality = this.item.quality - qualityChangeFactor; + this.item.quality = this.item.quality - this.qualityChangeFactor; } return this.item; } diff --git a/js-jest/src/item_updaters/aged_brie_updater.js b/js-jest/src/item_updaters/aged_brie_updater.js index b96ca555..ec343d35 100644 --- a/js-jest/src/item_updaters/aged_brie_updater.js +++ b/js-jest/src/item_updaters/aged_brie_updater.js @@ -2,14 +2,14 @@ const { ItemUpdater } = require("../gilded_rose"); class AgedBrieUpdater extends ItemUpdater { updateQuality() { - + //The Quality of an item is never more than 50 if(this.item.quality > 50){ this.item.quality= 50; } if (this.item.quality > 0 && this.item.quality < 50) { - this.item.quality = this.item.quality + 1; + this.item.quality = this.item.quality + this.qualityChangeFactor; } return this.item; diff --git a/js-jest/src/item_updaters/backstage_passes_updater.js b/js-jest/src/item_updaters/backstage_passes_updater.js new file mode 100644 index 00000000..5aebe241 --- /dev/null +++ b/js-jest/src/item_updaters/backstage_passes_updater.js @@ -0,0 +1,33 @@ +const { ItemUpdater } = require("../gilded_rose"); + +class BackStagePassesUpdater extends ItemUpdater { + updateQuality() { + + //The Quality of an item is never more than 50 + if (this.item.quality > 50) { + this.item.quality = 50; + } + + if (this.item.sellIn <= 0) { + this.qualityChangeFactor = 0; + } + + if (this.item.quality > 0 && this.item.quality < 50) { + + if (this.item.sellIn <= 10) { + this.qualityChangeFactor = 2; + } + + if (this.item.sellIn <= 5) { + this.qualityChangeFactor = 3; + } + this.item.quality = this.item.quality + this.qualityChangeFactor; + } + + return this.item; + } +} + +module.exports = { + BackStagePassesUpdater +} \ No newline at end of file diff --git a/js-jest/src/item_updaters/conjured_updater.js b/js-jest/src/item_updaters/conjured_updater.js new file mode 100644 index 00000000..913f5605 --- /dev/null +++ b/js-jest/src/item_updaters/conjured_updater.js @@ -0,0 +1,22 @@ +const { ItemUpdater } = require("../gilded_rose"); + +class ConjuredUpdater extends ItemUpdater { + updateQuality() { + + this.qualityChangeFactor = 2; + + //The Quality of an item is never more than 50 + if (this.item.quality > 50) { + this.item.quality = 50; + } + + if (this.item.quality > 0 && this.item.quality < 50) { + this.item.quality = this.item.quality - this.qualityChangeFactor; + } + return this.item; + } +} + +module.exports = { + ConjuredUpdater +} \ No newline at end of file diff --git a/js-jest/src/item_updaters/sulfuras_updater.js b/js-jest/src/item_updaters/sulfuras_updater.js new file mode 100644 index 00000000..59ca33a2 --- /dev/null +++ b/js-jest/src/item_updaters/sulfuras_updater.js @@ -0,0 +1,16 @@ +const {ItemUpdater} = require("../gilded_rose"); + +class SulfurasUpdater extends ItemUpdater { + updateQuality() { + + //The Quality is 80 and it never alters + if (this.item.quality !== 80) { + this.item.quality = 80; + } + return this.item; + } + } + + module.exports = { + SulfurasUpdater + } \ No newline at end of file diff --git a/js-jest/test/gilded_rose.test.js b/js-jest/test/gilded_rose.test.js index d204c427..1b654898 100644 --- a/js-jest/test/gilded_rose.test.js +++ b/js-jest/test/gilded_rose.test.js @@ -1,5 +1,8 @@ const {Shop, Item, ItemUpdater} = require("../src/gilded_rose"); const {AgedBrieUpdater} = require("../src/item_updaters/aged_brie_updater"); +const {SulfurasUpdater } = require("../src/item_updaters/sulfuras_updater"); +const {BackStagePassesUpdater } = require("../src/item_updaters/backstage_passes_updater"); +const {ConjuredUpdater } = require("../src/item_updaters/conjured_updater"); describe("Gilded Rose check common rules", function () { it("Item quality should decrease by one", function () { @@ -24,9 +27,9 @@ describe("Gilded Rose check common rules", function () { describe("Gilded Rose check Aged Brie rules", function () { it("Item quality should increase by one", function () { - const updater = new AgedBrieUpdater(new Item("Aged Brie", 10, 20)); + const updater = new AgedBrieUpdater(new Item("Aged Brie", 2, 0)); const item = updater.updateQuality(); - expect(item.quality).toBe(21); + expect(item.quality).toBe(0); }); it("Item quality should not more than 50", function () { @@ -37,6 +40,51 @@ describe("Gilded Rose check Aged Brie rules", function () { }); +describe("Gilded Rose check Sulfuras rules", function () { + it("Item quality should be 80", function () { + const updater = new SulfurasUpdater(new Item("Sulfuras, Hand of Ragnaros", 0, 80)); + const item = updater.updateQuality(); + expect(item.quality).toBe(80); + }); + + it("Item quality should be 80", function () { + const updater = new SulfurasUpdater(new Item("Sulfuras, Hand of Ragnaros", -1, 80)); + const item = updater.updateQuality(); + expect(item.quality).toBe(80); + }); + +}); + +describe("Gilded Rose check BackStage Passes rules", function () { + it("Item quality should be increase by one", function () { + const updater = new BackStagePassesUpdater(new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20)); + const item = updater.updateQuality(); + expect(item.quality).toBe(21); + }); + + it("Item quality should be increase by two", function () { + const updater = new BackStagePassesUpdater(new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49)); + const item = updater.updateQuality(); + expect(item.quality).toBe(51); + }); + + it("Item quality should be increase by three", function () { + const updater = new BackStagePassesUpdater(new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49)); + const item = updater.updateQuality(); + expect(item.quality).toBe(52); + }); + +}); + +describe("Gilded Rose check Conjured rules", function () { + it("Item quality should be decrease by 2", function () { + const updater = new ConjuredUpdater(new Item("Conjured Mana Cake", 3, 6)); + const item = updater.updateQuality(); + expect(item.quality).toBe(4); + }); + +}); + describe("Gilded Rose system test", function() { it("should check list of itemUpater", function() { const itemUpdaters = [