mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
Added update quality logic
This commit is contained in:
parent
dfda89c474
commit
4d82127c01
@ -1,5 +1,5 @@
|
|||||||
class Item {
|
class Item {
|
||||||
constructor(name, sellIn, quality){
|
constructor(name, sellIn, quality) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.sellIn = sellIn;
|
this.sellIn = sellIn;
|
||||||
this.quality = quality;
|
this.quality = quality;
|
||||||
@ -12,15 +12,19 @@ class ItemUpdater {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateQuality() {
|
updateQuality() {
|
||||||
|
if (this.item.quality > 0 && this.item.quality <= 50) {
|
||||||
|
this.item.quality = this.item.quality - 1;
|
||||||
|
}
|
||||||
return this.item;
|
return this.item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Shop {
|
class Shop {
|
||||||
constructor(items=[]){
|
constructor(items = []) {
|
||||||
this.items = items;
|
this.items = items;
|
||||||
}
|
}
|
||||||
updateQuality() {
|
updateQuality() {
|
||||||
|
|
||||||
for (let i = 0; i < this.items.length; i++) {
|
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].name != 'Aged Brie' && this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||||
if (this.items[i].quality > 0) {
|
if (this.items[i].quality > 0) {
|
||||||
|
|||||||
@ -9,9 +9,16 @@ describe("Gilded Rose", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("Gilded Rose check common rules", function () {
|
describe("Gilded Rose check common rules", function () {
|
||||||
it("should foo", function () {
|
it("Item quality should decrease by one", function () {
|
||||||
const gildedRose = new ItemUpdater(new Item("Aged Brie", 10, 0));
|
const gildedRose = new ItemUpdater(new Item("+5 Dexterity Vest", 10, 20));
|
||||||
const item = gildedRose.updateQuality();
|
const item = gildedRose.updateQuality();
|
||||||
expect(item.quality).toBe(10);
|
expect(item.quality).toBe(19);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
it("Item quality should not decrease by one", function () {
|
||||||
|
const gildedRose = new ItemUpdater(new Item("+5 Dexterity Vest", 10, 0));
|
||||||
|
const item = gildedRose.updateQuality();
|
||||||
|
expect(item.quality).toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
Loading…
Reference in New Issue
Block a user