1- import sqlFormatter from "sql-formatter" ;
1+ import { format } from "sql-formatter" ;
22import { postgres2Bigquery } from "../src/core" ;
33import { getTableRegexes } from "../src/utils" ;
44
@@ -25,24 +25,28 @@ describe("core", () => {
2525 ` ;
2626
2727 const bQuery = postgres2Bigquery ( query , "demo_dataset" , tableRegexes ) ;
28- expect ( bQuery ) . toBe ( sqlFormatter . format ( expectedQuery ) ) ;
28+ expect ( bQuery ) . toBe ( format ( expectedQuery ) ) ;
2929 } ) ;
3030
3131 it ( "should add prefix dataset to tables" , async ( ) => {
3232 const query = `
3333 SELECT created_at AS start_date, role, id
34- FROM users, roles
35- WHERE users.id = roles.user_id and role = 'admin';
34+ FROM users,
35+ roles
36+ WHERE users.id = roles.user_id
37+ and role = 'admin';
3638 ` ;
3739
3840 const expectedQuery = `
3941 SELECT created_at AS start_date, role, id
40- FROM demo_dataset.users, demo_dataset.roles
41- WHERE users.id = roles.user_id and role = 'admin';
42+ FROM demo_dataset.users,
43+ demo_dataset.roles
44+ WHERE users.id = roles.user_id
45+ and role = 'admin';
4246 ` ;
4347
4448 const bQuery = postgres2Bigquery ( query , "demo_dataset" , tableRegexes ) ;
45- expect ( bQuery ) . toBe ( sqlFormatter . format ( expectedQuery ) ) ;
49+ expect ( bQuery ) . toBe ( format ( expectedQuery ) ) ;
4650 } ) ;
4751
4852 it ( "should convert time calculations" , async ( ) => {
@@ -55,11 +59,12 @@ describe("core", () => {
5559 const expectedQuery = `
5660 SELECT *
5761 FROM demo_dataset.users
58- WHERE created_at > (TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY)) and created_at <= (TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 180 DAY));
62+ WHERE created_at > (TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 30 DAY))
63+ and created_at <= (TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 180 DAY));
5964 ` ;
6065
6166 const bQuery = postgres2Bigquery ( query , "demo_dataset" , tableRegexes ) ;
62- expect ( bQuery ) . toBe ( sqlFormatter . format ( expectedQuery ) ) ;
67+ expect ( bQuery ) . toBe ( format ( expectedQuery ) ) ;
6368 } ) ;
6469
6570 it ( "should find products with product id array" , async ( ) => {
@@ -76,7 +81,7 @@ describe("core", () => {
7681 ` ;
7782
7883 const bQuery = postgres2Bigquery ( query , "demo_dataset" , tableRegexes ) ;
79- expect ( bQuery ) . toBe ( sqlFormatter . format ( expectedQuery ) ) ;
84+ expect ( bQuery ) . toBe ( format ( expectedQuery ) ) ;
8085 } ) ;
8186
8287 it ( "should find products not in product id array" , async ( ) => {
@@ -93,24 +98,26 @@ describe("core", () => {
9398 ` ;
9499
95100 const bQuery = postgres2Bigquery ( query , "demo_dataset" , tableRegexes ) ;
96- expect ( bQuery ) . toBe ( sqlFormatter . format ( expectedQuery ) ) ;
101+ expect ( bQuery ) . toBe ( format ( expectedQuery ) ) ;
97102 } ) ;
98103
99104 it ( "should remove quotes for all numbers" , async ( ) => {
100105 const query = `
101106 SELECT *
102107 FROM products
103- WHERE id = '9' or id = 10;
108+ WHERE id = '9'
109+ or id = 10;
104110 ` ;
105111
106112 const expectedQuery = `
107113 SELECT *
108114 FROM demo_dataset.products
109- WHERE id = 9 or id = 10;
115+ WHERE id = 9
116+ or id = 10;
110117 ` ;
111118
112119 const bQuery = postgres2Bigquery ( query , "demo_dataset" , tableRegexes ) ;
113- expect ( bQuery ) . toBe ( sqlFormatter . format ( expectedQuery ) ) ;
120+ expect ( bQuery ) . toBe ( format ( expectedQuery ) ) ;
114121 } ) ;
115122
116123 it ( "should convert date_part function" , async ( ) => {
@@ -125,37 +132,37 @@ describe("core", () => {
125132 ` ;
126133
127134 const bQuery = postgres2Bigquery ( query , "demo_dataset" , tableRegexes ) ;
128- expect ( bQuery ) . toBe ( sqlFormatter . format ( expectedQuery ) ) ;
135+ expect ( bQuery ) . toBe ( format ( expectedQuery ) ) ;
129136 } ) ;
130137
131138 it ( "should cast else case of date_part to string" , async ( ) => {
132139 const query = `
133- SELECT
134- id,
135- name,
136- date_part('day'::text, created_at) AS year,
140+ SELECT id,
141+ name,
142+ date_part('day'::text, created_at) AS year,
137143 CASE
138144 WHEN date_part('month', created_at) < 10
139145 THEN concat('0', date_part('month', created_at))
140146 ELSE date_part('month', created_at)
141- END AS month
147+ END
148+ AS month
142149 FROM products;
143150 ` ;
144151
145152 const expectedQuery = `
146- SELECT
147- id,
148- name,
149- EXTRACT(DAY FROM created_at) AS year,
153+ SELECT id,
154+ name,
155+ EXTRACT(DAY FROM created_at) AS year,
150156 CASE
151157 WHEN EXTRACT(MONTH FROM created_at) < 10 THEN concat(0, EXTRACT(MONTH FROM created_at))
152158 ELSE CAST(EXTRACT(MONTH FROM created_at) AS STRING)
153- END AS month
159+ END
160+ AS month
154161 FROM
155162 demo_dataset.products;
156163 ` ;
157164
158165 const bQuery = postgres2Bigquery ( query , "demo_dataset" , tableRegexes ) ;
159- expect ( bQuery ) . toBe ( sqlFormatter . format ( expectedQuery ) ) ;
166+ expect ( bQuery ) . toBe ( format ( expectedQuery ) ) ;
160167 } ) ;
161168} ) ;
0 commit comments