|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const assert = require('assert'); |
| 4 | +const clear = require('./clear'); |
| 5 | +const Parse = require('../../node'); |
| 6 | + |
| 7 | +function testConfig() { |
| 8 | + const data = { |
| 9 | + params: { internal: 'i', public: 'p' }, |
| 10 | + masterKeyOnly: { internal: true }, |
| 11 | + }; |
| 12 | + return Parse.CoreManager.getRESTController().request( |
| 13 | + 'PUT', |
| 14 | + 'config', |
| 15 | + data, |
| 16 | + { useMasterKey: true } |
| 17 | + ); |
| 18 | +} |
| 19 | + |
| 20 | +describe('Parse Config', () => { |
| 21 | + beforeEach((done) => { |
| 22 | + Parse.initialize('integration', null, 'notsosecret'); |
| 23 | + Parse.CoreManager.set('SERVER_URL', 'http://localhost:1337/parse'); |
| 24 | + Parse.Storage._clear(); |
| 25 | + clear().then(() => { |
| 26 | + done(); |
| 27 | + }); |
| 28 | + }); |
| 29 | + |
| 30 | + it('can create a config', async () => { |
| 31 | + const config = await Parse.Config.save({ |
| 32 | + str: 'hello', |
| 33 | + num: 42 |
| 34 | + }); |
| 35 | + assert.equal(config.get('str'), 'hello'); |
| 36 | + assert.equal(config.get('num'), 42); |
| 37 | + }); |
| 38 | + |
| 39 | + it('can get a config', async () => { |
| 40 | + await Parse.Config.save({ |
| 41 | + str: 'hello', |
| 42 | + num: 42 |
| 43 | + }); |
| 44 | + const config = await Parse.Config.get(); |
| 45 | + assert.equal(config.get('str'), 'hello'); |
| 46 | + assert.equal(config.get('num'), 42); |
| 47 | + }); |
| 48 | + |
| 49 | + it('can get internal config parameter with masterkey', async () => { |
| 50 | + await testConfig(); |
| 51 | + |
| 52 | + const config = await Parse.Config.get({ useMasterKey: true }); |
| 53 | + assert.equal(config.get('internal'), 'i'); |
| 54 | + assert.equal(config.get('public'), 'p'); |
| 55 | + }); |
| 56 | + |
| 57 | + it('cannot get internal config parameter without masterkey', async () => { |
| 58 | + await testConfig(); |
| 59 | + |
| 60 | + const config = await Parse.Config.get(); |
| 61 | + assert.equal(config.get('internal'), undefined); |
| 62 | + assert.equal(config.get('public'), 'p'); |
| 63 | + }); |
| 64 | +}); |
0 commit comments