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([]); }); });