Skip to content

Commit 7618a25

Browse files
authored
Merge branch 'alpha' into postgresURI
2 parents b176032 + 7af5de4 commit 7618a25

7 files changed

+90
-108
lines changed

changelogs/CHANGELOG_alpha.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# [5.0.0-alpha.15](https://github.com/parse-community/parse-server/compare/5.0.0-alpha.14...5.0.0-alpha.15) (2022-01-02)
2+
3+
4+
### Features
5+
6+
* support `postgresql` protocol in database URI ([#7757](https://github.com/parse-community/parse-server/issues/7757)) ([caf4a23](https://github.com/parse-community/parse-server/commit/caf4a2341f554b28e3918c53e7e897a3ca47bf8b))
7+
18
# [5.0.0-alpha.14](https://github.com/parse-community/parse-server/compare/5.0.0-alpha.13...5.0.0-alpha.14) (2022-01-02)
29

310

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "parse-server",
3-
"version": "5.0.0-alpha.14",
3+
"version": "5.0.0-alpha.15",
44
"description": "An express module providing a Parse-compatible API server",
55
"main": "lib/index.js",
66
"repository": {

spec/ParseGraphQLServer.spec.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2600,11 +2600,19 @@ describe('ParseGraphQLServer', () => {
26002600
// "SecondaryObject:bBRgmzIRRM" < "SecondaryObject:nTMcuVbATY" true
26012601
// base64("SecondaryObject:bBRgmzIRRM"") < base64(""SecondaryObject:nTMcuVbATY"") false
26022602
// "U2Vjb25kYXJ5T2JqZWN0OmJCUmdteklSUk0=" < "U2Vjb25kYXJ5T2JqZWN0Om5UTWN1VmJBVFk=" false
2603+
const originalIds = [getSecondaryObjectsResult.data.secondaryObject2.objectId,
2604+
getSecondaryObjectsResult.data.secondaryObject4.objectId];
26032605
expect(
26042606
findSecondaryObjectsResult.data.secondaryObjects.edges[0].node.objectId
2605-
).toBeLessThan(
2607+
).not.toBe(
26062608
findSecondaryObjectsResult.data.secondaryObjects.edges[1].node.objectId
26072609
);
2610+
expect(
2611+
originalIds.includes(findSecondaryObjectsResult.data.secondaryObjects.edges[0].node.objectId)
2612+
).toBeTrue();
2613+
expect(
2614+
originalIds.includes(findSecondaryObjectsResult.data.secondaryObjects.edges[1].node.objectId)
2615+
).toBeTrue();
26082616

26092617
const createPrimaryObjectResult = await apolloClient.mutate({
26102618
mutation: gql`

spec/PostgresInitOptions.spec.js

Lines changed: 38 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/Postgre
44
const postgresURI =
55
process.env.PARSE_SERVER_TEST_DATABASE_URI ||
66
'postgres://localhost:5432/parse_server_postgres_adapter_test_database';
7-
const ParseServer = require('../lib/index');
8-
const express = require('express');
7+
98
//public schema
109
const databaseOptions1 = {
1110
initOptions: {
@@ -24,72 +23,57 @@ const GameScore = Parse.Object.extend({
2423
className: 'GameScore',
2524
});
2625

27-
function createParseServer(options) {
28-
return new Promise((resolve, reject) => {
29-
const parseServer = new ParseServer.default(
30-
Object.assign({}, defaultConfiguration, options, {
31-
serverURL: 'http://localhost:12668/parse',
32-
serverStartComplete: error => {
33-
if (error) {
34-
reject(error);
35-
} else {
36-
expect(Parse.applicationId).toEqual('test');
37-
const app = express();
38-
app.use('/parse', parseServer.app);
39-
40-
const server = app.listen(12668);
41-
Parse.serverURL = 'http://localhost:12668/parse';
42-
resolve(server);
43-
}
44-
},
45-
})
46-
);
47-
});
48-
}
49-
5026
describe_only_db('postgres')('Postgres database init options', () => {
51-
let server;
52-
53-
afterAll(done => {
54-
if (server) {
55-
Parse.serverURL = 'http://localhost:8378/1';
56-
server.close(done);
57-
}
58-
});
5927

60-
it('should create server with public schema databaseOptions', done => {
28+
it('should create server with public schema databaseOptions', async () => {
6129
const adapter = new PostgresStorageAdapter({
6230
uri: postgresURI,
6331
collectionPrefix: 'test_',
6432
databaseOptions: databaseOptions1,
6533
});
34+
await reconfigureServer({
35+
databaseAdapter: adapter,
36+
});
37+
const score = new GameScore({
38+
score: 1337,
39+
playerName: 'Sean Plott',
40+
cheatMode: false,
41+
});
42+
await score.save();
43+
});
6644

67-
createParseServer({ databaseAdapter: adapter })
68-
.then(newServer => {
69-
server = newServer;
70-
const score = new GameScore({
71-
score: 1337,
72-
playerName: 'Sean Plott',
73-
cheatMode: false,
74-
});
75-
return score.save();
76-
})
77-
.then(async () => {
78-
await reconfigureServer();
79-
done();
80-
}, done.fail);
45+
it('should create server using postgresql uri with public schema databaseOptions', async () => {
46+
const postgresURI2 = new URL(postgresURI);
47+
postgresURI2.protocol = 'postgresql:';
48+
const adapter = new PostgresStorageAdapter({
49+
uri: postgresURI2.toString(),
50+
collectionPrefix: 'test_',
51+
databaseOptions: databaseOptions1,
52+
});
53+
await reconfigureServer({
54+
databaseAdapter: adapter,
55+
});
56+
const score = new GameScore({
57+
score: 1337,
58+
playerName: 'Sean Plott',
59+
cheatMode: false,
60+
});
61+
await score.save();
8162
});
8263

83-
it('should fail to create server if schema databaseOptions does not exist', done => {
64+
it('should fail to create server if schema databaseOptions does not exist', async () => {
8465
const adapter = new PostgresStorageAdapter({
8566
uri: postgresURI,
8667
collectionPrefix: 'test_',
8768
databaseOptions: databaseOptions2,
8869
});
89-
90-
createParseServer({ databaseAdapter: adapter }).then(done.fail, async () => {
91-
await reconfigureServer();
92-
done();
93-
});
70+
try {
71+
await reconfigureServer({
72+
databaseAdapter: adapter,
73+
});
74+
fail("Should have thrown error");
75+
} catch(error) {
76+
expect(error).toBeDefined();
77+
}
9478
});
9579
});

spec/PostgresStorageAdapter.spec.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ describe_only_db('postgres')('PostgresStorageAdapter', () => {
555555
},
556556
classLevelPermissions: undefined,
557557
});
558-
await new Promise(resolve => setTimeout(resolve, 500));
558+
await new Promise(resolve => setTimeout(resolve, 2000));
559559
expect(adapter._onchange).toHaveBeenCalled();
560560
});
561561
});
@@ -567,4 +567,13 @@ describe_only_db('postgres')('PostgresStorageAdapter shutdown', () => {
567567
adapter.handleShutdown();
568568
expect(adapter._client.$pool.ending).toEqual(true);
569569
});
570+
571+
it('handleShutdown, close connection of postgresql uri', () => {
572+
const databaseURI2 = new URL(databaseURI);
573+
databaseURI2.protocol = 'postgresql:';
574+
const adapter = new PostgresStorageAdapter({ uri: databaseURI2.toString() });
575+
expect(adapter._client.$pool.ending).toEqual(false);
576+
adapter.handleShutdown();
577+
expect(adapter._client.$pool.ending).toEqual(true);
578+
});
570579
});

spec/PushController.spec.js

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,7 @@ describe('PushController', () => {
562562
});
563563
const pushStatusId = await sendPush(payload, {}, config, auth);
564564
// it is enqueued so it can take time
565-
await new Promise(resolve => {
566-
setTimeout(() => {
567-
resolve();
568-
}, 1000);
569-
});
565+
await sleep(1000);
570566
Parse.serverURL = 'http://localhost:8378/1'; // GOOD url
571567
const result = await Parse.Push.getPushStatus(pushStatusId);
572568
expect(result).toBeDefined();
@@ -767,7 +763,7 @@ describe('PushController', () => {
767763
});
768764
});
769765

770-
it('should not schedule push when not configured', done => {
766+
it('should not schedule push when not configured', async () => {
771767
const config = Config.get(Parse.applicationId);
772768
const auth = {
773769
isMaster: true,
@@ -800,33 +796,20 @@ describe('PushController', () => {
800796
installations.push(installation);
801797
}
802798

803-
reconfigureServer({
799+
await reconfigureServer({
804800
push: { adapter: pushAdapter },
805-
})
806-
.then(() => {
807-
return Parse.Object.saveAll(installations)
808-
.then(() => {
809-
return pushController.sendPush(payload, {}, config, auth);
810-
})
811-
.then(() => new Promise(resolve => setTimeout(resolve, 300)));
812-
})
813-
.then(() => {
814-
const query = new Parse.Query('_PushStatus');
815-
return query.find({ useMasterKey: true }).then(results => {
816-
expect(results.length).toBe(1);
817-
const pushStatus = results[0];
818-
expect(pushStatus.get('status')).not.toBe('scheduled');
819-
done();
820-
});
821-
})
822-
.catch(err => {
823-
console.error(err);
824-
fail('should not fail');
825-
done();
826-
});
801+
});
802+
await Parse.Object.saveAll(installations);
803+
await pushController.sendPush(payload, {}, config, auth);
804+
await sleep(1000);
805+
const query = new Parse.Query('_PushStatus');
806+
const results = await query.find({ useMasterKey: true });
807+
expect(results.length).toBe(1);
808+
const pushStatus = results[0];
809+
expect(pushStatus.get('status')).not.toBe('scheduled');
827810
});
828811

829-
it('should schedule push when configured', done => {
812+
it('should schedule push when configured', async () => {
830813
const auth = {
831814
isMaster: true,
832815
};
@@ -866,28 +849,19 @@ describe('PushController', () => {
866849
installation.set('deviceType', 'ios');
867850
installations.push(installation);
868851
}
869-
reconfigureServer({
852+
await reconfigureServer({
870853
push: { adapter: pushAdapter },
871854
scheduledPush: true,
872-
})
873-
.then(() => {
874-
const config = Config.get(Parse.applicationId);
875-
return Parse.Object.saveAll(installations)
876-
.then(() => {
877-
return pushController.sendPush(payload, {}, config, auth);
878-
})
879-
.then(() => new Promise(resolve => setTimeout(resolve, 300)));
880-
})
881-
.then(() => {
882-
const query = new Parse.Query('_PushStatus');
883-
return query.find({ useMasterKey: true }).then(results => {
884-
expect(results.length).toBe(1);
885-
const pushStatus = results[0];
886-
expect(pushStatus.get('status')).toBe('scheduled');
887-
});
888-
})
889-
.then(done)
890-
.catch(done.err);
855+
});
856+
const config = Config.get(Parse.applicationId);
857+
await Parse.Object.saveAll(installations);
858+
await pushController.sendPush(payload, {}, config, auth);
859+
await sleep(1000);
860+
const query = new Parse.Query('_PushStatus');
861+
const results = await query.find({ useMasterKey: true });
862+
expect(results.length).toBe(1);
863+
const pushStatus = results[0];
864+
expect(pushStatus.get('status')).toBe('scheduled');
891865
});
892866

893867
it('should not enqueue push when device token is not set', async () => {

0 commit comments

Comments
 (0)