|
@@ -61,5 +61,49 @@ describe('ConfigManager', () => {
|
|
|
|
|
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ describe('updateConfigsInTheSameNamespace', () => {
|
|
|
|
|
+ beforeEach(async() => {
|
|
|
|
|
+ await Config.deleteMany({ ns: 'testNamespace' }).exec();
|
|
|
|
|
+ await Config.create({ ns: 'testNamespace', key: 'key1', value: JSON.stringify('value1') });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('updates configs in the same namespace', async() => {
|
|
|
|
|
+ // arrange
|
|
|
|
|
+ await configManager.loadConfigs();
|
|
|
|
|
+
|
|
|
|
|
+ // act
|
|
|
|
|
+ await configManager.updateConfigsInTheSameNamespace('testNamespace', {
|
|
|
|
|
+ key1: 'value111',
|
|
|
|
|
+ key2: 'value222',
|
|
|
|
|
+ });
|
|
|
|
|
+ const updatedConfig1 = await Config.findOne({ ns: 'testNamespace', key: 'key1' }).exec();
|
|
|
|
|
+ const updatedConfig2 = await Config.findOne({ ns: 'testNamespace', key: 'key2' }).exec();
|
|
|
|
|
+
|
|
|
|
|
+ // assert
|
|
|
|
|
+ expect(updatedConfig1?.value).toEqual(JSON.stringify('value111'));
|
|
|
|
|
+ expect(updatedConfig2?.value).toEqual(JSON.stringify('value222'));
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ describe('removeConfigsInTheSameNamespace', () => {
|
|
|
|
|
+ beforeEach(async() => {
|
|
|
|
|
+ await Config.create({ ns: 'testNamespace', key: 'key1', value: JSON.stringify('value1') });
|
|
|
|
|
+ await Config.create({ ns: 'testNamespace', key: 'key2', value: JSON.stringify('value2') });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ test('removes configs in the same namespace', async() => {
|
|
|
|
|
+ // arrange
|
|
|
|
|
+ await configManager.loadConfigs();
|
|
|
|
|
+
|
|
|
|
|
+ // act
|
|
|
|
|
+ await configManager.removeConfigsInTheSameNamespace('testNamespace', ['key1', 'key2']);
|
|
|
|
|
+ const removedConfig1 = await Config.findOne({ ns: 'testNamespace', key: 'key1' }).exec();
|
|
|
|
|
+ const removedConfig2 = await Config.findOne({ ns: 'testNamespace', key: 'key2' }).exec();
|
|
|
|
|
+
|
|
|
|
|
+ // assert
|
|
|
|
|
+ expect(removedConfig1).toBeNull();
|
|
|
|
|
+ expect(removedConfig2).toBeNull();
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
});
|
|
});
|