Skip to content

Commit bc7ab4c

Browse files
committed
more test cases
1 parent eb17fc4 commit bc7ab4c

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

test/index.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,41 @@ describe("Queries", () => {
9595
expect(deparsed).to.eq(`INSERT INTO people (name, age) VALUES ('John', 28), ('Jane', 22)`)
9696
});
9797

98+
it("sync function should return a same SQL (update)", async () => {
99+
const testQuery = "UPDATE people SET age = age + 1 WHERE name = 'John';";
100+
const parsed = query.parseQuerySync(testQuery);
101+
const deparsed = query.deparseSync(parsed);
102+
expect(deparsed).to.eq("UPDATE people SET age = age + 1 WHERE name = 'John'");
103+
});
104+
105+
it("sync function should return a same SQL (join and where)", async () => {
106+
const testQuery = "select a.id, b.name from table_a a join table_b b on a.id = b.a_id where b.status = 'active';";
107+
const parsed = query.parseQuerySync(testQuery);
108+
const deparsed = query.deparseSync(parsed);
109+
expect(deparsed).to.eq("SELECT a.id, b.name FROM table_a a JOIN table_b b ON a.id = b.a_id WHERE b.status = 'active'");
110+
});
111+
112+
it("sync function should return a same SQL (CTE)", async () => {
113+
const testQuery = "with recent as (select * from people where age > 30) select name from recent;";
114+
const parsed = query.parseQuerySync(testQuery);
115+
const deparsed = query.deparseSync(parsed);
116+
expect(deparsed).to.eq("WITH recent AS (SELECT * FROM people WHERE age > 30) SELECT name FROM recent");
117+
});
118+
119+
it("sync function should return a same SQL (create table)", async () => {
120+
const testQuery = `CREATE TABLE orders (
121+
id serial PRIMARY KEY,
122+
user_id integer NOT NULL,
123+
total numeric(10,2) DEFAULT 0.00,
124+
ordered_at timestamp with time zone DEFAULT now(),
125+
description text,
126+
CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE
127+
);`;
128+
const parsed = query.parseQuerySync(testQuery);
129+
const deparsed = query.deparseSync(parsed);
130+
expect(deparsed).to.eq(`CREATE TABLE orders (id serial PRIMARY KEY, user_id int NOT NULL, total numeric(10, 2) DEFAULT 0.00, ordered_at timestamp with time zone DEFAULT now(), description text, CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE)`);
131+
});
132+
98133
it("should reject on bogus input", async () => {
99134
return query.deparse({stmts: [{}]}).then(
100135
() => {

0 commit comments

Comments
 (0)