diff --git a/spec/ParseGlobalConfig.spec.js b/spec/ParseGlobalConfig.spec.js index 9f8b109ed3..919c203a88 100644 --- a/spec/ParseGlobalConfig.spec.js +++ b/spec/ParseGlobalConfig.spec.js @@ -28,7 +28,7 @@ describe('a GlobalConfig', () => { }, query, { - params: { companies: ['US', 'DK'], internalParam: 'internal' }, + params: { companies: ['US', 'DK'], counter: 20, internalParam: 'internal' }, masterKeyOnly: { internalParam: true }, } ) @@ -114,6 +114,34 @@ describe('a GlobalConfig', () => { }); }); + it_only_db('mongo')('can addUnique', async () => { + await Parse.Config.save({ companies: { __op: 'AddUnique', objects: ['PA', 'RS', 'E'] } }); + const config = await Parse.Config.get(); + const companies = config.get('companies'); + expect(companies).toEqual(['US', 'DK', 'PA', 'RS', 'E']); + }); + + it_only_db('mongo')('can add to array', async () => { + await Parse.Config.save({ companies: { __op: 'Add', objects: ['PA'] } }); + const config = await Parse.Config.get(); + const companies = config.get('companies'); + expect(companies).toEqual(['US', 'DK', 'PA']); + }); + + it_only_db('mongo')('can remove from array', async () => { + await Parse.Config.save({ companies: { __op: 'Remove', objects: ['US'] } }); + const config = await Parse.Config.get(); + const companies = config.get('companies'); + expect(companies).toEqual(['DK']); + }); + + it('can increment', async () => { + await Parse.Config.save({ counter: { __op: 'Increment', amount: 49 } }); + const config = await Parse.Config.get(); + const counter = config.get('counter'); + expect(counter).toEqual(69); + }); + it('can add and retrive files', done => { request({ method: 'PUT', @@ -165,6 +193,7 @@ describe('a GlobalConfig', () => { body: { params: { companies: { __op: 'Delete' }, + counter: { __op: 'Delete' }, internalParam: { __op: 'Delete' }, foo: 'bar', }, @@ -183,6 +212,7 @@ describe('a GlobalConfig', () => { try { expect(response.status).toEqual(200); expect(body.params.companies).toBeUndefined(); + expect(body.params.counter).toBeUndefined(); expect(body.params.foo).toBe('bar'); expect(Object.keys(body.params).length).toBe(1); } catch (e) { diff --git a/src/Routers/GlobalConfigRouter.js b/src/Routers/GlobalConfigRouter.js index f45c0768f4..c30619fc21 100644 --- a/src/Routers/GlobalConfigRouter.js +++ b/src/Routers/GlobalConfigRouter.js @@ -46,7 +46,7 @@ export class GlobalConfigRouter extends PromiseRouter { return acc; }, {}); return req.config.database - .update('_GlobalConfig', { objectId: '1' }, update, { upsert: true }) + .update('_GlobalConfig', { objectId: '1' }, update, { upsert: true }, true) .then(() => ({ response: { result: true } })); }