|
1 | 1 | import { describe, it, expect } from 'vitest';
|
2 | 2 | import { Schema } from '../../../src/db/schema/Schema';
|
3 | 3 | import { Table } from '../../../src/db/schema/Table';
|
4 |
| -import { column, ColumnType } from '../../../src/db/schema/Column'; |
| 4 | +import { column, ColumnType, Column } from '../../../src/db/schema/Column'; |
5 | 5 |
|
6 | 6 | describe('Schema', () => {
|
7 |
| - it('should create a schema with an array of tables', () => { |
8 |
| - const tables = [ |
9 |
| - new Table({ name: column.text, }), |
10 |
| - new Table({ age: { type: ColumnType.INTEGER } }) |
11 |
| - ]; |
12 |
| - const schema = new Schema(tables); |
| 7 | + it('should fail if an array of tables using the new syntax is passed to schema', () => { |
| 8 | + const table1 = new Table({ name: column.text }); |
| 9 | + const table2 = new Table({ age: { type: ColumnType.INTEGER } }); |
| 10 | + expect(() => new Schema([table1, table2])).toThrow(); |
| 11 | + }); |
| 12 | + |
| 13 | + it('should create a schema with an array of tables using the old syntax', () => { |
| 14 | + const table1 = new Table({ |
| 15 | + name: 'table1', |
| 16 | + columns: [new Column({ name: 'name', type: ColumnType.TEXT })] |
| 17 | + }); |
| 18 | + const table2 = new Table({ |
| 19 | + name: 'table2', |
| 20 | + columns: [new Column({ name: 'age', type: ColumnType.INTEGER })] |
| 21 | + }); |
| 22 | + const schema = new Schema([table1, table2]); |
| 23 | + expect(() => schema.validate()).not.toThrow(); |
13 | 24 |
|
14 | 25 | expect(schema.tables).toHaveLength(2);
|
15 | 26 | expect(schema.tables[0].columns[0].name).toBe('name');
|
|
0 commit comments