Update ConfigurationService Usage
In OneCX v6, three methods of ConfigurationService have been updated to be asynchronous, returning Promise results instead of synchronous values.
Update the following methods
-
getProperty(key)→await getProperty(key) -
getConfig()→await getConfig() -
setProperty(key, val)→await setProperty(key, val)
- Guidelines
-
-
Update only methods of
ConfigurationServiceimported from@onecx/angular-integration-interface. -
If inside an observable: wrap the call with
from(…)and useswitchMapormergeMap. -
Outside observables: use
awaitin anasyncfunction; ifasyncnot allowed (e.g.constructor,ngOnInit), resolve the Promise with.then(…). -
Add
try/catchfor error handling where synchronous code previously assumed success. -
Update mocks to resolve promises:
-
Jest →
jest.spyOn(service, 'getProperty').mockResolvedValue('val'); -
Jasmine →
spyOn(service, 'getConfig').and.returnValue(Promise.resolve(cfg));
-
-
Example
const theme = this.configService.getProperty(CONFIG_KEY.TKIT_PORTAL_DEFAULT_THEME);
const config = this.configService.getConfig();
this.configService.setProperty(CONFIG_KEY.APP_VERSION, '6.0.0');
const theme = await this.configService.getProperty(CONFIG_KEY.TKIT_PORTAL_DEFAULT_THEME);
const config = await this.configService.getConfig();
await this.configService.setProperty(CONFIG_KEY.APP_VERSION, '6.0.0');