Skip to content

Commit 0e11136

Browse files
committed
Enhance test setup by adding 'tags' and 'article_tag_pivot' tables for improved schema testing. Update user table creation to include primary key and default UUID generation. Refactor test assertions for clarity and consistency in SQL output validation.
1 parent 323a9bb commit 0e11136

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

__tests__/repository/find-rows.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ describe("Repository findRows", () => {
204204
});
205205
});
206206

207-
// describe("Logical Operators", () => {
207+
describe("Logical Operators", () => {
208208
// it("should find rows with and operator", async () => {
209209
// const users = await createTestUsers(3);
210210
// const minAge = 25;
@@ -261,7 +261,7 @@ describe("Repository findRows", () => {
261261
// )
262262
// ).toBe(true);
263263
// });
264-
// });
264+
});
265265
//
266266
// describe("Sorting Operators", () => {
267267
// it("should sort rows with asc operator", async () => {

__tests__/schema.test.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,26 @@ interface Post {
2828
describe("Schema and Table", () => {
2929
describe("Table Creation", () => {
3030
it("should create a table with basic columns", () => {
31+
// CREATE TABLE IF NOT EXISTS users (
32+
// "id" UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(),
33+
// "name" VARCHAR(255),
34+
// "email" VARCHAR(255),
35+
// "age" INTEGER,
36+
// "createdAt" TIMESTAMP DEFAULT 'now()'
37+
// );
3138
const table = new Table<User>("users");
32-
table.column("id", uuid());
39+
table.column("id", uuid()).primaryKey().$defaultUUID();
3340
table.column("name", varchar(255));
3441
table.column("email", varchar(255));
3542
table.column("age", integer());
36-
table.column("createdAt", timestamp()).default("now()");
43+
table.column("createdAt", timestamp()).$defaultNOW();
3744
const sql = table.createTableSql();
3845
expect(sql).toContain("CREATE TABLE IF NOT EXISTS users");
39-
expect(sql).toContain('"id" UUID');
46+
expect(sql).toContain(`"id" UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid()`);
4047
expect(sql).toContain('"name" VARCHAR(255)');
4148
expect(sql).toContain('"email" VARCHAR(255)');
4249
expect(sql).toContain('"age" INTEGER');
43-
expect(sql).toContain('"createdAt" TIMESTAMP');
50+
expect(sql).toContain(`"createdAt" TIMESTAMP DEFAULT 'now()'`);
4451
});
4552

4653
it("should create a table with primary key", () => {

__tests__/select-builder.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {CompositeWhere, Join, OrderBy, SelectQueryBuilder, SimpleWhere, SqlExecutor} from "../src";
1+
import {and, CompositeWhere, eq, gt, Join, OrderBy, SelectQueryBuilder, SimpleWhere, SqlExecutor} from "../src";
22

33
// Mock SqlExecutor
44
const mockExecutor: SqlExecutor = {
@@ -28,6 +28,7 @@ describe("SelectQueryBuilder", () => {
2828
});
2929

3030
describe("Basic Select", () => {
31+
3132
it("should build correct SQL for basic select", () => {
3233
const result = builder.build();
3334

src/schema/column.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export class Column {
3434
}
3535

3636
$defaultUUID(): this {
37-
// @ts-ignore
3837
this._generateUUID = true;
3938
return this;
4039
}

test-setup.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,27 @@ export async function setupTestTables() {
4343
onDelete: "CASCADE",
4444
});
4545

46+
const tagTable = new Table<any>("tags");
47+
postTable.column("id", uuid()).primaryKey().$defaultUUID();
48+
postTable.column("title", varchar()).notNull();
49+
50+
const articleTagPivotTable = new Table<any>("article_tag_pivot");
51+
articleTagPivotTable.column("article_id", uuid()).notNull().references({
52+
table: "articles",
53+
column: "id",
54+
onDelete: "CASCADE",
55+
});
56+
articleTagPivotTable.column("tag_id", uuid()).notNull().references({
57+
table: "tags",
58+
column: "id",
59+
onDelete: "CASCADE",
60+
});
61+
4662
await pool.query(`
4763
${userTable.createTableSql()};
4864
${postTable.createTableSql()};
65+
${tagTable.createTableSql()};
66+
${articleTagPivotTable.createTableSql()};
4967
`);
5068
}
5169

0 commit comments

Comments
 (0)