committed by
Arthur Cinader
parent
ab04641ed0
commit
9dbb89a2e4
@@ -1,7 +1,7 @@
|
|||||||
const Parse = require('parse/node').Parse;
|
const Parse = require('parse/node').Parse;
|
||||||
const PostgresStorageAdapter = require('../src/Adapters/Storage/Postgres/PostgresStorageAdapter');
|
const PostgresStorageAdapter = require('../src/Adapters/Storage/Postgres/PostgresStorageAdapter');
|
||||||
const postgresURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
|
const postgresURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
|
||||||
|
const Config = require('../src/Config');
|
||||||
//public schema
|
//public schema
|
||||||
const databaseOptions1 = {
|
const databaseOptions1 = {
|
||||||
initOptions: {
|
initOptions: {
|
||||||
@@ -28,33 +28,40 @@ const GameScore = Parse.Object.extend({
|
|||||||
className: "GameScore"
|
className: "GameScore"
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Postgres database init options', () => {
|
describe_only_db('postgres')('Postgres database init options', () => {
|
||||||
it('should create server with public schema databaseOptions', (done) => {
|
it('should create server with public schema databaseOptions', (done) => {
|
||||||
|
const config = new Config('test');
|
||||||
|
// Close the current DB before continueing
|
||||||
|
config.database.adapter._pgp.end();
|
||||||
reconfigureServer({
|
reconfigureServer({
|
||||||
databaseAdapter: new PostgresStorageAdapter({
|
databaseAdapter: new PostgresStorageAdapter({
|
||||||
uri: postgresURI, collectionPrefix: 'test_',
|
uri: postgresURI, collectionPrefix: 'test_',
|
||||||
databaseOptions: databaseOptions1
|
databaseOptions: databaseOptions1
|
||||||
})
|
})
|
||||||
}).then(done, fail);
|
}).then(done, done.fail);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("save new GameScore in public schema", function (done) {
|
it("save new GameScore in public schema", function (done) {
|
||||||
var score = new GameScore({ "score": 1337, "playerName": "Sean Plott", "cheatMode": false });
|
var score = new GameScore({ "score": 1337, "playerName": "Sean Plott", "cheatMode": false });
|
||||||
score.save().then(done, fail);
|
score.save().then(done, done.fail);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to create server if schema databaseOptions does not exist', (done) => {
|
it('should fail to create server if schema databaseOptions does not exist', (done) => {
|
||||||
|
const config = new Config('test');
|
||||||
|
// Close the current DB before continueing
|
||||||
|
config.database.adapter._pgp.end();
|
||||||
reconfigureServer({
|
reconfigureServer({
|
||||||
databaseAdapter: new PostgresStorageAdapter({
|
databaseAdapter: new PostgresStorageAdapter({
|
||||||
uri: postgresURI, collectionPrefix: 'test_',
|
uri: postgresURI, collectionPrefix: 'test_',
|
||||||
databaseOptions: databaseOptions2
|
databaseOptions: databaseOptions2
|
||||||
})
|
})
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
|
done.fail('Should not succeed');
|
||||||
|
}, error => {
|
||||||
|
// INVALID_SCHEMA error 3F000
|
||||||
|
// https://www.postgresql.org/docs/9.5/static/errcodes-appendix.html
|
||||||
|
expect(error.code).toEqual('3F000');
|
||||||
done();
|
done();
|
||||||
})
|
});
|
||||||
.catch(error => {
|
|
||||||
expect(error.code).toEqual('42P01');
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -23,5 +23,5 @@ export function createClient(uri, databaseOptions) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return client;
|
return { client, pgp };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -403,6 +403,7 @@ export class PostgresStorageAdapter {
|
|||||||
// Private
|
// Private
|
||||||
_collectionPrefix: string;
|
_collectionPrefix: string;
|
||||||
_client;
|
_client;
|
||||||
|
_pgp;
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
uri,
|
uri,
|
||||||
@@ -410,7 +411,9 @@ export class PostgresStorageAdapter {
|
|||||||
databaseOptions
|
databaseOptions
|
||||||
}) {
|
}) {
|
||||||
this._collectionPrefix = collectionPrefix;
|
this._collectionPrefix = collectionPrefix;
|
||||||
this._client = createClient(uri, databaseOptions);
|
const { client, pgp } = createClient(uri, databaseOptions);
|
||||||
|
this._client = client;
|
||||||
|
this._pgp = pgp;
|
||||||
}
|
}
|
||||||
|
|
||||||
_ensureSchemaCollectionExists(conn) {
|
_ensureSchemaCollectionExists(conn) {
|
||||||
|
|||||||
Reference in New Issue
Block a user