import { describe, expect, it } from 'vitest'

import { createDb, eq, tenants } from '@zync/db'

import { createLegacyDbForParity } from '../db'

const ENV = {
  DB: {
    connectionString: 'postgres://user:pass@example.neon.tech/zync_test',
  },
}

describe('db platform parity', () => {
  it('builds the same fixed read query as the legacy postgres-js client', () => {
    const legacyDb = createLegacyDbForParity(ENV as never)
    const platformDb = createDb(ENV as never)

    const legacyQuery = legacyDb
      .select({
        id: tenants.id,
        name: tenants.name,
      })
      .from(tenants)
      .where(eq(tenants.id, '00000000-0000-0000-0000-000000000001'))
      .limit(1)
      .toSQL()

    const platformQuery = platformDb
      .select({
        id: tenants.id,
        name: tenants.name,
      })
      .from(tenants)
      .where(eq(tenants.id, '00000000-0000-0000-0000-000000000001'))
      .limit(1)
      .toSQL()

    expect(platformQuery).toEqual(legacyQuery)
    expect(typeof platformDb.transaction).toBe('function')
  })
})
