mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-16 06:51:27 +00:00
Updated updateQuantity function and test case file
This commit is contained in:
parent
181b48aff7
commit
3699ebb049
@ -12,51 +12,31 @@ class Shop {
|
||||
}
|
||||
updateQuality() {
|
||||
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) {
|
||||
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
|
||||
this.items[i].quality = this.items[i].quality - 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this.items[i].quality < 50) {
|
||||
this.items[i].quality = this.items[i].quality + 1;
|
||||
if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
if (this.items[i].sellIn < 11) {
|
||||
if (this.items[i].quality < 50) {
|
||||
this.items[i].quality = this.items[i].quality + 1;
|
||||
}
|
||||
|
||||
if(this.items[i].name !== 'Sulfuras') {
|
||||
if (this.items[i].name !== 'Aged Brie' && this.items[i].name !== 'Backstage passes') {
|
||||
if (this.items[i].sellIn <= 0) {
|
||||
if(this.items[i].name === 'Conjured' && this.items[i].quality - 4 > 0) {
|
||||
this.items[i].quality = this.items[i].quality - 4;
|
||||
} else if(this.items[i].quality - 2 > 0){
|
||||
this.items[i].quality = this.items[i].quality - 2;
|
||||
}
|
||||
if (this.items[i].sellIn < 6) {
|
||||
if (this.items[i].quality < 50) {
|
||||
this.items[i].quality = this.items[i].quality + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
|
||||
this.items[i].sellIn = this.items[i].sellIn - 1;
|
||||
}
|
||||
if (this.items[i].sellIn < 0) {
|
||||
if (this.items[i].name != 'Aged Brie') {
|
||||
if (this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') {
|
||||
if (this.items[i].quality > 0) {
|
||||
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
|
||||
this.items[i].quality = this.items[i].quality - 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.items[i].quality = this.items[i].quality - this.items[i].quality;
|
||||
}
|
||||
} else {
|
||||
if (this.items[i].quality < 50) {
|
||||
if ((this.items[i].sellIn <= 10 && this.items[i].sellIn >5) && this.items[i].quality + 2 <= 50) {
|
||||
this.items[i].quality = this.items[i].quality + 2;
|
||||
} else if ((this.items[i].sellIn <= 5 && this.items[i].sellIn > 0) && this.items[i].quality + 3 <= 50) {
|
||||
this.items[i].quality = this.items[i].quality + 3;
|
||||
} else if(this.items[i].quality < 50) {
|
||||
this.items[i].quality = this.items[i].quality + 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(this.items[i].quality < 80) {
|
||||
this.items[i].quality = 80;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.items;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,68 @@
|
||||
const {Shop, Item} = require("../src/gilded_rose");
|
||||
|
||||
describe("Gilded Rose", function() {
|
||||
it("should foo", function() {
|
||||
const gildedRose = new Shop([new Item("foo", 0, 0)]);
|
||||
describe("Gilded Rose with SellIn Zero", function() {
|
||||
it("Check Sulfuras quantity", function() {
|
||||
const gildedRose = new Shop([new Item("Sulfuras", 0, 78)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].name).toBe("fixme");
|
||||
expect(items[0].quality).toBe(80);
|
||||
})
|
||||
|
||||
it("Aged Brie to increase if SellIn is 0", function() {
|
||||
const gildedRose = new Shop([new Item("Aged Brie", 0, 20)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].quality).toBe(21);
|
||||
});
|
||||
|
||||
it("Other item to decrease twice if SellIn is 0", function() {
|
||||
const gildedRose = new Shop([new Item("Other item 1", 0, 20)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].quality).toBe(18);
|
||||
});
|
||||
|
||||
it("Conjured to decrease twice of normal items if SellIn is 0", function() {
|
||||
const gildedRose = new Shop([new Item("Conjured", 0, 20)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].quality).toBe(16);
|
||||
});
|
||||
|
||||
it("Backstage passes to increase if SellIn is 0", function() {
|
||||
const gildedRose = new Shop([new Item("Backstage passes", 0, 20)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].quality).toBe(21);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe("Gilded Rose with SellIn Non Zero", function() {
|
||||
it("Check Sulfuras quantity", function() {
|
||||
const gildedRose = new Shop([new Item("Sulfuras", 2, 78)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].quality).toBe(80);
|
||||
})
|
||||
|
||||
it("Aged Brie to increase if SellIn is 4", function() {
|
||||
const gildedRose = new Shop([new Item("Aged Brie", 4, 20)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].quality).toBe(23);
|
||||
});
|
||||
|
||||
it("Other item quantity no change if SellIn is greater than 0", function() {
|
||||
const gildedRose = new Shop([new Item("Other item 1", 5, 20)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].quality).toBe(20);
|
||||
});
|
||||
|
||||
it("Conjured quantity no change if SellIn is greater than 0", function() {
|
||||
const gildedRose = new Shop([new Item("Conjured", 6, 20)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].quality).toBe(20);
|
||||
});
|
||||
|
||||
it("Backstage passes to increase if SellIn is 8", function() {
|
||||
const gildedRose = new Shop([new Item("Backstage passes", 8, 20)]);
|
||||
const items = gildedRose.updateQuality();
|
||||
expect(items[0].quality).toBe(22);
|
||||
});
|
||||
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user