From 493d387fbd3458907e81f5710ae8037ca3d5e68d Mon Sep 17 00:00:00 2001 From: wirekang Date: Fri, 12 Dec 2025 22:58:26 +0900 Subject: [PATCH 1/2] add camel-case-plugin.test.ts --- test/node/src/camel-case-plugin.test.ts | 119 ++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 test/node/src/camel-case-plugin.test.ts diff --git a/test/node/src/camel-case-plugin.test.ts b/test/node/src/camel-case-plugin.test.ts new file mode 100644 index 000000000..1e4c1c829 --- /dev/null +++ b/test/node/src/camel-case-plugin.test.ts @@ -0,0 +1,119 @@ +import { + CamelCasePlugin, + CamelCasePluginOptions, + createQueryId, + CreateTableNode, +} from '../../..' +import { expect } from './test-setup' + +describe('CamelCasePlugin', () => { + type TestCaseWithOptions = { + name: string + options?: CamelCasePluginOptions + schema: [source: string, expected: string][] + result: [source: string, expected: string][] + } + const testCaseWithOptions: TestCaseWithOptions[] = [ + { + name: 'undefined', + options: undefined, + schema: [ + ['asis', 'asis'], + ['fooBar', 'foo_bar'], + ['aFOOBar', 'a_foobar'], + ['_fooBar', '_foo_bar'], + ], + result: [ + ['asis', 'asis'], + ['foo_bar', 'fooBar'], + ['a_f_o_o_bar', 'aFOOBar'], + ['_id', '_Id'], + ], + }, + { + name: 'upperCase', + options: { upperCase: true }, + schema: [ + ['foo', 'FOO'], + ['fooBar', 'FOO_BAR'], + ], + result: [ + ['asis', 'asis'], + ['FOO', 'foo'], + ['foo_bar', 'fooBar'], + ['FOO_BAR', 'fooBar'], + ], + }, + { + name: 'underscoreBetweenUppercaseLetters', + options: { underscoreBetweenUppercaseLetters: true }, + schema: [ + ['asis', 'asis'], + ['fooBar', 'foo_bar'], + ['aFOOBar', 'a_f_o_o_bar'], + ['_fooBar', '_foo_bar'], + ], + result: [ + ['asis', 'asis'], + ['foo_bar', 'fooBar'], + ['a_f_o_o_bar', 'aFOOBar'], + ], + }, + { + name: 'underscoreBeforeDigits', + options: { underscoreBeforeDigits: true }, + schema: [ + ['asis', 'asis'], + ['fooBar', 'foo_bar'], + ['foo12Bar', 'foo_12_bar'], + ], + result: [ + ['asis', 'asis'], + ['foo_bar', 'fooBar'], + ['a_f_o_o_bar', 'aFOOBar'], + ], + }, + ] + + for (const { + name, + options, + schema: schemaTestCases, + result: resultTestCases, + } of testCaseWithOptions) { + describe(`with "${name}" options`, () => { + const plugin = new CamelCasePlugin(options) + + for (const [source, expected] of schemaTestCases) { + it(`should convert schema "${source}"`, () => { + const result = plugin.transformQuery({ + queryId: createQueryId(), + node: { + kind: 'CreateTableNode', + table: { + kind: 'TableNode', + table: { + kind: 'SchemableIdentifierNode', + identifier: { kind: 'IdentifierNode', name: source }, + }, + }, + columns: [], + }, + }) as CreateTableNode + expect(result.table.table.identifier.name).to.equal(expected) + }) + } + + for (const [source, expected] of resultTestCases) { + it(`should convert result "${source}"`, async () => { + const { rows } = await plugin.transformResult({ + queryId: createQueryId(), + result: { rows: [{ [source]: 123456789 }] }, + }) + expect(rows[0]).has.key(expected) + expect(rows[0][expected]).to.equal(123456789) + }) + } + }) + } +}) From 19cceba2e0dd0e63803257d86e560345a8c87240 Mon Sep 17 00:00:00 2001 From: wirekang Date: Fri, 12 Dec 2025 23:30:45 +0900 Subject: [PATCH 2/2] update camel-case-plugin.test.ts --- test/node/src/camel-case-plugin.test.ts | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test/node/src/camel-case-plugin.test.ts b/test/node/src/camel-case-plugin.test.ts index 1e4c1c829..f7875be85 100644 --- a/test/node/src/camel-case-plugin.test.ts +++ b/test/node/src/camel-case-plugin.test.ts @@ -3,10 +3,23 @@ import { CamelCasePluginOptions, createQueryId, CreateTableNode, + DummyDriver, + Kysely, + PostgresAdapter, + PostgresIntrospector, + PostgresQueryCompiler, } from '../../..' import { expect } from './test-setup' describe('CamelCasePlugin', () => { + const db = new Kysely({ + dialect: { + createAdapter: () => new PostgresAdapter(), + createDriver: () => new DummyDriver(), + createIntrospector: (db) => new PostgresIntrospector(db), + createQueryCompiler: () => new PostgresQueryCompiler(), + }, + }) type TestCaseWithOptions = { name: string options?: CamelCasePluginOptions @@ -88,17 +101,7 @@ describe('CamelCasePlugin', () => { it(`should convert schema "${source}"`, () => { const result = plugin.transformQuery({ queryId: createQueryId(), - node: { - kind: 'CreateTableNode', - table: { - kind: 'TableNode', - table: { - kind: 'SchemableIdentifierNode', - identifier: { kind: 'IdentifierNode', name: source }, - }, - }, - columns: [], - }, + node: db.schema.createTable(source).toOperationNode(), }) as CreateTableNode expect(result.table.table.identifier.name).to.equal(expected) })