|
| 1 | +const Parse = require('parse/node').Parse; |
| 2 | +const PostgresStorageAdapter = require('../src/Adapters/Storage/Postgres/PostgresStorageAdapter'); |
| 3 | +const postgresURI = 'postgres://localhost:5432/parse_server_postgres_adapter_test_database'; |
| 4 | + |
| 5 | +//public schema |
| 6 | +const databaseOptions1 = { |
| 7 | + initOptions: { |
| 8 | + connect: function (client, dc, isFresh) { |
| 9 | + if (isFresh) { |
| 10 | + client.query('SET search_path = public'); |
| 11 | + } |
| 12 | + } |
| 13 | + } |
| 14 | +}; |
| 15 | + |
| 16 | +//not exists schema |
| 17 | +const databaseOptions2 = { |
| 18 | + initOptions: { |
| 19 | + connect: function (client, dc, isFresh) { |
| 20 | + if (isFresh) { |
| 21 | + client.query('SET search_path = not_exists_schema'); |
| 22 | + } |
| 23 | + } |
| 24 | + } |
| 25 | +}; |
| 26 | + |
| 27 | +const GameScore = Parse.Object.extend({ |
| 28 | + className: "GameScore" |
| 29 | +}); |
| 30 | + |
| 31 | +describe('Postgres database init options', () => { |
| 32 | + it('create server with public schema databaseOptions,shoud be ok', (done) => { |
| 33 | + reconfigureServer({ |
| 34 | + databaseAdapter: new PostgresStorageAdapter({ |
| 35 | + uri: postgresURI, collectionPrefix: 'test_', |
| 36 | + databaseOptions: databaseOptions1 |
| 37 | + }) |
| 38 | + }).then(done, fail); |
| 39 | + }); |
| 40 | + |
| 41 | + it("save new GameScore in public schema", function (done) { |
| 42 | + var score = new GameScore({ "score": 1337, "playerName": "Sean Plott", "cheatMode": false }); |
| 43 | + score.save().then(done, fail); |
| 44 | + }); |
| 45 | + |
| 46 | + it('create server with not exists schema databaseOptions,shoud be fail', (done) => { |
| 47 | + reconfigureServer({ |
| 48 | + databaseAdapter: new PostgresStorageAdapter({ |
| 49 | + uri: postgresURI, collectionPrefix: 'test_', |
| 50 | + databaseOptions: databaseOptions2 |
| 51 | + }) |
| 52 | + }).then(() => { |
| 53 | + done(); |
| 54 | + }) |
| 55 | + .catch(error => { |
| 56 | + expect(error.code).toEqual('42P01'); |
| 57 | + done(); |
| 58 | + }); |
| 59 | + }); |
| 60 | +}); |
0 commit comments