@@ -4,8 +4,7 @@ const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/Postgre
44const 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
109const 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-
5026describe_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} ) ;
0 commit comments