mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Added All test cases for the items including Conjured item
This commit is contained in:
parent
388c67b7c7
commit
577e92e699
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
33
js-jest/src/item_updaters/backstage_passes_updater.js
Normal file
33
js-jest/src/item_updaters/backstage_passes_updater.js
Normal file
@ -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
|
||||
}
|
||||
22
js-jest/src/item_updaters/conjured_updater.js
Normal file
22
js-jest/src/item_updaters/conjured_updater.js
Normal file
@ -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
|
||||
}
|
||||
16
js-jest/src/item_updaters/sulfuras_updater.js
Normal file
16
js-jest/src/item_updaters/sulfuras_updater.js
Normal file
@ -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
|
||||
}
|
||||
@ -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 = [
|
||||
|
||||
Loading…
Reference in New Issue
Block a user