fix: Deprecation warning logged at server launch for nested Parse Server option even if option is explicitly set (#9934)

This commit is contained in:
Manuel
2025-11-17 19:43:32 +01:00
committed by GitHub
parent 5e15403bc1
commit c22cb0ae58
4 changed files with 103 additions and 1 deletions

View File

@@ -45,4 +45,29 @@ describe('Deprecator', () => {
`DeprecationWarning: ${options.usage} is deprecated and will be removed in a future version. ${options.solution}`
);
});
it('logs deprecation for nested option key with dot notation', async () => {
deprecations = [{ optionKey: 'databaseOptions.allowPublicExplain', changeNewDefault: 'false' }];
spyOn(Deprecator, '_getDeprecations').and.callFake(() => deprecations);
const logger = require('../lib/logger').logger;
const logSpy = spyOn(logger, 'warn').and.callFake(() => {});
await reconfigureServer();
expect(logSpy.calls.all()[0].args[0]).toEqual(
`DeprecationWarning: The Parse Server option '${deprecations[0].optionKey}' default will change to '${deprecations[0].changeNewDefault}' in a future version.`
);
});
it('does not log deprecation for nested option key if option is set manually', async () => {
deprecations = [{ optionKey: 'databaseOptions.allowPublicExplain', changeNewDefault: 'false' }];
spyOn(Deprecator, '_getDeprecations').and.callFake(() => deprecations);
const logSpy = spyOn(Deprecator, '_logOption').and.callFake(() => {});
const Config = require('../lib/Config');
const config = Config.get('test');
// Directly test scanParseServerOptions with nested option set
Deprecator.scanParseServerOptions({ databaseOptions: { allowPublicExplain: true } });
expect(logSpy).not.toHaveBeenCalled();
});
});

View File

@@ -122,4 +122,55 @@ describe('Utils', () => {
expect(result).toBe('{"name":"test","number":42,"nested":{"key":"value"}}');
});
});
describe('getNestedProperty', () => {
it('should get top-level property', () => {
const obj = { foo: 'bar' };
expect(Utils.getNestedProperty(obj, 'foo')).toBe('bar');
});
it('should get nested property with dot notation', () => {
const obj = { database: { options: { enabled: true } } };
expect(Utils.getNestedProperty(obj, 'database.options.enabled')).toBe(true);
});
it('should return undefined for non-existent property', () => {
const obj = { foo: 'bar' };
expect(Utils.getNestedProperty(obj, 'baz')).toBeUndefined();
});
it('should return undefined for non-existent nested property', () => {
const obj = { database: { options: {} } };
expect(Utils.getNestedProperty(obj, 'database.options.enabled')).toBeUndefined();
});
it('should return undefined when path traverses non-object', () => {
const obj = { database: 'string' };
expect(Utils.getNestedProperty(obj, 'database.options.enabled')).toBeUndefined();
});
it('should return undefined for null object', () => {
expect(Utils.getNestedProperty(null, 'foo')).toBeUndefined();
});
it('should return undefined for empty path', () => {
const obj = { foo: 'bar' };
expect(Utils.getNestedProperty(obj, '')).toBeUndefined();
});
it('should handle value of 0', () => {
const obj = { database: { timeout: 0 } };
expect(Utils.getNestedProperty(obj, 'database.timeout')).toBe(0);
});
it('should handle value of false', () => {
const obj = { database: { enabled: false } };
expect(Utils.getNestedProperty(obj, 'database.enabled')).toBe(false);
});
it('should handle value of empty string', () => {
const obj = { database: { name: '' } };
expect(Utils.getNestedProperty(obj, 'database.name')).toBe('');
});
});
});