Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

798 B
Raw Blame
import { describe, expect, expectTypeOf, it } from 'vitest'
import { PRODUCT_STATUSES, type ProductStatus, subsetOf } from '../src'

describe('subsetOf', () => {
  it('keeps the picked values and their narrow type', () => {
    const editable = subsetOf(PRODUCT_STATUSES, ['draft', 'active'])

    expect(editable).toEqual(['draft', 'active'])
    expectTypeOf(editable[0]).toEqualTypeOf<'draft' | 'active'>()
  })

  it('answers includes for any status the API returns', () => {
    const status: ProductStatus = 'archived'

    expect(subsetOf(PRODUCT_STATUSES, ['draft']).includes(status)).toBe(false)
  })

  it('rejects a value the list does not hold', () => {
    // @ts-expect-error 'published' is not a built-in product status
    subsetOf(PRODUCT_STATUSES, ['draft', 'published'])
  })
})