Events can take a waitlist for sold-out lines. When places free up (cancellation, smaller booking, higher stock limit) the next person is offered them with a claim link and the places are held for a set time; unclaimed offers expire and move on, with optional partial offers. Stock is now counted in one place (utils/stock.js), including held places, and manual registrations and booking edits are now stock-checked. Adds a supervisor waitlist page, My Events waitlists, and the daily summary count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32 lines
995 B
JavaScript
32 lines
995 B
JavaScript
const { pickOffers } = require('../src/utils/waitlist');
|
|
|
|
const q = (...qs) => qs.map((quantity, i) => ({ id: `e${i + 1}`, quantity }));
|
|
|
|
describe('pickOffers', () => {
|
|
test('offers people in order while places last', () => {
|
|
expect(pickOffers(q(1, 2, 1), 3, true)).toEqual([
|
|
{ entryId: 'e1', quantity: 1 },
|
|
{ entryId: 'e2', quantity: 2 },
|
|
]);
|
|
});
|
|
|
|
test('nothing free, no offers', () => {
|
|
expect(pickOffers(q(1), 0, true)).toEqual([]);
|
|
});
|
|
|
|
test('partial offers: the first in line gets what is free, nobody jumps ahead', () => {
|
|
expect(pickOffers(q(3, 1), 2, true)).toEqual([{ entryId: 'e1', quantity: 2 }]);
|
|
});
|
|
|
|
test('without partial offers, skips to the next person who fits', () => {
|
|
expect(pickOffers(q(3, 1, 1), 2, false)).toEqual([
|
|
{ entryId: 'e2', quantity: 1 },
|
|
{ entryId: 'e3', quantity: 1 },
|
|
]);
|
|
});
|
|
|
|
test('without partial offers, nobody fits', () => {
|
|
expect(pickOffers(q(3, 4), 2, false)).toEqual([]);
|
|
});
|
|
});
|