mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Added quality factor for the sellIn date and separate item updater classes
This commit is contained in:
parent
5a6a648d8a
commit
388c67b7c7
@ -12,8 +12,21 @@ class ItemUpdater {
|
||||
}
|
||||
|
||||
updateQuality() {
|
||||
if (this.item.quality > 0 && this.item.quality <= 50) {
|
||||
this.item.quality = this.item.quality - 1;
|
||||
|
||||
let qualityChangeFactor = 1;
|
||||
|
||||
//Once the sell by date has passed, Quality degrades twice as fast
|
||||
if(this.item.sellIn < 0) {
|
||||
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 - qualityChangeFactor;
|
||||
}
|
||||
return this.item;
|
||||
}
|
||||
|
||||
21
js-jest/src/item_updaters/aged_brie_updater.js
Normal file
21
js-jest/src/item_updaters/aged_brie_updater.js
Normal file
@ -0,0 +1,21 @@
|
||||
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;
|
||||
}
|
||||
|
||||
return this.item;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
AgedBrieUpdater
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
const {Shop, Item, ItemUpdater} = require("../src/gilded_rose");
|
||||
const {AgedBrieUpdater} = require("../src/item_updaters/aged_brie_updater");
|
||||
|
||||
describe("Gilded Rose check common rules", function () {
|
||||
it("Item quality should decrease by one", function () {
|
||||
@ -13,12 +14,34 @@ describe("Gilded Rose check common rules", function () {
|
||||
expect(item.quality).toBe(0);
|
||||
});
|
||||
|
||||
it("Item quality should decrease by two ", function () {
|
||||
const gildedRose = new ItemUpdater(new Item("+5 Dexterity Vest", -10, 20));
|
||||
const item = gildedRose.updateQuality();
|
||||
expect(item.quality).toBe(18);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
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 item = updater.updateQuality();
|
||||
expect(item.quality).toBe(21);
|
||||
});
|
||||
|
||||
it("Item quality should not more than 50", function () {
|
||||
const updater = new AgedBrieUpdater(new Item("Aged Brie", 10, 70));
|
||||
const item = updater.updateQuality();
|
||||
expect(item.quality).toBe(50);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe("Gilded Rose system test", function() {
|
||||
it("should check list of itemUpater", function() {
|
||||
const itemUpdaters = [
|
||||
new ItemUpdater(new Item("+5 Dexterity Vest", 10, 20)),
|
||||
new AgedBrieUpdater(new Item("Aged Brie", 2, 0)),
|
||||
];
|
||||
|
||||
const days = Number(process.argv[2]) || 2;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user