Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion spec/ParseGlobalConfig.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}
)
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -165,6 +193,7 @@ describe('a GlobalConfig', () => {
body: {
params: {
companies: { __op: 'Delete' },
counter: { __op: 'Delete' },
internalParam: { __op: 'Delete' },
foo: 'bar',
},
Expand All @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/Routers/GlobalConfigRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }));
}

Expand Down