* chore(package): update jasmine to version 3.0.0 Closes #4547 * Fixes failing tests for jasmine 3.0 Starting 3.0, done(something) will fail * Update tests so they dont leverage var, but let and const With jasmine 3.0, the randomization engine was making the test fails because of the scope of `var` * Remove randomizer * Use same adapter for PG tests, drop table to ensure the tests dont side effect
83 lines
2.4 KiB
JavaScript
83 lines
2.4 KiB
JavaScript
const Parse = require('parse/node').Parse;
|
|
import PostgresStorageAdapter from '../src/Adapters/Storage/Postgres/PostgresStorageAdapter';
|
|
const postgresURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
|
|
const ParseServer = require("../src/index");
|
|
const express = require('express');
|
|
//public schema
|
|
const databaseOptions1 = {
|
|
initOptions: {
|
|
connect: function (client, dc, isFresh) {
|
|
if (isFresh) {
|
|
client.query('SET search_path = public');
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
//not exists schema
|
|
const databaseOptions2 = {
|
|
initOptions: {
|
|
connect: function (client, dc, isFresh) {
|
|
if (isFresh) {
|
|
client.query('SET search_path = not_exists_schema');
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
const GameScore = Parse.Object.extend({
|
|
className: "GameScore"
|
|
});
|
|
|
|
function createParseServer(options) {
|
|
return new Promise((resolve, reject) => {
|
|
const parseServer = new ParseServer.default(Object.assign({},
|
|
defaultConfiguration, options, {
|
|
serverURL: "http://localhost:12666/parse",
|
|
__indexBuildCompletionCallbackForTests: promise => {
|
|
promise
|
|
.then(() => {
|
|
expect(Parse.applicationId).toEqual("test");
|
|
const app = express();
|
|
app.use('/parse', parseServer.app);
|
|
|
|
const server = app.listen(12666);
|
|
Parse.serverURL = "http://localhost:12666/parse";
|
|
resolve(server);
|
|
}, reject);
|
|
}}));
|
|
});
|
|
}
|
|
|
|
describe_only_db('postgres')('Postgres database init options', () => {
|
|
let server;
|
|
|
|
afterEach(() => {
|
|
if (server) {
|
|
server.close();
|
|
}
|
|
})
|
|
|
|
it('should create server with public schema databaseOptions', (done) => {
|
|
const adapter = new PostgresStorageAdapter({
|
|
uri: postgresURI, collectionPrefix: 'test_',
|
|
databaseOptions: databaseOptions1
|
|
})
|
|
|
|
createParseServer({ databaseAdapter: adapter }).then((newServer) => {
|
|
server = newServer;
|
|
const score = new GameScore({ "score": 1337, "playerName": "Sean Plott", "cheatMode": false });
|
|
return score.save();
|
|
}).then(done, done.fail);
|
|
});
|
|
|
|
it('should fail to create server if schema databaseOptions does not exist', (done) => {
|
|
const adapter = new PostgresStorageAdapter({
|
|
uri: postgresURI, collectionPrefix: 'test_',
|
|
databaseOptions: databaseOptions2
|
|
})
|
|
|
|
createParseServer({ databaseAdapter: adapter }).then(done.fail, () => done());
|
|
});
|
|
});
|