Skip to content

Commit 37069e4

Browse files
jonasnobileclaude
andcommitted
test: update tests for DatabaseDataType enum and clean up unused imports
Migrate string literal data types to DatabaseDataType enum values, add missing column fields in test fixtures, and remove unused imports. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6549e8d commit 37069e4

13 files changed

+37
-53
lines changed

tests/connection-manager.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { ConnectionManager } from '@dotaz/backend-shared/services/connection-manager'
22
import type { StatusChangeEvent } from '@dotaz/backend-shared/services/connection-manager'
33
import { AppDatabase } from '@dotaz/backend-shared/storage/app-db'
4-
import type { ConnectionConfig, PostgresConnectionConfig, SqliteConnectionConfig } from '@dotaz/shared/types/connection'
5-
import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test'
6-
import { tmpSqlitePath } from './helpers'
4+
import type { PostgresConnectionConfig, SqliteConnectionConfig } from '@dotaz/shared/types/connection'
5+
import { afterEach, beforeEach, describe, expect, test } from 'bun:test'
76

87
// ── Helpers ──────────────────────────────────────────────────
98

@@ -908,7 +907,7 @@ describe('ConnectionManager', () => {
908907
})
909908

910909
test('password is cached on connect and cleared on disconnect', async () => {
911-
const conn = manager.createConnection({
910+
manager.createConnection({
912911
name: 'PG',
913912
config: pgConfig,
914913
})

tests/csv-stream-parser.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
type CsvBatch,
44
CsvParseError,
55
type CsvStreamOptions,
6-
MAX_BUFFER_SIZE,
76
parseCsvStream,
87
} from '@dotaz/backend-shared/services/csv-stream-parser'
98
import { describe, expect, test } from 'bun:test'

tests/explain.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import type { DatabaseDriver } from '@dotaz/backend-shared/db/driver'
22
import type { ConnectionManager } from '@dotaz/backend-shared/services/connection-manager'
33
import { QueryExecutor } from '@dotaz/backend-shared/services/query-executor'
4-
import type { ExplainNode, QueryResult } from '@dotaz/shared/types/query'
4+
import type { QueryResult } from '@dotaz/shared/types/query'
5+
import { DatabaseDataType } from '@dotaz/shared/types/database'
56
import { describe, expect, mock, test } from 'bun:test'
67

78
// ── Helpers ──────────────────────────────────────────────────
89

910
function makeSuccessResult(rows: Record<string, unknown>[] = [], durationMs = 0): QueryResult {
1011
const columns = rows.length > 0
11-
? Object.keys(rows[0]).map((name) => ({ name, dataType: 'unknown' }))
12+
? Object.keys(rows[0]).map((name) => ({ name, dataType: DatabaseDataType.Unknown }))
1213
: []
1314
return { columns, rows, rowCount: rows.length, durationMs }
1415
}

tests/export-service.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ import type { DatabaseDriver } from '@dotaz/backend-shared/db/driver'
22
import { buildExportSelectQuery, exportPreview, exportToFile, exportToStream } from '@dotaz/backend-shared/services/export-service'
33
import type { ExportParams, ExportWriter } from '@dotaz/backend-shared/services/export-service'
44
import type { QueryResult } from '@dotaz/shared/types/query'
5+
import { DatabaseDataType } from '@dotaz/shared/types/database'
56
import { afterEach, beforeEach, describe, expect, mock, test } from 'bun:test'
6-
import { existsSync, mkdtempSync, rmdirSync, unlinkSync } from 'node:fs'
7+
import { mkdtempSync, rmdirSync, unlinkSync } from 'node:fs'
78
import { tmpdir } from 'node:os'
89
import { join } from 'node:path'
910

1011
function makeResult(rows: Record<string, unknown>[]): QueryResult {
1112
const columns = rows.length > 0
12-
? Object.keys(rows[0]).map((name) => ({ name, dataType: 'unknown' }))
13+
? Object.keys(rows[0]).map((name) => ({ name, dataType: DatabaseDataType.Unknown }))
1314
: []
1415
return { columns, rows, rowCount: rows.length, durationMs: 0 }
1516
}

tests/grid-store.test.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { GridDataResponse } from '@dotaz/shared/types/grid'
21
import { beforeEach, describe, expect, mock, test } from 'bun:test'
32

43
// ── Mock solid-js/store ──────────────────────────────────
@@ -130,20 +129,6 @@ const { gridStore } = await import('@dotaz/frontend-shared/stores/grid')
130129

131130
// ── Test helpers ─────────────────────────────────────────
132131

133-
function makeResponse(overrides?: Partial<GridDataResponse>): GridDataResponse {
134-
return {
135-
columns: [
136-
{ name: 'id', dataType: 'integer', nullable: false, isPrimaryKey: true },
137-
{ name: 'name', dataType: 'text', nullable: true, isPrimaryKey: false },
138-
],
139-
rows: defaultRows,
140-
totalRows: defaultTotalRows,
141-
page: 1,
142-
pageSize: 100,
143-
...overrides,
144-
}
145-
}
146-
147132
function resetState() {
148133
storeState.tabs = {}
149134
mockQueryExecute.mockReset()

tests/import-service.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { DatabaseDriver } from '@dotaz/backend-shared/db/driver'
22
import { importFromStream, importPreviewFromStream, parseJson } from '@dotaz/backend-shared/services/import-service'
3-
import type { QueryResult } from '@dotaz/shared/types/query'
43
import { describe, expect, mock, test } from 'bun:test'
54

65
function stringToStream(content: string): ReadableStream<Uint8Array> {

tests/join-completion.test.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { buildJoinCompletions, detectJoinContext, parseTableReferences } from '@dotaz/frontend-shared/lib/join-completion'
22
import type { SchemaData } from '@dotaz/shared/types/database'
3+
import { DatabaseDataType } from '@dotaz/shared/types/database'
34
import { describe, expect, it } from 'bun:test'
45

56
// ── Helper ────────────────────────────────────────────────
@@ -9,29 +10,29 @@ function createSchemaData(overrides?: Partial<SchemaData>): SchemaData {
910
schemas: [{ name: 'public' }],
1011
tables: {
1112
public: [
12-
{ name: 'orders', type: 'table' },
13-
{ name: 'customers', type: 'table' },
14-
{ name: 'products', type: 'table' },
15-
{ name: 'order_items', type: 'table' },
13+
{ name: 'orders', type: 'table', schema: 'public' },
14+
{ name: 'customers', type: 'table', schema: 'public' },
15+
{ name: 'products', type: 'table', schema: 'public' },
16+
{ name: 'order_items', type: 'table', schema: 'public' },
1617
],
1718
},
1819
columns: {
1920
'public.orders': [
20-
{ name: 'id', dataType: 'integer', nullable: false, isPrimaryKey: true },
21-
{ name: 'customer_id', dataType: 'integer', nullable: false, isPrimaryKey: false },
21+
{ name: 'id', dataType: DatabaseDataType.Integer, nullable: false, defaultValue: null, isPrimaryKey: true, isAutoIncrement: false },
22+
{ name: 'customer_id', dataType: DatabaseDataType.Integer, nullable: false, defaultValue: null, isPrimaryKey: false, isAutoIncrement: false },
2223
],
2324
'public.customers': [
24-
{ name: 'id', dataType: 'integer', nullable: false, isPrimaryKey: true },
25-
{ name: 'name', dataType: 'text', nullable: false, isPrimaryKey: false },
25+
{ name: 'id', dataType: DatabaseDataType.Integer, nullable: false, defaultValue: null, isPrimaryKey: true, isAutoIncrement: false },
26+
{ name: 'name', dataType: DatabaseDataType.Text, nullable: false, defaultValue: null, isPrimaryKey: false, isAutoIncrement: false },
2627
],
2728
'public.order_items': [
28-
{ name: 'id', dataType: 'integer', nullable: false, isPrimaryKey: true },
29-
{ name: 'order_id', dataType: 'integer', nullable: false, isPrimaryKey: false },
30-
{ name: 'product_id', dataType: 'integer', nullable: false, isPrimaryKey: false },
29+
{ name: 'id', dataType: DatabaseDataType.Integer, nullable: false, defaultValue: null, isPrimaryKey: true, isAutoIncrement: false },
30+
{ name: 'order_id', dataType: DatabaseDataType.Integer, nullable: false, defaultValue: null, isPrimaryKey: false, isAutoIncrement: false },
31+
{ name: 'product_id', dataType: DatabaseDataType.Integer, nullable: false, defaultValue: null, isPrimaryKey: false, isAutoIncrement: false },
3132
],
3233
'public.products': [
33-
{ name: 'id', dataType: 'integer', nullable: false, isPrimaryKey: true },
34-
{ name: 'name', dataType: 'text', nullable: false, isPrimaryKey: false },
34+
{ name: 'id', dataType: DatabaseDataType.Integer, nullable: false, defaultValue: null, isPrimaryKey: true, isAutoIncrement: false },
35+
{ name: 'name', dataType: DatabaseDataType.Text, nullable: false, defaultValue: null, isPrimaryKey: false, isAutoIncrement: false },
3536
],
3637
},
3738
indexes: {},
@@ -283,7 +284,7 @@ describe('buildJoinCompletions', () => {
283284
it('handles SQLite mode (no schema prefix)', () => {
284285
const sqliteSchema = createSchemaData()
285286
// For SQLite, use empty string as default schema but still key by "schema.table"
286-
const completions = buildJoinCompletions(
287+
buildJoinCompletions(
287288
[{ table: 'orders' }],
288289
sqliteSchema,
289290
true,

tests/pg-driver.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,13 @@ describe('PostgresDriver loadSchema', () => {
255255
expect(idCol.nullable).toBe(false)
256256

257257
const nameCol = columns.find((c) => c.name === 'name')!
258-
expect(nameCol.dataType).toBe('text')
258+
expect(nameCol.dataType).toBe(DatabaseDataType.Text)
259259
expect(nameCol.isPrimaryKey).toBe(false)
260260
expect(nameCol.isAutoIncrement).toBe(false)
261261
expect(nameCol.nullable).toBe(false)
262262

263263
const ageCol = columns.find((c) => c.name === 'age')!
264-
expect(ageCol.dataType).toBe('integer')
264+
expect(ageCol.dataType).toBe(DatabaseDataType.Integer)
265265
expect(ageCol.nullable).toBe(true)
266266

267267
const metadataCol = columns.find((c) => c.name === 'metadata')!

tests/query-executor.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ describe('MySQL placeholder generation', () => {
501501

502502
test('buildQuickSearchClause uses ? placeholders', () => {
503503
const columns = [
504-
{ name: 'name', dataType: 'varchar' },
505-
{ name: 'description', dataType: 'text' },
504+
{ name: 'name', dataType: DatabaseDataType.Varchar },
505+
{ name: 'description', dataType: DatabaseDataType.Text },
506506
]
507507
const result = buildQuickSearchClause(columns, 'test', driver)
508508
expect(result.sql).toBe(
@@ -586,7 +586,7 @@ describe('splitStatements', () => {
586586

587587
function makeSuccessResult(rows: Record<string, unknown>[] = [], durationMs = 0): QueryResult {
588588
const columns = rows.length > 0
589-
? Object.keys(rows[0]).map((name) => ({ name, dataType: 'unknown' }))
589+
? Object.keys(rows[0]).map((name) => ({ name, dataType: DatabaseDataType.Unknown }))
590590
: []
591591
return { columns, rows, rowCount: rows.length, durationMs }
592592
}
@@ -626,8 +626,8 @@ describe('QueryExecutor', () => {
626626
expect(results).toHaveLength(1)
627627
expect(results[0].rows).toEqual(rows)
628628
expect(results[0].columns).toEqual([
629-
{ name: 'id', dataType: 'unknown' },
630-
{ name: 'name', dataType: 'unknown' },
629+
{ name: 'id', dataType: DatabaseDataType.Unknown },
630+
{ name: 'name', dataType: DatabaseDataType.Unknown },
631631
])
632632
expect(results[0].error).toBeUndefined()
633633
expect(results[0].durationMs).toBeGreaterThanOrEqual(0)
@@ -741,7 +741,7 @@ describe('QueryExecutor', () => {
741741
test('stops multi-statement execution on error', async () => {
742742
let callCount = 0
743743
const driver = makeMockDriver({
744-
execute: mock(async (sql: string) => {
744+
execute: mock(async (_sql: string) => {
745745
callCount++
746746
if (callCount === 2) throw new Error('syntax error')
747747
return makeSuccessResult([{ n: callCount }])

tests/rpc-handlers.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -441,10 +441,10 @@ describe('RPC Handlers', () => {
441441
const config = {
442442
columns: ['id', 'name', 'email'],
443443
sort: [{ column: 'name', direction: 'asc' as const }],
444-
filters: [{ column: 'active', operator: 'eq', value: true }],
444+
filters: [{ column: 'active', operator: 'eq' as const, value: true }],
445445
columnWidths: { id: 60, name: 200, email: 300 },
446446
}
447-
const view = handlers['views.save']({
447+
handlers['views.save']({
448448
connectionId,
449449
schemaName: 'main',
450450
tableName: 'users',

0 commit comments

Comments
 (0)