import { describe, expect, it } from 'vitest'; import { allInPrice, buyerPremium, feeScheduleFor, FEE_SCHEDULES } from './fees.js'; describe('buyer premium schedules (§35)', () => { it('finds houses by name, connector id and tolerant alias', () => { expect(feeScheduleFor("Sotheby's")?.id).toBe('sothebys'); expect(feeScheduleFor('bring-a-trailer')?.id).toBe('bring-a-trailer'); expect(feeScheduleFor("Sotheby's Hong Kong")?.id).toBe('sothebys'); expect(feeScheduleFor('Some Unknown Auctioneer')).toBeUndefined(); }); it('applies marginal tiers', () => { const s = feeScheduleFor("Sotheby's")!; expect(buyerPremium(100_000, s).premium).toBe(27_000); // 1,000,000 × 27 % + 500,000 × 22 % expect(buyerPremium(1_500_000, s).premium).toBe(380_000); expect(buyerPremium(1_500_000, s).allIn).toBe(1_880_000); }); it('applies minimum, maximum and fixed fees', () => { const bat = feeScheduleFor('Bring a Trailer')!; expect(buyerPremium(1_000, bat).premium).toBe(250); // minimum expect(buyerPremium(500_000, bat).premium).toBe(7_500); // cap expect(buyerPremium(40_000, bat).premium).toBe(2_000); const cw = feeScheduleFor('Catawiki')!; expect(buyerPremium(100, cw).premium).toBe(10); // 9 % + €1 }); it('converts tier boundaries when the lot is billed in another currency', () => { const s = feeScheduleFor("Sotheby's")!; // 1,200,000 EUR at 1.1 USD/EUR = 1,320,000 USD → 1,000,000 × 27 % + 320,000 × 22 % = 340,400 USD → /1.1 = 309,454.55 EUR expect(buyerPremium(1_200_000, s, { fxToScheduleCurrency: 1.1 }).premium).toBeCloseTo(309_454.55, 1); }); it('all-in price follows the connector flag and the source type', () => { expect(allInPrice({ price: 1000, buyerPremiumIncluded: true, house: 'Goldin' })).toMatchObject({ allIn: 1000, basis: 'included' }); expect(allInPrice({ price: 1000, buyerPremiumIncluded: false, house: 'Goldin' })).toMatchObject({ allIn: 1200, basis: 'added_published' }); expect(allInPrice({ price: 1000, buyerPremiumIncluded: false, house: 'Noonans' })).toMatchObject({ allIn: 1240, basis: 'added_approximate' }); expect(allInPrice({ price: 1000, buyerPremiumIncluded: false, house: 'Unknown House' })).toMatchObject({ allIn: 1220, basis: 'added_default' }); expect(allInPrice({ price: 1000, buyerPremiumIncluded: null, house: 'Mecum Auctions' })).toMatchObject({ allIn: 1100, basis: 'added_approximate' }); expect(allInPrice({ price: 1000, buyerPremiumIncluded: null, house: 'Totally Unknown' })).toMatchObject({ allIn: 1000, basis: 'unknown' }); expect(allInPrice({ price: 1000, buyerPremiumIncluded: null, house: 'ComicLink' })).toMatchObject({ allIn: 1000, basis: 'none' }); expect(allInPrice({ price: 1000, buyerPremiumIncluded: null, saleType: 'fixed_price', sourceType: 'marketplace' })).toMatchObject({ allIn: 1000, basis: 'none' }); }); it('every schedule has sane tiers', () => { for (const s of FEE_SCHEDULES) { expect(s.tiers.length).toBeGreaterThan(0); expect(s.tiers.at(-1)!.upTo).toBeNull(); for (const t of s.tiers) expect(t.rate).toBeGreaterThanOrEqual(0), expect(t.rate).toBeLessThan(0.5); } }); });