Skip to content

Commit 0d074d8

Browse files
committed
pretty test
1 parent c5186ac commit 0d074d8

13 files changed

+158
-194
lines changed
Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`should format constraints-1: pretty/constraints-1.sql (non-pretty) 1`] = `"CREATE TABLE orders (id serial PRIMARY KEY, user_id int NOT NULL, total numeric(10, 2) CHECK (total > 0), status varchar(20) DEFAULT 'pending', created_at pg_catalog.timestamp DEFAULT now(), CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE, CONSTRAINT unique_user_date UNIQUE (user_id, created_at), CONSTRAINT check_status CHECK (status IN ('pending', 'completed', 'cancelled')))"`;
3+
exports[`non-pretty: pretty/constraints-1.sql 1`] = `"CREATE TABLE orders (id serial PRIMARY KEY, user_id int NOT NULL, total numeric(10, 2) CHECK (total > 0), status varchar(20) DEFAULT 'pending', created_at pg_catalog.timestamp DEFAULT now(), CONSTRAINT fk_user FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE, CONSTRAINT unique_user_date UNIQUE (user_id, created_at), CONSTRAINT check_status CHECK (status IN ('pending', 'completed', 'cancelled')))"`;
44

5-
exports[`should format constraints-1: pretty/constraints-1.sql (pretty) 1`] = `
5+
exports[`non-pretty: pretty/constraints-2.sql 1`] = `"ALTER TABLE products ADD CONSTRAINT fk_category FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE CASCADE ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED"`;
6+
7+
exports[`non-pretty: pretty/constraints-3.sql 1`] = `"ALTER TABLE products ADD CONSTRAINT check_price CHECK (price > 0)"`;
8+
9+
exports[`non-pretty: pretty/constraints-4.sql 1`] = `"ALTER TABLE users ADD CONSTRAINT unique_email UNIQUE (email)"`;
10+
11+
exports[`pretty: pretty/constraints-1.sql 1`] = `
612
"CREATE TABLE orders (
713
id serial PRIMARY KEY,
814
user_id int NOT NULL,
@@ -16,20 +22,14 @@ exports[`should format constraints-1: pretty/constraints-1.sql (pretty) 1`] = `
1622
)"
1723
`;
1824

19-
exports[`should format constraints-2: pretty/constraints-2.sql (non-pretty) 1`] = `"ALTER TABLE products ADD CONSTRAINT fk_category FOREIGN KEY (category_id) REFERENCES categories (id) ON UPDATE CASCADE ON DELETE SET NULL DEFERRABLE INITIALLY DEFERRED"`;
20-
21-
exports[`should format constraints-2: pretty/constraints-2.sql (pretty) 1`] = `
25+
exports[`pretty: pretty/constraints-2.sql 1`] = `
2226
"ALTER TABLE products ADD CONSTRAINT fk_category FOREIGN KEY (category_id) REFERENCES categories (id)
2327
ON UPDATE CASCADE
2428
ON DELETE SET NULL
2529
DEFERRABLE
2630
INITIALLY DEFERRED"
2731
`;
2832

29-
exports[`should format constraints-3: pretty/constraints-3.sql (non-pretty) 1`] = `"ALTER TABLE products ADD CONSTRAINT check_price CHECK (price > 0)"`;
30-
31-
exports[`should format constraints-3: pretty/constraints-3.sql (pretty) 1`] = `"ALTER TABLE products ADD CONSTRAINT check_price CHECK (price > 0)"`;
32-
33-
exports[`should format constraints-4: pretty/constraints-4.sql (non-pretty) 1`] = `"ALTER TABLE users ADD CONSTRAINT unique_email UNIQUE (email)"`;
33+
exports[`pretty: pretty/constraints-3.sql 1`] = `"ALTER TABLE products ADD CONSTRAINT check_price CHECK (price > 0)"`;
3434

35-
exports[`should format constraints-4: pretty/constraints-4.sql (pretty) 1`] = `"ALTER TABLE users ADD CONSTRAINT unique_email UNIQUE (email)"`;
35+
exports[`pretty: pretty/constraints-4.sql 1`] = `"ALTER TABLE users ADD CONSTRAINT unique_email UNIQUE (email)"`;

packages/deparser/__tests__/pretty/__snapshots__/create-policy-pretty.test.ts.snap

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`should format create_policy-1: pretty/create_policy-1.sql (non-pretty) 1`] = `"CREATE POLICY "user_policy" ON users AS PERMISSIVE FOR ALL TO authenticated_users USING (user_id = current_user_id())"`;
3+
exports[`non-pretty: pretty/create_policy-1.sql 1`] = `"CREATE POLICY "user_policy" ON users AS PERMISSIVE FOR ALL TO authenticated_users USING (user_id = current_user_id())"`;
44

5-
exports[`should format create_policy-1: pretty/create_policy-1.sql (pretty) 1`] = `
5+
exports[`non-pretty: pretty/create_policy-2.sql 1`] = `"CREATE POLICY "admin_policy" ON sensitive_data AS RESTRICTIVE FOR SELECT TO admin_role USING (department = current_user_department()) WITH CHECK (approved = true)"`;
6+
7+
exports[`non-pretty: pretty/create_policy-3.sql 1`] = `"CREATE POLICY "complex_policy" ON documents AS PERMISSIVE FOR UPDATE TO document_editors USING (owner_id = current_user_id() OR (shared = true AND permissions @> '{"edit": true}')) WITH CHECK (status <> 'archived' AND last_modified > (now() - '1 day'::interval))"`;
8+
9+
exports[`non-pretty: pretty/create_policy-4.sql 1`] = `"CREATE POLICY "simple_policy" ON posts AS PERMISSIVE FOR SELECT TO PUBLIC USING (published = true)"`;
10+
11+
exports[`non-pretty: pretty/create_policy-5.sql 1`] = `"CREATE POLICY "simple_policy" ON posts AS PERMISSIVE FOR SELECT TO PUBLIC USING (published = true)"`;
12+
13+
exports[`non-pretty: pretty/create_policy-6.sql 1`] = `"CREATE POLICY "Simple Policy" ON posts AS PERMISSIVE FOR SELECT TO PUBLIC USING (published = true)"`;
14+
15+
exports[`non-pretty: pretty/create_policy-7.sql 1`] = `"CREATE POLICY "simplepolicy" ON posts AS PERMISSIVE FOR SELECT TO PUBLIC USING (published = true)"`;
16+
17+
exports[`pretty: pretty/create_policy-1.sql 1`] = `
618
"CREATE POLICY "user_policy"
719
ON users
820
AS PERMISSIVE
@@ -13,9 +25,7 @@ exports[`should format create_policy-1: pretty/create_policy-1.sql (pretty) 1`]
1325
)"
1426
`;
1527

16-
exports[`should format create_policy-2: pretty/create_policy-2.sql (non-pretty) 1`] = `"CREATE POLICY "admin_policy" ON sensitive_data AS RESTRICTIVE FOR SELECT TO admin_role USING (department = current_user_department()) WITH CHECK (approved = true)"`;
17-
18-
exports[`should format create_policy-2: pretty/create_policy-2.sql (pretty) 1`] = `
28+
exports[`pretty: pretty/create_policy-2.sql 1`] = `
1929
"CREATE POLICY "admin_policy"
2030
ON sensitive_data
2131
AS RESTRICTIVE
@@ -29,9 +39,7 @@ exports[`should format create_policy-2: pretty/create_policy-2.sql (pretty) 1`]
2939
)"
3040
`;
3141

32-
exports[`should format create_policy-3: pretty/create_policy-3.sql (non-pretty) 1`] = `"CREATE POLICY "complex_policy" ON documents AS PERMISSIVE FOR UPDATE TO document_editors USING (owner_id = current_user_id() OR (shared = true AND permissions @> '{"edit": true}')) WITH CHECK (status <> 'archived' AND last_modified > (now() - '1 day'::interval))"`;
33-
34-
exports[`should format create_policy-3: pretty/create_policy-3.sql (pretty) 1`] = `
42+
exports[`pretty: pretty/create_policy-3.sql 1`] = `
3543
"CREATE POLICY "complex_policy"
3644
ON documents
3745
AS PERMISSIVE
@@ -48,9 +56,7 @@ exports[`should format create_policy-3: pretty/create_policy-3.sql (pretty) 1`]
4856
)"
4957
`;
5058

51-
exports[`should format create_policy-4: pretty/create_policy-4.sql (non-pretty) 1`] = `"CREATE POLICY "simple_policy" ON posts AS PERMISSIVE FOR SELECT TO PUBLIC USING (published = true)"`;
52-
53-
exports[`should format create_policy-4: pretty/create_policy-4.sql (pretty) 1`] = `
59+
exports[`pretty: pretty/create_policy-4.sql 1`] = `
5460
"CREATE POLICY "simple_policy"
5561
ON posts
5662
AS PERMISSIVE
@@ -61,9 +67,7 @@ exports[`should format create_policy-4: pretty/create_policy-4.sql (pretty) 1`]
6167
)"
6268
`;
6369

64-
exports[`should format create_policy-5: pretty/create_policy-5.sql (non-pretty) 1`] = `"CREATE POLICY "simple_policy" ON posts AS PERMISSIVE FOR SELECT TO PUBLIC USING (published = true)"`;
65-
66-
exports[`should format create_policy-5: pretty/create_policy-5.sql (pretty) 1`] = `
70+
exports[`pretty: pretty/create_policy-5.sql 1`] = `
6771
"CREATE POLICY "simple_policy"
6872
ON posts
6973
AS PERMISSIVE
@@ -74,9 +78,7 @@ exports[`should format create_policy-5: pretty/create_policy-5.sql (pretty) 1`]
7478
)"
7579
`;
7680

77-
exports[`should format create_policy-6: pretty/create_policy-6.sql (non-pretty) 1`] = `"CREATE POLICY "Simple Policy" ON posts AS PERMISSIVE FOR SELECT TO PUBLIC USING (published = true)"`;
78-
79-
exports[`should format create_policy-6: pretty/create_policy-6.sql (pretty) 1`] = `
81+
exports[`pretty: pretty/create_policy-6.sql 1`] = `
8082
"CREATE POLICY "Simple Policy"
8183
ON posts
8284
AS PERMISSIVE
@@ -87,9 +89,7 @@ exports[`should format create_policy-6: pretty/create_policy-6.sql (pretty) 1`]
8789
)"
8890
`;
8991

90-
exports[`should format create_policy-7: pretty/create_policy-7.sql (non-pretty) 1`] = `"CREATE POLICY "simplepolicy" ON posts AS PERMISSIVE FOR SELECT TO PUBLIC USING (published = true)"`;
91-
92-
exports[`should format create_policy-7: pretty/create_policy-7.sql (pretty) 1`] = `
92+
exports[`pretty: pretty/create_policy-7.sql 1`] = `
9393
"CREATE POLICY "simplepolicy"
9494
ON posts
9595
AS PERMISSIVE

packages/deparser/__tests__/pretty/__snapshots__/create-table-pretty.test.ts.snap

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`should format create_table-1: pretty/create_table-1.sql (non-pretty) 1`] = `"CREATE TABLE users (id serial PRIMARY KEY, name text NOT NULL, email text UNIQUE)"`;
3+
exports[`non-pretty: pretty/create_table-1.sql 1`] = `"CREATE TABLE users (id serial PRIMARY KEY, name text NOT NULL, email text UNIQUE)"`;
44

5-
exports[`should format create_table-1: pretty/create_table-1.sql (pretty) 1`] = `
5+
exports[`non-pretty: pretty/create_table-2.sql 1`] = `"CREATE TABLE products (id serial PRIMARY KEY, name varchar(255) NOT NULL, price numeric(10, 2) CHECK (price > 0), category_id int, description text, created_at pg_catalog.timestamp DEFAULT now(), updated_at pg_catalog.timestamp, UNIQUE (name, category_id), FOREIGN KEY (category_id) REFERENCES categories (id))"`;
6+
7+
exports[`non-pretty: pretty/create_table-3.sql 1`] = `"CREATE TABLE orders (id serial PRIMARY KEY, subtotal numeric(10, 2) NOT NULL, tax_rate numeric(5, 4) DEFAULT 0.0825, tax_amount numeric(10, 2) GENERATED ALWAYS AS (subtotal * tax_rate) STORED, total numeric(10, 2) GENERATED ALWAYS AS (subtotal + tax_amount) STORED)"`;
8+
9+
exports[`non-pretty: pretty/create_table-4.sql 1`] = `"CREATE TABLE sales (id serial, sale_date date NOT NULL, amount numeric(10, 2), region varchar(50)) PARTITION BY RANGE (sale_date)"`;
10+
11+
exports[`non-pretty: pretty/create_table-5.sql 1`] = `"CREATE TEMPORARY TABLE temp_calculations (id int, value numeric(15, 5), result text)"`;
12+
13+
exports[`non-pretty: pretty/create_table-6.sql 1`] = `"CREATE TABLE orders (id serial PRIMARY KEY, user_id int NOT NULL, total numeric(10, 2) CHECK (total > 0), status varchar(20) DEFAULT 'pending', created_at pg_catalog.timestamp DEFAULT now(), FOREIGN KEY (user_id) REFERENCES users (id))"`;
14+
15+
exports[`pretty: pretty/create_table-1.sql 1`] = `
616
"CREATE TABLE users (
717
id serial PRIMARY KEY,
818
name text NOT NULL,
919
email text UNIQUE
1020
)"
1121
`;
1222

13-
exports[`should format create_table-2: pretty/create_table-2.sql (non-pretty) 1`] = `"CREATE TABLE products (id serial PRIMARY KEY, name varchar(255) NOT NULL, price numeric(10, 2) CHECK (price > 0), category_id int, description text, created_at pg_catalog.timestamp DEFAULT now(), updated_at pg_catalog.timestamp, UNIQUE (name, category_id), FOREIGN KEY (category_id) REFERENCES categories (id))"`;
14-
15-
exports[`should format create_table-2: pretty/create_table-2.sql (pretty) 1`] = `
23+
exports[`pretty: pretty/create_table-2.sql 1`] = `
1624
"CREATE TABLE products (
1725
id serial PRIMARY KEY,
1826
name varchar(255) NOT NULL,
@@ -26,9 +34,7 @@ exports[`should format create_table-2: pretty/create_table-2.sql (pretty) 1`] =
2634
)"
2735
`;
2836

29-
exports[`should format create_table-3: pretty/create_table-3.sql (non-pretty) 1`] = `"CREATE TABLE orders (id serial PRIMARY KEY, subtotal numeric(10, 2) NOT NULL, tax_rate numeric(5, 4) DEFAULT 0.0825, tax_amount numeric(10, 2) GENERATED ALWAYS AS (subtotal * tax_rate) STORED, total numeric(10, 2) GENERATED ALWAYS AS (subtotal + tax_amount) STORED)"`;
30-
31-
exports[`should format create_table-3: pretty/create_table-3.sql (pretty) 1`] = `
37+
exports[`pretty: pretty/create_table-3.sql 1`] = `
3238
"CREATE TABLE orders (
3339
id serial PRIMARY KEY,
3440
subtotal numeric(10, 2) NOT NULL,
@@ -38,9 +44,7 @@ exports[`should format create_table-3: pretty/create_table-3.sql (pretty) 1`] =
3844
)"
3945
`;
4046

41-
exports[`should format create_table-4: pretty/create_table-4.sql (non-pretty) 1`] = `"CREATE TABLE sales (id serial, sale_date date NOT NULL, amount numeric(10, 2), region varchar(50)) PARTITION BY RANGE (sale_date)"`;
42-
43-
exports[`should format create_table-4: pretty/create_table-4.sql (pretty) 1`] = `
47+
exports[`pretty: pretty/create_table-4.sql 1`] = `
4448
"CREATE TABLE sales (
4549
id serial,
4650
sale_date date NOT NULL,
@@ -49,19 +53,15 @@ exports[`should format create_table-4: pretty/create_table-4.sql (pretty) 1`] =
4953
) PARTITION BY RANGE (sale_date)"
5054
`;
5155

52-
exports[`should format create_table-5: pretty/create_table-5.sql (non-pretty) 1`] = `"CREATE TEMPORARY TABLE temp_calculations (id int, value numeric(15, 5), result text)"`;
53-
54-
exports[`should format create_table-5: pretty/create_table-5.sql (pretty) 1`] = `
56+
exports[`pretty: pretty/create_table-5.sql 1`] = `
5557
"CREATE TEMPORARY TABLE temp_calculations (
5658
id int,
5759
value numeric(15, 5),
5860
result text
5961
)"
6062
`;
6163

62-
exports[`should format create_table-6: pretty/create_table-6.sql (non-pretty) 1`] = `"CREATE TABLE orders (id serial PRIMARY KEY, user_id int NOT NULL, total numeric(10, 2) CHECK (total > 0), status varchar(20) DEFAULT 'pending', created_at pg_catalog.timestamp DEFAULT now(), FOREIGN KEY (user_id) REFERENCES users (id))"`;
63-
64-
exports[`should format create_table-6: pretty/create_table-6.sql (pretty) 1`] = `
64+
exports[`pretty: pretty/create_table-6.sql 1`] = `
6565
"CREATE TABLE orders (
6666
id serial PRIMARY KEY,
6767
user_id int NOT NULL,

packages/deparser/__tests__/pretty/__snapshots__/cte-pretty.test.ts.snap

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`should format cte-1: pretty/cte-1.sql (non-pretty) 1`] = `"WITH regional_sales AS (SELECT region, sum(sales_amount) AS total_sales FROM sales GROUP BY region) SELECT * FROM regional_sales"`;
3+
exports[`non-pretty: pretty/cte-1.sql 1`] = `"WITH regional_sales AS (SELECT region, sum(sales_amount) AS total_sales FROM sales GROUP BY region) SELECT * FROM regional_sales"`;
44

5-
exports[`should format cte-1: pretty/cte-1.sql (pretty) 1`] = `
5+
exports[`non-pretty: pretty/cte-2.sql 1`] = `"WITH regional_sales AS (SELECT region, sum(sales_amount) AS total_sales FROM sales GROUP BY region), top_regions AS (SELECT region FROM regional_sales WHERE total_sales > 1000000) SELECT * FROM top_regions"`;
6+
7+
exports[`non-pretty: pretty/cte-3.sql 1`] = `"WITH RECURSIVE employee_hierarchy AS (SELECT id, name, manager_id, 1 AS level FROM employees WHERE manager_id IS NULL UNION ALL SELECT e.id, e.name, e.manager_id, eh.level + 1 FROM employees AS e JOIN employee_hierarchy AS eh ON e.manager_id = eh.id) SELECT * FROM employee_hierarchy"`;
8+
9+
exports[`non-pretty: pretty/cte-4.sql 1`] = `"WITH sales_summary AS (SELECT region, product_category, sum(amount) AS total FROM sales GROUP BY region, product_category), regional_totals AS (SELECT region, sum(total) AS region_total FROM sales_summary GROUP BY region) SELECT s.region, s.product_category, s.total, r.region_total FROM sales_summary AS s JOIN regional_totals AS r ON s.region = r.region"`;
10+
11+
exports[`pretty: pretty/cte-1.sql 1`] = `
612
"WITH
713
regional_sales AS (SELECT
814
region,
@@ -14,9 +20,7 @@ SELECT *
1420
FROM regional_sales"
1521
`;
1622

17-
exports[`should format cte-2: pretty/cte-2.sql (non-pretty) 1`] = `"WITH regional_sales AS (SELECT region, sum(sales_amount) AS total_sales FROM sales GROUP BY region), top_regions AS (SELECT region FROM regional_sales WHERE total_sales > 1000000) SELECT * FROM top_regions"`;
18-
19-
exports[`should format cte-2: pretty/cte-2.sql (pretty) 1`] = `
23+
exports[`pretty: pretty/cte-2.sql 1`] = `
2024
"WITH
2125
regional_sales AS (SELECT
2226
region,
@@ -32,9 +36,7 @@ SELECT *
3236
FROM top_regions"
3337
`;
3438

35-
exports[`should format cte-3: pretty/cte-3.sql (non-pretty) 1`] = `"WITH RECURSIVE employee_hierarchy AS (SELECT id, name, manager_id, 1 AS level FROM employees WHERE manager_id IS NULL UNION ALL SELECT e.id, e.name, e.manager_id, eh.level + 1 FROM employees AS e JOIN employee_hierarchy AS eh ON e.manager_id = eh.id) SELECT * FROM employee_hierarchy"`;
36-
37-
exports[`should format cte-3: pretty/cte-3.sql (pretty) 1`] = `
39+
exports[`pretty: pretty/cte-3.sql 1`] = `
3840
"WITH RECURSIVE
3941
employee_hierarchy AS (SELECT
4042
id,
@@ -57,9 +59,7 @@ SELECT *
5759
FROM employee_hierarchy"
5860
`;
5961

60-
exports[`should format cte-4: pretty/cte-4.sql (non-pretty) 1`] = `"WITH sales_summary AS (SELECT region, product_category, sum(amount) AS total FROM sales GROUP BY region, product_category), regional_totals AS (SELECT region, sum(total) AS region_total FROM sales_summary GROUP BY region) SELECT s.region, s.product_category, s.total, r.region_total FROM sales_summary AS s JOIN regional_totals AS r ON s.region = r.region"`;
61-
62-
exports[`should format cte-4: pretty/cte-4.sql (pretty) 1`] = `
62+
exports[`pretty: pretty/cte-4.sql 1`] = `
6363
"WITH
6464
sales_summary AS (SELECT
6565
region,

0 commit comments

Comments
 (0)