Skip to content

Commit 01c9f24

Browse files
committed
tests for every type
1 parent 7c217c2 commit 01c9f24

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

sqldef.test.js

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,65 @@ test('should be able to diff some mysql', async ({ assert }) => {
1717
) Engine=InnoDB DEFAULT CHARSET=utf8mb4;
1818
`
1919
const r = await sqldef('mysql', sql1, sql2)
20-
assert.equal(r, 'ALTER TABLE `user` DROP COLUMN `created_at`')
20+
assert.snapshot(r)
21+
})
22+
23+
test('should be able to diff some mssql', async ({ assert }) => {
24+
const sql1 = `
25+
CREATE TABLE dbo.Employee (
26+
EmployeeID INT PRIMARY KEY
27+
);
28+
`
29+
30+
const sql2 = `
31+
CREATE TABLE dbo.Employee (
32+
Employee INT PRIMARY KEY
33+
);
34+
`
35+
const r = await sqldef('mssql', sql1, sql2)
36+
assert.snapshot(r)
37+
})
38+
39+
test('should be able to diff some sqlite', async ({ assert }) => {
40+
const sql1 = `
41+
CREATE TABLE IF NOT EXISTS user (
42+
id INT PRIMARY KEY
43+
);
44+
`
45+
46+
const sql2 = `
47+
CREATE TABLE IF NOT EXISTS user (
48+
id INT PRIMARY KEY,
49+
name VARCHAR NOT NULL
50+
);
51+
`
52+
const r = await sqldef('sqlite', sql1, sql2)
53+
assert.snapshot(r)
54+
})
55+
56+
test('should be able to diff some postgres', async ({ assert }) => {
57+
const sql1 = `
58+
CREATE TABLE IF NOT EXISTS user (
59+
id INT PRIMARY KEY
60+
);
61+
`
62+
63+
const sql2 = `
64+
CREATE TABLE IF NOT EXISTS user (
65+
id INT PRIMARY KEY,
66+
name VARCHAR NOT NULL,
67+
location point
68+
);
69+
`
70+
const r = await sqldef('postgres', sql1, sql2)
71+
assert.snapshot(r)
2172
})
2273

2374
test('should throw on bad SQL', async ({assert}) => {
2475
try {
2576
await sqldef('mysql', 'BAD STUFF', 'NOT SQL, SORRRY')
2677
assert.equal(true, 'Should have thrown')
2778
} catch(e) {
28-
assert.equal(true, e.message.includes('found syntax error when parsing DDL'), `Error is not correct: ${e.message}`)
79+
assert.snapshot(e.message)
2980
}
3081
})

sqldef.test.js.snapshot

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
exports[`should be able to diff some mssql 1`] = `
2+
"ALTER TABLE [dbo].[Employee] ADD [EmployeeID] int NOT NULL;\\nALTER TABLE [dbo].[Employee] DROP CONSTRAINT [PRIMARY];\\nALTER TABLE [dbo].[Employee] ADD PRIMARY KEY CLUSTERED ([EmployeeID]);\\nALTER TABLE [dbo].[Employee] DROP COLUMN [Employee]"
3+
`;
4+
5+
exports[`should be able to diff some mysql 1`] = `
6+
"ALTER TABLE \`user\` DROP COLUMN \`created_at\`"
7+
`;
8+
9+
exports[`should be able to diff some postgres 1`] = `
10+
"ALTER TABLE \\"\\".\\"user\\" DROP COLUMN \\"name\\";\\nALTER TABLE \\"\\".\\"user\\" DROP COLUMN \\"location\\""
11+
`;
12+
13+
exports[`should be able to diff some sqlite 1`] = `
14+
"ALTER TABLE \`user\` CHANGE COLUMN \`id\` \`id\` int NOT NULL;\\nALTER TABLE \`user\` DROP COLUMN \`name\`"
15+
`;
16+
17+
exports[`should throw on bad SQL 1`] = `
18+
"found syntax error when parsing DDL \\"BAD STUFF\\": syntax error at position 4 near 'BAD'"
19+
`;

0 commit comments

Comments
 (0)