|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { formatSqlQuery } from "./formatSqlQuery"; |
| 3 | + |
| 4 | +describe("formatSqlQuery", () => { |
| 5 | + it("should convert camelCase column names to snake_case", () => { |
| 6 | + const input = "SELECT userId, firstName, lastName FROM users"; |
| 7 | + const expected = 'SELECT "user_id", "first_name", "last_name" FROM "users"'; |
| 8 | + expect(formatSqlQuery(input)).toBe(expected); |
| 9 | + }); |
| 10 | + |
| 11 | + it("should not modify non-camelCase column names", () => { |
| 12 | + const input = "SELECT user_id, first_name, last_name FROM users"; |
| 13 | + const expected = 'SELECT "user_id", "first_name", "last_name" FROM "users"'; |
| 14 | + expect(formatSqlQuery(input)).toBe(expected); |
| 15 | + }); |
| 16 | + |
| 17 | + it("should not modify camelCase words that are not column names", () => { |
| 18 | + const input = "SELECT * FROM users WHERE firstName LIKE '%NameSurname%'"; |
| 19 | + const expected = 'SELECT * FROM "users" WHERE "first_name" LIKE \'%NameSurname%\''; |
| 20 | + expect(formatSqlQuery(input)).toBe(expected); |
| 21 | + }); |
| 22 | + |
| 23 | + it("should not modify table names", () => { |
| 24 | + const input = "SELECT * FROM usersTable"; |
| 25 | + const expected = 'SELECT * FROM "usersTable"'; |
| 26 | + expect(formatSqlQuery(input)).toBe(expected); |
| 27 | + |
| 28 | + const input2 = "SELECT * FROM users_table"; |
| 29 | + const expected2 = 'SELECT * FROM "users_table"'; |
| 30 | + expect(formatSqlQuery(input2)).toBe(expected2); |
| 31 | + }); |
| 32 | +}); |
0 commit comments