UNPKG

jsonschema2ddl

Version:
58 lines (43 loc) 1.74 kB
import test from 'ava'; import fs from 'fs'; import { Column, Table } from '../src/models'; test('test column', t => { let simple: any = { "type": "integer" }; let column = new Column({ name: "simple", jsonschema_type: simple["type"], jsonschema_fields: simple }) t.is(column.name, "simple"); t.is(column.data_type, "bigint"); simple = { "type": "string" }; column = new Column({ name: "simple", jsonschema_type: simple["type"], jsonschema_fields: simple }); t.is(column.name, "simple"); t.is(column.data_type, "varchar(256)"); simple = { "type": "string", "maxLength": 1024 }; column = new Column({ name: "simple", jsonschema_type: simple["type"], jsonschema_fields: simple }); t.is(column.name, "simple"); t.is(column.data_type, "varchar(1024)"); }); test('test_column_hash', t => { let simple1 = { "type": "integer" }; let simple2 = { "type": "string" }; let columns = new Set(); let column1 = new Column({ name: "simple1", jsonschema_type: simple1["type"] }); let column2 = new Column({ name: "simple2", jsonschema_type: simple2["type"] }); columns.add(column1); columns.add(column2); columns.add(column2); t.is(columns.size, 2); }); test('test_table', t => { const data = fs.readFileSync('test/schema_flat.json', 'utf8'); const schema_flat = JSON.parse(data); console.log('schema_flat:', schema_flat); const root_table = new Table({ ref: "root", name: "root", database_flavor: "postgres", jsonschema_fields: schema_flat, }); t.is(root_table.name, "root"); t.is(root_table.ref, "root"); root_table.expand_columns({ table_definitions: { "root": root_table } }); t.is(root_table.columns.length, Object.keys(schema_flat["properties"]).length); });