TypeScript 61.9%
HTML 37.2%
SQL 0.7%
1import { describe, expect, it } from 'vitest';2import { allInPrice, buyerPremium, feeScheduleFor, FEE_SCHEDULES } from './fees.js';34describe('buyer premium schedules (§35)', () => {5 it('finds houses by name, connector id and tolerant alias', () => {6 expect(feeScheduleFor("Sotheby's")?.id).toBe('sothebys');7 expect(feeScheduleFor('bring-a-trailer')?.id).toBe('bring-a-trailer');8 expect(feeScheduleFor("Sotheby's Hong Kong")?.id).toBe('sothebys');9 expect(feeScheduleFor('Some Unknown Auctioneer')).toBeUndefined();10 });11 it('applies marginal tiers', () => {12 const s = feeScheduleFor("Sotheby's")!;13 expect(buyerPremium(100_000, s).premium).toBe(27_000);14 // 1,000,000 × 27 % + 500,000 × 22 %15 expect(buyerPremium(1_500_000, s).premium).toBe(380_000);16 expect(buyerPremium(1_500_000, s).allIn).toBe(1_880_000);17 });18 it('applies minimum, maximum and fixed fees', () => {19 const bat = feeScheduleFor('Bring a Trailer')!;20 expect(buyerPremium(1_000, bat).premium).toBe(250); // minimum21 expect(buyerPremium(500_000, bat).premium).toBe(7_500); // cap22 expect(buyerPremium(40_000, bat).premium).toBe(2_000);23 const cw = feeScheduleFor('Catawiki')!;24 expect(buyerPremium(100, cw).premium).toBe(10); // 9 % + €125 });26 it('converts tier boundaries when the lot is billed in another currency', () => {27 const s = feeScheduleFor("Sotheby's")!;28 // 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 EUR29 expect(buyerPremium(1_200_000, s, { fxToScheduleCurrency: 1.1 }).premium).toBeCloseTo(309_454.55, 1);30 });31 it('all-in price follows the connector flag and the source type', () => {32 expect(allInPrice({ price: 1000, buyerPremiumIncluded: true, house: 'Goldin' })).toMatchObject({ allIn: 1000, basis: 'included' });33 expect(allInPrice({ price: 1000, buyerPremiumIncluded: false, house: 'Goldin' })).toMatchObject({ allIn: 1200, basis: 'added_published' });34 expect(allInPrice({ price: 1000, buyerPremiumIncluded: false, house: 'Noonans' })).toMatchObject({ allIn: 1240, basis: 'added_approximate' });35 expect(allInPrice({ price: 1000, buyerPremiumIncluded: false, house: 'Unknown House' })).toMatchObject({ allIn: 1220, basis: 'added_default' });36 expect(allInPrice({ price: 1000, buyerPremiumIncluded: null, house: 'Mecum Auctions' })).toMatchObject({ allIn: 1100, basis: 'added_approximate' });37 expect(allInPrice({ price: 1000, buyerPremiumIncluded: null, house: 'Totally Unknown' })).toMatchObject({ allIn: 1000, basis: 'unknown' });38 expect(allInPrice({ price: 1000, buyerPremiumIncluded: null, house: 'ComicLink' })).toMatchObject({ allIn: 1000, basis: 'none' });39 expect(allInPrice({ price: 1000, buyerPremiumIncluded: null, saleType: 'fixed_price', sourceType: 'marketplace' })).toMatchObject({ allIn: 1000, basis: 'none' });40 });41 it('every schedule has sane tiers', () => {42 for (const s of FEE_SCHEDULES) {43 expect(s.tiers.length).toBeGreaterThan(0);44 expect(s.tiers.at(-1)!.upTo).toBeNull();45 for (const t of s.tiers) expect(t.rate).toBeGreaterThanOrEqual(0), expect(t.rate).toBeLessThan(0.5);46 }47 });48});49