Skip to content

Commit 484aff3

Browse files
committed
Use same adapter for PG tests, drop table to ensure the tests dont side effect
1 parent 71fd229 commit 484aff3

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

spec/PostgresInitOptions.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ describe_only_db('postgres')('Postgres database init options', () => {
7777
databaseOptions: databaseOptions2
7878
})
7979

80-
createParseServer({ databaseAdapter: adapter }).then(done.fail, done);
80+
createParseServer({ databaseAdapter: adapter }).then(done.fail, () => done);
8181
});
8282
});

spec/PostgresStorageAdapter.spec.js

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,17 @@ const getColumns = (client, className) => {
55
return client.map('SELECT column_name FROM information_schema.columns WHERE table_name = $<className>', { className }, a => a.column_name);
66
};
77

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 $<className:name>', { className });
10+
}
1711

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();
2516
});
2617

2718
it('schemaUpgrade, upgrade the database schema when schema changes', done => {
28-
const adapter = new PostgresStorageAdapter({ uri: databaseURI });
2919
const client = adapter._client;
3020
const className = '_PushStatus';
3121
const schema = {
@@ -59,7 +49,6 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
5949
});
6050

6151
it('schemaUpgrade, maintain correct schema', done => {
62-
const adapter = new PostgresStorageAdapter({ uri: databaseURI });
6352
const client = adapter._client;
6453
const className = 'Table';
6554
const schema = {
@@ -91,24 +80,21 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
9180
});
9281

9382
it('Create a table without columns and upgrade with columns', done => {
94-
const adapter = new PostgresStorageAdapter({ uri: databaseURI });
9583
const client = adapter._client;
9684
const className = 'EmptyTable';
97-
let schema = {};
98-
99-
adapter.createTable(className, schema)
85+
dropTable(client, className).then(() => adapter.createTable(className, {}))
10086
.then(() => getColumns(client, className))
10187
.then(columns => {
10288
expect(columns.length).toBe(0);
10389

104-
schema = {
90+
const newSchema = {
10591
fields: {
10692
"columnA": { type: 'String' },
10793
"columnB": { type: 'String' }
10894
},
10995
};
11096

111-
return adapter.schemaUpgrade(className, schema);
97+
return adapter.schemaUpgrade(className, newSchema);
11298
})
11399
.then(() => getColumns(client, className))
114100
.then(columns => {
@@ -117,6 +103,15 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
117103
expect(columns).toContain('columnB');
118104
done();
119105
})
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+
});
122117
});

0 commit comments

Comments
 (0)