Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import {
CloudflareD1Source,
StarbaseDBSource,
TursoDBSource,
HyperdriveSource,
ExternalDatabaseSource,
DataSource,
RegionLocationHint,
} from './types'

Expand Down Expand Up @@ -65,6 +67,19 @@ describe('Database Source Type Tests', () => {
expectTypeOf(tursoSource).toMatchTypeOf<TursoDBSource>()
})

it('should match the expected HyperdriveSource structure', () => {
const hyperdriveSource: HyperdriveSource = {
dialect: 'postgresql',
connectionString: 'postgres://user:pass@example.com/db',
defaultSchema: 'public',
}

expect(hyperdriveSource.dialect).toBe('postgresql')
expect(hyperdriveSource.connectionString).toContain('example.com')
expect(hyperdriveSource.defaultSchema).toBe('public')
expectTypeOf(hyperdriveSource).toMatchTypeOf<HyperdriveSource>()
})

it('should allow all ExternalDatabaseSource types', () => {
const externalSource: ExternalDatabaseSource = {
dialect: 'postgresql',
Expand All @@ -76,6 +91,25 @@ describe('Database Source Type Tests', () => {
}
expectTypeOf(externalSource).toMatchTypeOf<ExternalDatabaseSource>()
})

it('should allow DataSource metadata for hyperdrive connections', () => {
const dataSource = {
source: 'hyperdrive',
external: {
dialect: 'postgresql',
connectionString: 'postgres://user:pass@example.com/db',
},
cache: true,
cacheTTL: 60,
context: { tenant: 'test' },
} as unknown as DataSource

expect(dataSource.source).toBe('hyperdrive')
expect(dataSource.external?.dialect).toBe('postgresql')
expect(dataSource.cache).toBe(true)
expect(dataSource.cacheTTL).toBe(60)
expect(dataSource.context).toEqual({ tenant: 'test' })
})
})

describe('RegionLocationHint Enum Tests', () => {
Expand Down