Skip to content

Instantly share code, notes, and snippets.

@trikitrok
Created March 28, 2025 13:00
Show Gist options
  • Save trikitrok/58257f78b688afcbe07bc500f86c6ccb to your computer and use it in GitHub Desktop.
Save trikitrok/58257f78b688afcbe07bc500f86c6ccb to your computer and use it in GitHub Desktop.
Legacy Argent Rose tests with 100% coverage but some mutants still alive
import {ArgentRoseStore} from "../src/ArgentRoseStore";
import {Product} from "../src/Product";
describe("ArgentRoseStore", () => {
it("Regular Product decreases quality by two", async () => {
const store = storeIncluding(regularProduct(5, 10));
await store.update();
expect(store.getSavedInventory()).toEqual(inventoryIncluding(regularProduct(4, 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("Theatre Passes increase quality by three when sell-in is near", async () => {
const store = storeIncluding(theatrePasses(3, 12));
await store.update();
expect(store.getSavedInventory()).toEqual(inventoryIncluding(theatrePasses(2, 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(9, 12));
await store.update();
expect(store.getSavedInventory()).toEqual(inventoryIncluding(theatrePasses(8, 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