@@ -5,27 +5,17 @@ const getColumns = (client, className) => {
5
5
return client . map ( 'SELECT column_name FROM information_schema.columns WHERE table_name = $<className>' , { className } , a => a . column_name ) ;
6
6
} ;
7
7
8
- describe_only_db ( 'postgres' ) ( 'PostgresStorageAdapter' , ( ) => {
9
- beforeEach ( done => {
10
- const adapter = new PostgresStorageAdapter ( { uri : databaseURI } )
11
- . deleteAllClasses ( )
12
- . then ( ( ) => {
13
- adapter . handleShutdown ( ) ;
14
- } , fail )
15
- . catch ( done ) ;
16
- } ) ;
8
+ const dropTable = ( client , className ) => {
9
+ return client . none ( 'DROP TABLE IF EXISTS $<className:name>' , { className } ) ;
10
+ }
17
11
18
- it ( 'handleShutdown, close connection' , ( done ) => {
19
- const adapter = new PostgresStorageAdapter ( { uri : databaseURI } ) ;
20
-
21
- expect ( adapter . _client . $pool . ending ) . toEqual ( false ) ;
22
- adapter . handleShutdown ( ) ;
23
- expect ( adapter . _client . $pool . ending ) . toEqual ( true ) ;
24
- done ( ) ;
12
+ describe_only_db ( 'postgres' ) ( 'PostgresStorageAdapter' , ( ) => {
13
+ const adapter = new PostgresStorageAdapter ( { uri : databaseURI } )
14
+ beforeEach ( ( ) => {
15
+ return adapter . deleteAllClasses ( ) ;
25
16
} ) ;
26
17
27
18
it ( 'schemaUpgrade, upgrade the database schema when schema changes' , done => {
28
- const adapter = new PostgresStorageAdapter ( { uri : databaseURI } ) ;
29
19
const client = adapter . _client ;
30
20
const className = '_PushStatus' ;
31
21
const schema = {
@@ -59,7 +49,6 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
59
49
} ) ;
60
50
61
51
it ( 'schemaUpgrade, maintain correct schema' , done => {
62
- const adapter = new PostgresStorageAdapter ( { uri : databaseURI } ) ;
63
52
const client = adapter . _client ;
64
53
const className = 'Table' ;
65
54
const schema = {
@@ -91,24 +80,21 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
91
80
} ) ;
92
81
93
82
it ( 'Create a table without columns and upgrade with columns' , done => {
94
- const adapter = new PostgresStorageAdapter ( { uri : databaseURI } ) ;
95
83
const client = adapter . _client ;
96
84
const className = 'EmptyTable' ;
97
- let schema = { } ;
98
-
99
- adapter . createTable ( className , schema )
85
+ dropTable ( client , className ) . then ( ( ) => adapter . createTable ( className , { } ) )
100
86
. then ( ( ) => getColumns ( client , className ) )
101
87
. then ( columns => {
102
88
expect ( columns . length ) . toBe ( 0 ) ;
103
89
104
- schema = {
90
+ const newSchema = {
105
91
fields : {
106
92
"columnA" : { type : 'String' } ,
107
93
"columnB" : { type : 'String' }
108
94
} ,
109
95
} ;
110
96
111
- return adapter . schemaUpgrade ( className , schema ) ;
97
+ return adapter . schemaUpgrade ( className , newSchema ) ;
112
98
} )
113
99
. then ( ( ) => getColumns ( client , className ) )
114
100
. then ( columns => {
@@ -117,6 +103,15 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
117
103
expect ( columns ) . toContain ( 'columnB' ) ;
118
104
done ( ) ;
119
105
} )
120
- . catch ( error => done . fail ( error ) ) ;
121
- } )
106
+ . catch ( done ) ;
107
+ } ) ;
108
+ } ) ;
109
+
110
+ describe_only_db ( 'postgres' ) ( 'PostgresStorageAdapter shutdown' , ( ) => {
111
+ it ( 'handleShutdown, close connection' , ( ) => {
112
+ const adapter = new PostgresStorageAdapter ( { uri : databaseURI } ) ;
113
+ expect ( adapter . _client . $pool . ending ) . toEqual ( false ) ;
114
+ adapter . handleShutdown ( ) ;
115
+ expect ( adapter . _client . $pool . ending ) . toEqual ( true ) ;
116
+ } ) ;
122
117
} ) ;
0 commit comments