-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathschematGeneration.test.ts
78 lines (75 loc) · 3.8 KB
/
schematGeneration.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import * as assert from 'power-assert'
import { Database, getDatabase } from '../../src/index'
import { writeTsFile, compare, loadSchema } from '../testUtility'
describe('schemat generation integration testing', () => {
describe('postgres', () => {
let db: Database
before(async function () {
if (!process.env.POSTGRES_URL) {
return this.skip()
}
db = getDatabase(process.env.POSTGRES_URL)
await loadSchema(db, './test/fixture/postgres/initCleanup.sql')
})
it('Basic generation', async () => {
const inputSQLFile = 'test/fixture/postgres/osm.sql'
const outputFile = './test/actual/postgres/osm.ts'
const expectedFile = './test/expected/postgres/osm.ts'
const config: any = './fixture/postgres/osm.json'
await writeTsFile(inputSQLFile, config, outputFile, db)
return assert(await compare(expectedFile, outputFile))
})
it('Camelcase generation', async () => {
const inputSQLFile = 'test/fixture/postgres/osm.sql'
const outputFile = './test/actual/postgres/osm-camelcase.ts'
const expectedFile = './test/expected/postgres/osm-camelcase.ts'
const config: any = './fixture/postgres/osm-camelcase.json'
await writeTsFile(inputSQLFile, config, outputFile, db)
return assert(await compare(expectedFile, outputFile))
})
it('Camelcase (types only) generation', async () => {
const inputSQLFile = 'test/fixture/postgres/osm.sql'
const outputFile = './test/actual/postgres/osm-camelcase-types.ts'
const expectedFile = './test/expected/postgres/osm-camelcase-types.ts'
const config: any = './fixture/postgres/osm-camelcase-types.json'
await writeTsFile(inputSQLFile, config, outputFile, db)
return assert(await compare(expectedFile, outputFile))
})
it('Camelcase (columns only) generation', async () => {
const inputSQLFile = 'test/fixture/postgres/osm.sql'
const outputFile = './test/actual/postgres/osm-camelcase-columns.ts'
const expectedFile = './test/expected/postgres/osm-camelcase-columns.ts'
const config: any = './fixture/postgres/osm-camelcase-columns.json'
await writeTsFile(inputSQLFile, config, outputFile, db)
return assert(await compare(expectedFile, outputFile))
})
})
describe('mysql', () => {
let db: Database
before(async function () {
if (!process.env.MYSQL_URL) {
return this.skip()
}
db = getDatabase(`${process.env.MYSQL_URL}?multipleStatements=true`)
await loadSchema(db, './test/fixture/mysql/initCleanup.sql')
})
it ('Basic generation', async () => {
const inputSQLFile = 'test/fixture/mysql/osm.sql'
const outputFile = './test/actual/mysql/osm.ts'
const expectedFile = './test/expected/mysql/osm.ts'
const config: any = './fixture/mysql/osm.json'
await writeTsFile(inputSQLFile, config, outputFile, db)
return assert(await compare(expectedFile, outputFile))
})
it('Enum conflict in columns', async () => {
const inputSQLFile = 'test/fixture/mysql/conflict.sql'
const outputFile = './test/actual/mysql/conflict.ts'
const config: any = './fixture/mysql/conflict.json'
try {
await writeTsFile(inputSQLFile, config, outputFile, db)
} catch (e) {
assert.equal(e.message, 'Multiple enums with the same name and contradicting types were found: location_type: ["city","province","country"] and ["city","state","country"]')
}
})
})
})