Skip to content

Commit 346eeae

Browse files
committed
Refactor test setup to rename 'article_tag_pivot' to 'post_tag_pivot', update table creation logic, and ensure proper cleanup of test tables. Improve SQL query execution by separating table creation statements for clarity.
1 parent 30b4c6d commit 346eeae

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

test-setup.ts

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
import { Pool } from "pg";
2-
import { PostgresAdapter, Table } from "./src";
3-
import {
4-
integer,
5-
text,
6-
timestamp,
7-
uuid,
8-
varchar,
9-
} from "./src/types/column-type";
1+
import {Pool} from "pg";
2+
import {PostgresAdapter, Table} from "./src";
3+
import {integer, text, timestamp, uuid, varchar,} from "./src/types/column-type";
104

115
// Test database configuration
126
const TEST_DB_CONFIG = {
@@ -44,12 +38,12 @@ export async function setupTestTables() {
4438
});
4539

4640
const tagTable = new Table<any>("tags");
47-
postTable.column("id", uuid()).primaryKey().$defaultUUID();
48-
postTable.column("title", varchar()).notNull();
41+
tagTable.column("id", uuid()).primaryKey().$defaultUUID();
42+
tagTable.column("title", varchar()).notNull();
4943

50-
const articleTagPivotTable = new Table<any>("article_tag_pivot");
51-
articleTagPivotTable.column("article_id", uuid()).notNull().references({
52-
table: "articles",
44+
const articleTagPivotTable = new Table<any>("post_tag_pivot");
45+
articleTagPivotTable.column("post_id", uuid()).notNull().references({
46+
table: "posts",
5347
column: "id",
5448
onDelete: "CASCADE",
5549
});
@@ -58,20 +52,26 @@ export async function setupTestTables() {
5852
column: "id",
5953
onDelete: "CASCADE",
6054
});
55+
await cleanupTestTables()
6156

62-
await pool.query(`
63-
${userTable.createTableSql()};
64-
${postTable.createTableSql()};
65-
${tagTable.createTableSql()};
66-
${articleTagPivotTable.createTableSql()};
67-
`);
57+
const createUserTableSQL = userTable.createTableSql()
58+
const createPostsTableSql = postTable.createTableSql()
59+
const createTagsTableSql = tagTable.createTableSql()
60+
const createPostTagPivotTableSql = articleTagPivotTable.createTableSql()
61+
62+
await pool.query(createUserTableSQL);
63+
await pool.query(createPostsTableSql);
64+
await pool.query(createTagsTableSql);
65+
await pool.query(createPostTagPivotTableSql);
6866
}
6967

7068
// Clean up test tables
7169
export async function cleanupTestTables() {
7270
await pool.query(`
7371
DROP TABLE IF EXISTS users CASCADE;
7472
DROP TABLE IF EXISTS posts CASCADE;
73+
DROP TABLE IF EXISTS tags CASCADE;
74+
DROP TABLE IF EXISTS post_tag_pivot CASCADE;
7575
`);
7676
}
7777

@@ -80,6 +80,8 @@ export async function cleanupTestData() {
8080
await pool.query(`
8181
TRUNCATE TABLE users CASCADE;
8282
TRUNCATE TABLE posts CASCADE;
83+
TRUNCATE TABLE tags CASCADE;
84+
TRUNCATE TABLE post_tag_pivot CASCADE;
8385
`);
8486
}
8587

0 commit comments

Comments
 (0)