mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
refactor test for readability
This commit is contained in:
parent
4dd9a7c3b2
commit
b2205f03db
@ -1,13 +1,22 @@
|
|||||||
import { Item, GildedRose } from "@/gilded-rose";
|
import { Item, GildedRose } from "@/gilded-rose";
|
||||||
|
|
||||||
|
const generalItem = (sellIn: number, quality: number) =>
|
||||||
|
new Item("foo", sellIn, quality);
|
||||||
|
const ageableItem = (sellIn: number, quality: number) =>
|
||||||
|
new Item("Aged Brie", sellIn, quality);
|
||||||
|
const legendaryItem = (sellIn: number, quality: number) =>
|
||||||
|
new Item("Sulfuras, Hand of Ragnaros", sellIn, quality);
|
||||||
|
const backstagePassItem = (sellIn: number, quality: number) =>
|
||||||
|
new Item("Backstage passes to a TAFKAL80ETC concert", sellIn, quality);
|
||||||
|
|
||||||
describe("Gilded Rose", () => {
|
describe("Gilded Rose", () => {
|
||||||
it("should degrade quality", () => {
|
it("should degrade quality", () => {
|
||||||
const gildedRose = new GildedRose([new Item("foo", 1, 1)]);
|
const gildedRose = new GildedRose([generalItem(1, 1)]);
|
||||||
const items = gildedRose.updateQuality();
|
const items = gildedRose.updateQuality();
|
||||||
expect(items[0].quality).toBe(0);
|
expect(items[0].quality).toBe(0);
|
||||||
});
|
});
|
||||||
it("should tick down sell in", () => {
|
it("should tick down sell in", () => {
|
||||||
const gildedRose = new GildedRose([new Item("foo", 1, 1)]);
|
const gildedRose = new GildedRose([generalItem(1, 1)]);
|
||||||
const items = gildedRose.updateQuality();
|
const items = gildedRose.updateQuality();
|
||||||
expect(items[0].sellIn).toBe(0);
|
expect(items[0].sellIn).toBe(0);
|
||||||
});
|
});
|
||||||
@ -26,72 +35,62 @@ describe("Gilded Rose", () => {
|
|||||||
expect(items[1].sellIn).toBe(1);
|
expect(items[1].sellIn).toBe(1);
|
||||||
});
|
});
|
||||||
it("should degrade twice as fast past sell in date", () => {
|
it("should degrade twice as fast past sell in date", () => {
|
||||||
const gildedRose = new GildedRose([new Item("foo", 0, 3)]);
|
const gildedRose = new GildedRose([generalItem(0, 3)]);
|
||||||
const items = gildedRose.updateQuality();
|
const items = gildedRose.updateQuality();
|
||||||
expect(items[0].sellIn).toBe(-1);
|
expect(items[0].sellIn).toBe(-1);
|
||||||
expect(items[0].quality).toBe(1);
|
expect(items[0].quality).toBe(1);
|
||||||
});
|
});
|
||||||
it("should not have negative quality for expired items", () => {
|
it("should not have negative quality for expired items", () => {
|
||||||
const gildedRose = new GildedRose([new Item("foo", 0, 0)]);
|
const gildedRose = new GildedRose([generalItem(0, 0)]);
|
||||||
const items = gildedRose.updateQuality();
|
const items = gildedRose.updateQuality();
|
||||||
expect(items[0].sellIn).toBe(-1);
|
expect(items[0].sellIn).toBe(-1);
|
||||||
expect(items[0].quality).toBe(0);
|
expect(items[0].quality).toBe(0);
|
||||||
});
|
});
|
||||||
it("should not have negative quality for non expired items", () => {
|
it("should not have negative quality for non expired items", () => {
|
||||||
const gildedRose = new GildedRose([new Item("foo", 1, 0)]);
|
const gildedRose = new GildedRose([generalItem(1, 0)]);
|
||||||
const items = gildedRose.updateQuality();
|
const items = gildedRose.updateQuality();
|
||||||
expect(items[0].sellIn).toBe(0);
|
expect(items[0].sellIn).toBe(0);
|
||||||
expect(items[0].quality).toBe(0);
|
expect(items[0].quality).toBe(0);
|
||||||
});
|
});
|
||||||
it("should tick up quality for Aged Brie", () => {
|
it("should tick up quality for Aged Brie", () => {
|
||||||
const gildedRose = new GildedRose([new Item("Aged Brie", 1, 0)]);
|
const gildedRose = new GildedRose([ageableItem(1, 0)]);
|
||||||
const items = gildedRose.updateQuality();
|
const items = gildedRose.updateQuality();
|
||||||
expect(items[0].sellIn).toBe(0);
|
expect(items[0].sellIn).toBe(0);
|
||||||
expect(items[0].quality).toBe(1);
|
expect(items[0].quality).toBe(1);
|
||||||
});
|
});
|
||||||
it("should not exceed a quality of 50", () => {
|
it("should not exceed a quality of 50", () => {
|
||||||
const gildedRose = new GildedRose([new Item("Aged Brie", 1, 50)]);
|
const gildedRose = new GildedRose([ageableItem(1, 50)]);
|
||||||
const items = gildedRose.updateQuality();
|
const items = gildedRose.updateQuality();
|
||||||
expect(items[0].sellIn).toBe(0);
|
expect(items[0].sellIn).toBe(0);
|
||||||
expect(items[0].quality).toBe(50);
|
expect(items[0].quality).toBe(50);
|
||||||
});
|
});
|
||||||
it("should not tick down sell in or quality if the item is Sulfuras", () => {
|
it("should not tick down sell in or quality if the item is Sulfuras", () => {
|
||||||
const gildedRose = new GildedRose([
|
const gildedRose = new GildedRose([legendaryItem(1, 2)]);
|
||||||
new Item("Sulfuras, Hand of Ragnaros", 1, 2),
|
|
||||||
]);
|
|
||||||
const items = gildedRose.updateQuality();
|
const items = gildedRose.updateQuality();
|
||||||
expect(items[0].sellIn).toBe(1);
|
expect(items[0].sellIn).toBe(1);
|
||||||
expect(items[0].quality).toBe(2);
|
expect(items[0].quality).toBe(2);
|
||||||
});
|
});
|
||||||
describe("backstage pass", () => {
|
describe("backstage pass", () => {
|
||||||
it("should tick up quality with more than 10 days of sell in", () => {
|
it("should tick up quality with more than 10 days of sell in", () => {
|
||||||
const gildedRose = new GildedRose([
|
const gildedRose = new GildedRose([backstagePassItem(11, 2)]);
|
||||||
new Item("Backstage passes to a TAFKAL80ETC concert", 11, 2),
|
|
||||||
]);
|
|
||||||
const items = gildedRose.updateQuality();
|
const items = gildedRose.updateQuality();
|
||||||
expect(items[0].sellIn).toBe(10);
|
expect(items[0].sellIn).toBe(10);
|
||||||
expect(items[0].quality).toBe(3);
|
expect(items[0].quality).toBe(3);
|
||||||
});
|
});
|
||||||
it("should tick up quality twice with less than 10 days of sell in", () => {
|
it("should tick up quality twice with less than 10 days of sell in", () => {
|
||||||
const gildedRose = new GildedRose([
|
const gildedRose = new GildedRose([backstagePassItem(10, 2)]);
|
||||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 2),
|
|
||||||
]);
|
|
||||||
const items = gildedRose.updateQuality();
|
const items = gildedRose.updateQuality();
|
||||||
expect(items[0].sellIn).toBe(9);
|
expect(items[0].sellIn).toBe(9);
|
||||||
expect(items[0].quality).toBe(4);
|
expect(items[0].quality).toBe(4);
|
||||||
});
|
});
|
||||||
it("should tick up quality thrice with less than 5 days of sell in", () => {
|
it("should tick up quality thrice with less than 5 days of sell in", () => {
|
||||||
const gildedRose = new GildedRose([
|
const gildedRose = new GildedRose([backstagePassItem(5, 2)]);
|
||||||
new Item("Backstage passes to a TAFKAL80ETC concert", 5, 2),
|
|
||||||
]);
|
|
||||||
const items = gildedRose.updateQuality();
|
const items = gildedRose.updateQuality();
|
||||||
expect(items[0].sellIn).toBe(4);
|
expect(items[0].sellIn).toBe(4);
|
||||||
expect(items[0].quality).toBe(5);
|
expect(items[0].quality).toBe(5);
|
||||||
});
|
});
|
||||||
it("should have 0 quality when sell in date has passed", () => {
|
it("should have 0 quality when sell in date has passed", () => {
|
||||||
const gildedRose = new GildedRose([
|
const gildedRose = new GildedRose([backstagePassItem(0, 2)]);
|
||||||
new Item("Backstage passes to a TAFKAL80ETC concert", 0, 2),
|
|
||||||
]);
|
|
||||||
const items = gildedRose.updateQuality();
|
const items = gildedRose.updateQuality();
|
||||||
expect(items[0].sellIn).toBe(-1);
|
expect(items[0].sellIn).toBe(-1);
|
||||||
expect(items[0].quality).toBe(0);
|
expect(items[0].quality).toBe(0);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user