import type { Database } from '@platform-modules/db'
import { describe, expect, it } from 'vitest'
import { isInventoryTransactionRequiredError } from '../errors.js'
import type { InventorySchema } from '../schema.js'
import { withInventoryTransaction } from './public-helpers.js'

describe('withInventoryTransaction', () => {
  it('throws a typed error when db lacks transaction support', async () => {
    const db = {} as Database<InventorySchema>

    await expect(
      withInventoryTransaction(db, async () => 'ok'),
    ).rejects.toSatisfy((error) => isInventoryTransactionRequiredError(error))
  })
})
