@@ -4,8 +4,7 @@ const PostgresStorageAdapter = require('../lib/Adapters/Storage/Postgres/Postgre
4
4
const postgresURI =
5
5
process . env . PARSE_SERVER_TEST_DATABASE_URI ||
6
6
'postgres://localhost:5432/parse_server_postgres_adapter_test_database' ;
7
- const ParseServer = require ( '../lib/index' ) ;
8
- const express = require ( 'express' ) ;
7
+
9
8
//public schema
10
9
const databaseOptions1 = {
11
10
initOptions : {
@@ -24,72 +23,57 @@ const GameScore = Parse.Object.extend({
24
23
className : 'GameScore' ,
25
24
} ) ;
26
25
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
-
50
26
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
- } ) ;
59
27
60
- it ( 'should create server with public schema databaseOptions' , done => {
28
+ it ( 'should create server with public schema databaseOptions' , async ( ) => {
61
29
const adapter = new PostgresStorageAdapter ( {
62
30
uri : postgresURI ,
63
31
collectionPrefix : 'test_' ,
64
32
databaseOptions : databaseOptions1 ,
65
33
} ) ;
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
+ } ) ;
66
44
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 ( ) ;
81
62
} ) ;
82
63
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 ( ) => {
84
65
const adapter = new PostgresStorageAdapter ( {
85
66
uri : postgresURI ,
86
67
collectionPrefix : 'test_' ,
87
68
databaseOptions : databaseOptions2 ,
88
69
} ) ;
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
+ }
94
78
} ) ;
95
79
} ) ;
0 commit comments