2021-03-30 22:42:34 +02:00
'use strict' ;
const Deprecator = require ( '../lib/Deprecator/Deprecator' ) ;
describe ( 'Deprecator' , ( ) => {
let deprecations = [ ] ;
beforeEach ( async ( ) => {
deprecations = [ { optionKey : 'exampleKey' , changeNewDefault : 'exampleNewDefault' } ] ;
} ) ;
it ( 'deprecations are an array' , async ( ) => {
expect ( Deprecator . _getDeprecations ( ) ) . toBeInstanceOf ( Array ) ;
} ) ;
it ( 'logs deprecation for new default' , async ( ) => {
deprecations = [ { optionKey : 'exampleKey' , changeNewDefault : 'exampleNewDefault' } ] ;
spyOn ( Deprecator , '_getDeprecations' ) . and . callFake ( ( ) => deprecations ) ;
const logger = require ( '../lib/logger' ) . logger ;
const logSpy = spyOn ( logger , 'warn' ) . and . callFake ( ( ) => { } ) ;
await reconfigureServer ( ) ;
2021-07-12 20:14:35 +02:00
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. `
) ;
2021-03-30 22:42:34 +02:00
} ) ;
it ( 'does not log deprecation for new default if option is set manually' , async ( ) => {
deprecations = [ { optionKey : 'exampleKey' , changeNewDefault : 'exampleNewDefault' } ] ;
spyOn ( Deprecator , '_getDeprecations' ) . and . callFake ( ( ) => deprecations ) ;
2021-07-12 20:14:35 +02:00
const logSpy = spyOn ( Deprecator , '_logOption' ) . and . callFake ( ( ) => { } ) ;
2021-03-30 22:42:34 +02:00
await reconfigureServer ( { [ deprecations [ 0 ] . optionKey ] : 'manuallySet' } ) ;
expect ( logSpy ) . not . toHaveBeenCalled ( ) ;
} ) ;
2021-07-12 20:14:35 +02:00
it ( 'logs runtime deprecation' , async ( ) => {
const logger = require ( '../lib/logger' ) . logger ;
const logSpy = spyOn ( logger , 'warn' ) . and . callFake ( ( ) => { } ) ;
const options = { usage : 'Doing this' , solution : 'Do that instead.' } ;
Deprecator . logRuntimeDeprecation ( options ) ;
expect ( logSpy . calls . all ( ) [ 0 ] . args [ 0 ] ) . toEqual (
` DeprecationWarning: ${ options . usage } is deprecated and will be removed in a future version. ${ options . solution } `
) ;
} ) ;
2025-11-17 19:43:32 +01:00
it ( 'logs deprecation for nested option key with dot notation' , async ( ) => {
2025-12-12 21:07:07 +01:00
deprecations = [ { optionKey : 'databaseOptions.testOption' , changeNewDefault : 'false' } ] ;
2025-11-17 19:43:32 +01:00
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 ( ) => {
2025-12-12 21:07:07 +01:00
deprecations = [ { optionKey : 'databaseOptions.testOption' , changeNewDefault : 'false' } ] ;
2025-11-17 19:43:32 +01:00
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
2025-12-12 21:07:07 +01:00
Deprecator . scanParseServerOptions ( { databaseOptions : { testOption : true } } ) ;
2025-11-17 19:43:32 +01:00
expect ( logSpy ) . not . toHaveBeenCalled ( ) ;
} ) ;
2021-03-30 22:42:34 +02:00
} ) ;