Created
March 28, 2025 13:15
-
-
Save trikitrok/2f8389c5237c93b46cb24b8ae7a86f0e to your computer and use it in GitHub Desktop.
Legacy Argent Rose tests with no mutants alive but not covering the loop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {ArgentRoseStore} from "../src/ArgentRoseStore"; | |
import {Product} from "../src/Product"; | |
describe("ArgentRoseStore", () => { | |
it("Regular Product decreases quality by two", async () => { | |
const store = storeIncluding(regularProduct(1, 10)); | |
await store.update(); | |
expect(store.getSavedInventory()).toEqual(inventoryIncluding(regularProduct(0, 8))); | |
}); | |
it("Expired Regular Product decreases quality twice as fast", async () => { | |
const store = storeIncluding(regularProduct(0, 10)); | |
await store.update(); | |
expect(store.getSavedInventory()).toEqual(inventoryIncluding(regularProduct(-1, 6))); | |
}); | |
it("Regular Product quality is never below the minimum quality", async () => { | |
const store = storeIncluding(regularProduct(2, 1)); | |
await store.update(); | |
expect(store.getSavedInventory()).toEqual(inventoryIncluding(regularProduct(1, 0))); | |
}); | |
it("Expired Regular Product quality is never below the minimum quality", async () => { | |
const store = storeIncluding(regularProduct(0, 3)); | |
await store.update(); | |
expect(store.getSavedInventory()).toEqual(inventoryIncluding(regularProduct(-1, 0))); | |
}); | |
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(0, 10)); | |
await store.update(); | |
expect(store.getSavedInventory()).toEqual(inventoryIncluding(lanzaroteWine(-1, 14))); | |
}); | |
it("Lanzarote Wine quality never increases over the maximum quality", async () => { | |
const store = storeIncluding(lanzaroteWine(3, 50)); | |
await store.update(); | |
expect(store.getSavedInventory()).toEqual(inventoryIncluding(lanzaroteWine(2, 50))); | |
}); | |
it("Expired Lanzarote Wine quality never increases over the maximum quality", async () => { | |
const store = storeIncluding(lanzaroteWine(0, 50)); | |
await store.update(); | |
expect(store.getSavedInventory()).toEqual(inventoryIncluding(lanzaroteWine(-1, 50))); | |
}); | |
it("Expired Theatre Passes' quality drops to zero", async () => { | |
const store = storeIncluding(theatrePasses(0, 5)); | |
await store.update(); | |
expect(store.getSavedInventory()).toEqual(inventoryIncluding(theatrePasses(-1, 0))); | |
}); | |
it.each([1, 5])( | |
"Theatre Passes increase quality by three when sell-in is near (sellIn: %i)", | |
async (sellIn) => { | |
const store = storeIncluding(theatrePasses(sellIn, 12)); | |
await store.update(); | |
expect(store.getSavedInventory()).toEqual( | |
inventoryIncluding(theatrePasses(sellIn - 1, 15)) | |
); | |
} | |
); | |
it("Theatre Pass quality never increases over the maximum quality when sell-in is near", async () => { | |
const store = storeIncluding(theatrePasses(2, 48)); | |
await store.update(); | |
expect(store.getSavedInventory()).toEqual(inventoryIncluding(theatrePasses(1, 50))); | |
}); | |
it("Theatre Passes increase quality by one when sell-in is far away", async () => { | |
const store = storeIncluding(theatrePasses(6, 12)); | |
await store.update(); | |
expect(store.getSavedInventory()).toEqual(inventoryIncluding(theatrePasses(5, 13))); | |
}); | |
it("Theatre Pass quality never increases over the maximum quality when sell-in is far away", async () => { | |
const store = storeIncluding(theatrePasses(9, 50)); | |
await store.update(); | |
expect(store.getSavedInventory()).toEqual(inventoryIncluding(theatrePasses(8, 50))); | |
}); | |
function regularProduct(sellIn: number, quality: number): Product { | |
return new Product("Regular Product", sellIn, quality); | |
} | |
function lanzaroteWine(sellIn: number, quality: number): Product { | |
return new Product("Lanzarote Wine", sellIn, quality); | |
} | |
function theatrePasses(sellIn: number, quality: number): Product { | |
return new Product("Theatre Passes", sellIn, quality); | |
} | |
function storeIncluding(...products: Product[]): ArgentRoseStoreForTesting { | |
return new ArgentRoseStoreForTesting(products); | |
} | |
function inventoryIncluding(...products: Product[]): Product[] { | |
return products; | |
} | |
}); | |
export class ArgentRoseStoreForTesting extends ArgentRoseStore { | |
private savedInventory: Product[]; | |
private readonly initialInventory: Product[]; | |
constructor(initialInventory: Product[]) { | |
super(); | |
this.savedInventory = []; | |
this.initialInventory = initialInventory; | |
} | |
getSavedInventory(): Product[] { | |
return this.savedInventory; | |
} | |
protected async saveInventoryToDb(inventory: Product[]): Promise<void> { | |
this.savedInventory = inventory; | |
} | |
protected async getInventoryFromDB(): Promise<Product[]> { | |
return this.initialInventory; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment