fix: use major version config from storage when offline

Closes #218
This commit is contained in:
Jovan Krunić
2024-08-01 16:35:58 +02:00
committed by Rainer Killinger
parent 7276525dfa
commit 7afc24f1bc
3 changed files with 21 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"@openstapps/app": patch
---
fixed config version comparison

View File

@@ -132,6 +132,8 @@ describe('ConfigProvider', () => {
wrongConfig.backend.SCVersion = '0.1.0'; wrongConfig.backend.SCVersion = '0.1.0';
storageProviderSpy.get.and.returnValue(Promise.resolve(wrongConfig)); storageProviderSpy.get.and.returnValue(Promise.resolve(wrongConfig));
spyOn(configProvider.client, 'handshake').and.returnValue(Promise.resolve(sampleIndexResponse)); spyOn(configProvider.client, 'handshake').and.returnValue(Promise.resolve(sampleIndexResponse));
// sets StApps core version which has a different major version
configProvider.scVersion = '1.0.0';
await configProvider.init(); await configProvider.init();
expect(ngxLogger.warn).toHaveBeenCalledWith( expect(ngxLogger.warn).toHaveBeenCalledWith(
@@ -139,6 +141,19 @@ describe('ConfigProvider', () => {
); );
}); });
it('should load from storage if offline and same major version stored', async () => {
internetConnectionServiceMock = {offline$: new BehaviorSubject<boolean>(true)};
storageProviderSpy.has.and.returnValue(Promise.resolve(true));
const configInStorage = structuredClone(sampleIndexResponse);
configInStorage.backend.SCVersion = '1.0.0';
storageProviderSpy.get.and.returnValue(Promise.resolve(configInStorage));
// sets StApps core version which has the same major version
configProvider.scVersion = '1.1.1';
await configProvider.init();
expect(configProvider.getAnyValue('app')).toEqual(configInStorage.app);
});
it('should throw error on saved app configuration not available', async () => { it('should throw error on saved app configuration not available', async () => {
storageProviderSpy.has.and.returnValue(Promise.resolve(false)); storageProviderSpy.has.and.returnValue(Promise.resolve(false));
// eslint-disable-next-line unicorn/error-message // eslint-disable-next-line unicorn/error-message

View File

@@ -132,7 +132,7 @@ export class ConfigProvider {
this.config = await this.loadLocal(); this.config = await this.loadLocal();
this.firstSession = false; this.firstSession = false;
this.logger.log(`initialised configuration from storage`); this.logger.log(`initialised configuration from storage`);
if (this.config.backend.SCVersion !== this.scVersion) { if (this.config.backend.SCVersion.split('.')[0] !== this.scVersion.split('.')[0]) {
loadError = new WrongConfigVersionInStorage(this.scVersion, this.config.backend.SCVersion); loadError = new WrongConfigVersionInStorage(this.scVersion, this.config.backend.SCVersion);
} }
} catch (error) { } catch (error) {