import { describe, expect, it } from 'vitest'; import { isSizeEligible, sizeGuideResolution } from './sizeEligibility'; const variants = [ { variant_id: '2', size_label: 'M', available: true } ]; describe( 'the WooCommerce size entry gate', () => { it( 'requires a configured guide with an available matching variation', () => { expect( isSizeEligible( { hasSizeGuide: false }, [ 'shirts' ], '1', variants ) ).toBe( false ); expect( isSizeEligible( { hasSizeGuide: true }, [ 'shirts' ], '1', [ { ...variants[ 0 ], available: false } ] ) ).toBe( false ); expect( isSizeEligible( { hasSizeGuide: true, guides: [] }, [ 'shirts' ], '1', variants ) ).toBe( false ); expect( isSizeEligible( { hasSizeGuide: true, guides: [ { id: 'g', categories: { categories: [] }, labels: [ 'S' ] } ], }, [ 'shirts' ], '1', variants ) ).toBe( false ); } ); it( 'honours include and exclude targeting independently from try-on', () => { const base = { hasSizeGuide: true, guides: [ { id: 'g', categories: { categories: [] }, labels: [ 'M' ] } ], }; expect( isSizeEligible( { ...base, targeting: { mode: 'include', categories: [ 'shirts' ], productIds: [] } }, [ 'shirts' ], '1', variants ) ).toBe( true ); expect( isSizeEligible( { ...base, targeting: { mode: 'exclude', categories: [ 'shirts' ], productIds: [] } }, [ 'shirts' ], '1', variants ) ).toBe( false ); } ); it( 'reports whether the applicable guide came from a collection or the shop default', () => { const size = { hasSizeGuide: true, guides: [ { id: 'g', categories: { categories: [ 'shirts' ] }, labels: [ 'M' ] } ], }; expect( sizeGuideResolution( size, [ 'shirts' ], variants ) ).toBe( 'collection' ); } ); } );