feat: Add atomic operations for Cloud Config parameters (#9219)

This commit is contained in:
Diamond Lewis
2024-07-17 19:52:39 -05:00
committed by GitHub
parent 69aba3bd3b
commit 35cadf9b83
2 changed files with 32 additions and 2 deletions

View File

@@ -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) {

View File

@@ -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 } }));
}