Skip to content

Commit 2fd7c12

Browse files
committed
fix
1 parent 604011d commit 2fd7c12

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

spec/Deprecator.spec.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,29 @@ describe('Deprecator', () => {
4545
`DeprecationWarning: ${options.usage} is deprecated and will be removed in a future version. ${options.solution}`
4646
);
4747
});
48+
49+
it('logs deprecation for nested option key with dot notation', async () => {
50+
deprecations = [{ optionKey: 'databaseOptions.allowPublicExplain', changeNewDefault: 'false' }];
51+
52+
spyOn(Deprecator, '_getDeprecations').and.callFake(() => deprecations);
53+
const logger = require('../lib/logger').logger;
54+
const logSpy = spyOn(logger, 'warn').and.callFake(() => {});
55+
56+
await reconfigureServer();
57+
expect(logSpy.calls.all()[0].args[0]).toEqual(
58+
`DeprecationWarning: The Parse Server option '${deprecations[0].optionKey}' default will change to '${deprecations[0].changeNewDefault}' in a future version.`
59+
);
60+
});
61+
62+
it('does not log deprecation for nested option key if option is set manually', async () => {
63+
deprecations = [{ optionKey: 'databaseOptions.allowPublicExplain', changeNewDefault: 'false' }];
64+
65+
spyOn(Deprecator, '_getDeprecations').and.callFake(() => deprecations);
66+
const logSpy = spyOn(Deprecator, '_logOption').and.callFake(() => {});
67+
const Config = require('../lib/Config');
68+
const config = Config.get('test');
69+
// Directly test scanParseServerOptions with nested option set
70+
Deprecator.scanParseServerOptions({ databaseOptions: { allowPublicExplain: true } });
71+
expect(logSpy).not.toHaveBeenCalled();
72+
});
4873
});

src/Deprecator/Deprecator.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logger from '../logger';
22
import Deprecations from './Deprecations';
3+
import Utils from '../Utils';
34

45
/**
56
* The deprecator class.
@@ -21,7 +22,7 @@ class Deprecator {
2122
const changeNewDefault = deprecation.changeNewDefault;
2223

2324
// If default will change, only throw a warning if option is not set
24-
if (changeNewDefault != null && options[optionKey] == null) {
25+
if (changeNewDefault != null && Utils.getNestedProperty(options, optionKey) == null) {
2526
Deprecator._logOption({ optionKey, changeNewDefault, solution });
2627
}
2728
}

0 commit comments

Comments
 (0)