Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

1007 B
Raw Blame
import { describe, expect, it } from 'vitest'

import { enrichLintsQuery, safeSql } from '../../../src'

describe('enrichLintsQuery', () => {
  const dummyQuery = safeSql`SELECT 1`

  it('should include SET LOCAL pgrst.db_schemas when exposedSchemas is provided', () => {
    const result = enrichLintsQuery(dummyQuery, 'public, storage')
    expect(result).toContain("set local pgrst.db_schemas = 'public, storage';")
  })

  it('should NOT include SET LOCAL pgrst.db_schemas when exposedSchemas is undefined', () => {
    const result = enrichLintsQuery(dummyQuery, undefined)
    expect(result).not.toContain('pgrst.db_schemas')
  })

  it("should set pgrst.db_schemas to '' when exposedSchemas is empty string (Data API off)", () => {
    const result = enrichLintsQuery(dummyQuery, '')
    expect(result).toContain("set local pgrst.db_schemas = '';")
  })

  it('should always include the query', () => {
    const result = enrichLintsQuery(dummyQuery)
    expect(result).toContain(dummyQuery)
  })
})