Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Last active April 3, 2025 18:37
Show Gist options
  • Save trikitrok/44d7395be58754ed537bbb1dd2bb6eef to your computer and use it in GitHub Desktop.
Save trikitrok/44d7395be58754ed537bbb1dd2bb6eef to your computer and use it in GitHub Desktop.
legacy argent rose code including Lanzarote Wine
export class ArgentRoseStore
// ...
private updateQuality(product: Product): void {
if (product.isTheatrePasses()) {
if (product.sellIn < 0) {
product.dropQualityToMinimum();
} else if (product.sellIn < 5) {
product.increaseQualityBy(3);
} else {
product.increaseQualityBy(1);
}
} else if (product.isLanzaroteWine()) {
product.increaseQualityBy(2);
} else {
product.decreaseQualityBy(2);
}
}
/// ....
}
export class Product {
/// ...
isLanzaroteWine() {
return this.description === "Lanzarote Wine";
}
/// ...
}
it("Lanzarote Wine increases quality by one", async () => {
const store = storeIncluding(lanzaroteWine(3, 10));
await store.update();
expect(store.getSavedInventory()).toEqual(inventoryIncluding(lanzaroteWine(2, 12)));
});
it("Expired Lanzarote Wine increases quality twice as fast", async () => {
const store = storeIncluding(lanzaroteWine(-5, 10));
await store.update();
expect(store.getSavedInventory()).toEqual(inventoryIncluding(lanzaroteWine(-6, 14)));
});
function lanzaroteWine(sellIn: number, quality: number): Product {
return new Product("Lanzarote Wine", sellIn, quality);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment