File tree Expand file tree Collapse file tree 2 files changed +83
-8
lines changed Expand file tree Collapse file tree 2 files changed +83
-8
lines changed Original file line number Diff line number Diff line change @@ -3,11 +3,8 @@ import { PostgresMeta } from "."
3
3
export default class TypeScriptTypes {
4
4
pgMeta : PostgresMeta
5
5
6
- constructor ( ) {
7
- this . pgMeta = new PostgresMeta ( {
8
- connectionString : "postgres://postgres:postgres@localhost:5432/postgres" ,
9
- max : 1
10
- } )
6
+ constructor ( { pgMeta } : { pgMeta : PostgresMeta } ) {
7
+ this . pgMeta = pgMeta ;
11
8
}
12
9
13
10
async dump ( ) : Promise < any > {
@@ -27,6 +24,3 @@ export default class TypeScriptTypes {
27
24
}
28
25
}
29
26
}
30
-
31
-
32
- new TypeScriptTypes ( ) . dump ( ) . then ( console . log )
Original file line number Diff line number Diff line change
1
+ var assert = require ( 'assert' )
2
+ var sinon = require ( 'sinon' )
3
+
4
+ import TypeScriptTypes from '../../bin/src/lib/TypeScriptTypes'
5
+ import { PostgresMeta } from '../../bin/src/lib'
6
+
7
+
8
+ describe ( 'dump()' , ( ) => {
9
+ it ( 'returns a string of TypeScript types' , async ( ) => {
10
+ const pgMeta = new PostgresMeta ( { connectionString : '' , max : 1 } )
11
+ const columnsData = [
12
+ {
13
+ table_id : 16402 ,
14
+ schema : 'public' ,
15
+ table : 'todos' ,
16
+ id : '16402.1' ,
17
+ ordinal_position : 1 ,
18
+ name : 'id' ,
19
+ default_value : null ,
20
+ data_type : 'bigint' ,
21
+ format : 'int8' ,
22
+ is_identity : true ,
23
+ identity_generation : 'BY DEFAULT' ,
24
+ is_nullable : false ,
25
+ is_updatable : true ,
26
+ enums : [ ] ,
27
+ comment : null
28
+ } ,
29
+ {
30
+ table_id : 16402 ,
31
+ schema : 'public' ,
32
+ table : 'todos' ,
33
+ id : '16402.2' ,
34
+ ordinal_position : 2 ,
35
+ name : 'details' ,
36
+ default_value : null ,
37
+ data_type : 'text' ,
38
+ format : 'text' ,
39
+ is_identity : false ,
40
+ identity_generation : null ,
41
+ is_nullable : true ,
42
+ is_updatable : true ,
43
+ enums : [ ] ,
44
+ comment : null
45
+ } ,
46
+ {
47
+ table_id : 16402 ,
48
+ schema : 'public' ,
49
+ table : 'todos' ,
50
+ id : '16402.3' ,
51
+ ordinal_position : 3 ,
52
+ name : 'user-id' ,
53
+ default_value : null ,
54
+ data_type : 'bigint' ,
55
+ format : 'int8' ,
56
+ is_identity : false ,
57
+ identity_generation : null ,
58
+ is_nullable : false ,
59
+ is_updatable : true ,
60
+ enums : [ ] ,
61
+ comment : null
62
+ } ,
63
+ ]
64
+ sinon
65
+ . stub ( pgMeta . columns , "list" )
66
+ . returns ( Promise . resolve ( { data : columnsData } ) )
67
+
68
+ const example = new TypeScriptTypes ( { pgMeta : pgMeta } ) ;
69
+
70
+ // TODO: ewww
71
+ const expected = `export interface definitions {
72
+ todos: {
73
+ id: number;
74
+ details?: string;
75
+ user_id: number;
76
+ };
77
+ }`
78
+
79
+ assert . equal ( await example . dump ( ) , expected )
80
+ } )
81
+ } )
You can’t perform that action at this time.
0 commit comments