1
1
const Parse = require ( 'parse/node' ) . Parse ;
2
2
const PostgresStorageAdapter = require ( '../src/Adapters/Storage/Postgres/PostgresStorageAdapter' ) ;
3
3
const postgresURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database' ;
4
- const Config = require ( '../src/Config' ) ;
4
+ var ParseServer = require ( "../src/index" ) ;
5
+ var express = require ( 'express' ) ;
5
6
//public schema
6
7
const databaseOptions1 = {
7
8
initOptions : {
@@ -28,47 +29,54 @@ const GameScore = Parse.Object.extend({
28
29
className : "GameScore"
29
30
} ) ;
30
31
32
+ function createParseServer ( options ) {
33
+ return new Promise ( ( resolve , reject ) => {
34
+ const parseServer = new ParseServer . default ( Object . assign ( { } ,
35
+ defaultConfiguration , options , {
36
+ serverURL : "http://localhost:12666/parse" ,
37
+ __indexBuildCompletionCallbackForTests : promise => {
38
+ promise
39
+ . then ( ( ) => {
40
+ expect ( Parse . applicationId ) . toEqual ( "test" ) ;
41
+ var app = express ( ) ;
42
+ app . use ( '/parse' , parseServer . app ) ;
43
+
44
+ const server = app . listen ( 12666 ) ;
45
+ Parse . serverURL = "http://localhost:12666/parse" ;
46
+ resolve ( server ) ;
47
+ } , reject ) ;
48
+ } } ) ) ;
49
+ } ) ;
50
+ }
51
+
31
52
describe_only_db ( 'postgres' ) ( 'Postgres database init options' , ( ) => {
53
+ let server ;
54
+
32
55
afterEach ( ( ) => {
33
- defaultConfiguration . databaseAdapter = new PostgresStorageAdapter ( {
34
- uri : process . env . PARSE_SERVER_TEST_DATABASE_URI || postgresURI ,
35
- collectionPrefix : 'test_' ,
36
- } ) ;
37
- } ) ;
56
+ if ( server ) {
57
+ server . close ( ) ;
58
+ }
59
+ } )
38
60
39
61
it ( 'should create server with public schema databaseOptions' , ( done ) => {
40
- const config = new Config ( 'test' ) ;
41
- // Close the current DB before continueing
42
- config . database . adapter . _pgp . end ( ) ;
43
- reconfigureServer ( {
44
- databaseAdapter : new PostgresStorageAdapter ( {
45
- uri : postgresURI , collectionPrefix : 'test_' ,
46
- databaseOptions : databaseOptions1
47
- } )
62
+ const adapter = new PostgresStorageAdapter ( {
63
+ uri : postgresURI , collectionPrefix : 'test_' ,
64
+ databaseOptions : databaseOptions1
48
65
} )
49
- . then ( ( ) => {
50
- var score = new GameScore ( { "score" : 1337 , "playerName" : "Sean Plott" , "cheatMode" : false } ) ;
51
- return score . save ( ) ;
52
- } )
53
- . then ( done , done . fail ) ;
66
+
67
+ createParseServer ( { databaseAdapter : adapter } ) . then ( ( newServer ) => {
68
+ server = newServer ;
69
+ var score = new GameScore ( { "score" : 1337 , "playerName" : "Sean Plott" , "cheatMode" : false } ) ;
70
+ return score . save ( ) ;
71
+ } ) . then ( done , done . fail ) ;
54
72
} ) ;
55
73
56
74
it ( 'should fail to create server if schema databaseOptions does not exist' , ( done ) => {
57
- const config = new Config ( 'test' ) ;
58
- // Close the current DB before continueing
59
- config . database . adapter . _pgp . end ( ) ;
60
- reconfigureServer ( {
61
- databaseAdapter : new PostgresStorageAdapter ( {
62
- uri : postgresURI , collectionPrefix : 'test_' ,
63
- databaseOptions : databaseOptions2
64
- } )
65
- } ) . then ( ( ) => {
66
- done . fail ( 'Should not succeed' ) ;
67
- } , error => {
68
- // INVALID_SCHEMA error 3F000
69
- // https://www.postgresql.org/docs/9.5/static/errcodes-appendix.html
70
- expect ( error . code ) . toEqual ( '3F000' ) ;
71
- done ( ) ;
72
- } ) ;
75
+ const adapter = new PostgresStorageAdapter ( {
76
+ uri : postgresURI , collectionPrefix : 'test_' ,
77
+ databaseOptions : databaseOptions2
78
+ } )
79
+
80
+ createParseServer ( { databaseAdapter : adapter } ) . then ( done . fail , done ) ;
73
81
} ) ;
74
82
} ) ;
0 commit comments