Skip to content

Commit 35cadf9

Browse files
authored
feat: Add atomic operations for Cloud Config parameters (#9219)
1 parent 69aba3b commit 35cadf9

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

spec/ParseGlobalConfig.spec.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe('a GlobalConfig', () => {
2828
},
2929
query,
3030
{
31-
params: { companies: ['US', 'DK'], internalParam: 'internal' },
31+
params: { companies: ['US', 'DK'], counter: 20, internalParam: 'internal' },
3232
masterKeyOnly: { internalParam: true },
3333
}
3434
)
@@ -114,6 +114,34 @@ describe('a GlobalConfig', () => {
114114
});
115115
});
116116

117+
it_only_db('mongo')('can addUnique', async () => {
118+
await Parse.Config.save({ companies: { __op: 'AddUnique', objects: ['PA', 'RS', 'E'] } });
119+
const config = await Parse.Config.get();
120+
const companies = config.get('companies');
121+
expect(companies).toEqual(['US', 'DK', 'PA', 'RS', 'E']);
122+
});
123+
124+
it_only_db('mongo')('can add to array', async () => {
125+
await Parse.Config.save({ companies: { __op: 'Add', objects: ['PA'] } });
126+
const config = await Parse.Config.get();
127+
const companies = config.get('companies');
128+
expect(companies).toEqual(['US', 'DK', 'PA']);
129+
});
130+
131+
it_only_db('mongo')('can remove from array', async () => {
132+
await Parse.Config.save({ companies: { __op: 'Remove', objects: ['US'] } });
133+
const config = await Parse.Config.get();
134+
const companies = config.get('companies');
135+
expect(companies).toEqual(['DK']);
136+
});
137+
138+
it('can increment', async () => {
139+
await Parse.Config.save({ counter: { __op: 'Increment', amount: 49 } });
140+
const config = await Parse.Config.get();
141+
const counter = config.get('counter');
142+
expect(counter).toEqual(69);
143+
});
144+
117145
it('can add and retrive files', done => {
118146
request({
119147
method: 'PUT',
@@ -165,6 +193,7 @@ describe('a GlobalConfig', () => {
165193
body: {
166194
params: {
167195
companies: { __op: 'Delete' },
196+
counter: { __op: 'Delete' },
168197
internalParam: { __op: 'Delete' },
169198
foo: 'bar',
170199
},
@@ -183,6 +212,7 @@ describe('a GlobalConfig', () => {
183212
try {
184213
expect(response.status).toEqual(200);
185214
expect(body.params.companies).toBeUndefined();
215+
expect(body.params.counter).toBeUndefined();
186216
expect(body.params.foo).toBe('bar');
187217
expect(Object.keys(body.params).length).toBe(1);
188218
} catch (e) {

src/Routers/GlobalConfigRouter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export class GlobalConfigRouter extends PromiseRouter {
4646
return acc;
4747
}, {});
4848
return req.config.database
49-
.update('_GlobalConfig', { objectId: '1' }, update, { upsert: true })
49+
.update('_GlobalConfig', { objectId: '1' }, update, { upsert: true }, true)
5050
.then(() => ({ response: { result: true } }));
5151
}
5252

0 commit comments

Comments
 (0)