Make "Buy again" add the item to the basket
The order status view now carries each item's menu item id and the ids of its current Options matching the ordered ones by name, since editing a Menu Item recreates its Options under new ids. Options no longer on the menu are left out. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -698,6 +698,64 @@ describe('kitchen simulation', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('buying an item again', () => {
|
||||
const pizzaOption = (name: string) =>
|
||||
seed.menuItemOptions.pizza.find((option) => option.name === name)!
|
||||
|
||||
it("offers the Menu Item's current Options matching the ones ordered", async () => {
|
||||
const order = await placeGuestOrder([
|
||||
{
|
||||
menuItemId: seed.menuItems.pizza.id,
|
||||
selectedOptionIds: [
|
||||
pizzaOption('Extra cheese').id,
|
||||
pizzaOption('No onions').id,
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
const [item] = (await getStatus(order)).items
|
||||
expect(item.menuItemId).toBe(seed.menuItems.pizza.id)
|
||||
expect(item.buyAgainOptionIds).toEqual(
|
||||
expect.arrayContaining([
|
||||
pizzaOption('Extra cheese').id,
|
||||
pizzaOption('No onions').id,
|
||||
]),
|
||||
)
|
||||
expect(item.buyAgainOptionIds).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('leaves out an Option that is no longer on the menu', async () => {
|
||||
const order = await placeGuestOrder([
|
||||
{
|
||||
menuItemId: seed.menuItems.pizza.id,
|
||||
selectedOptionIds: [
|
||||
pizzaOption('Extra cheese').id,
|
||||
pizzaOption('No onions').id,
|
||||
],
|
||||
},
|
||||
])
|
||||
|
||||
const noOnionsEdit = eq(
|
||||
schema.menuItemOptions.id,
|
||||
pizzaOption('No onions').id,
|
||||
)
|
||||
await testDb.db
|
||||
.update(schema.menuItemOptions)
|
||||
.set({ name: 'Extra onions' })
|
||||
.where(noOnionsEdit)
|
||||
|
||||
try {
|
||||
const [item] = (await getStatus(order)).items
|
||||
expect(item.buyAgainOptionIds).toEqual([pizzaOption('Extra cheese').id])
|
||||
} finally {
|
||||
await testDb.db
|
||||
.update(schema.menuItemOptions)
|
||||
.set({ name: 'No onions' })
|
||||
.where(noOnionsEdit)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('recipe snapshot', () => {
|
||||
it("keeps an Order Item on the Recipe as it existed at order time, even if the Menu Item's live Recipe is edited afterwards", async () => {
|
||||
const order = await placeGuestOrder([
|
||||
|
||||
Reference in New Issue
Block a user