fix: use stapps core version to compare with backends' core version

Note: not app version (e.g. 2.0.0).

Closes #77
This commit is contained in:
Jovan Krunić
2020-11-27 15:36:55 +01:00
parent 072204b748
commit 66b8720da0
4 changed files with 18 additions and 7 deletions

View File

@@ -13,18 +13,19 @@
* this program. If not, see <https://www.gnu.org/licenses/>. * this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { import {
HTTP_INTERCEPTORS,
HttpClient, HttpClient,
HttpEvent, HttpEvent,
HttpHandler, HttpHandler,
HttpInterceptor, HttpInterceptor,
HttpRequest, HttpRequest,
HttpResponse, HttpResponse,
HTTP_INTERCEPTORS,
} from '@angular/common/http'; } from '@angular/common/http';
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {SCIndexResponse, SCSettingInputType, SCThingOriginType, SCThingType} from '@openstapps/core'; import {SCIndexResponse, SCSettingInputType, SCThingOriginType, SCThingType} from '@openstapps/core';
import {Observable, of} from 'rxjs'; import {Observable, of} from 'rxjs';
import {delay, map} from 'rxjs/operators'; import {delay, map} from 'rxjs/operators';
import {dependencies} from '../../../package.json';
import {facetsMock} from './data/sample-facets'; import {facetsMock} from './data/sample-facets';
import {SampleThings} from './data/sample-things'; import {SampleThings} from './data/sample-things';
@@ -268,7 +269,7 @@ export const sampleIndexResponse: SCIndexResponse = {
], ],
}, },
backend: { backend: {
SCVersion: '2.0.0', SCVersion: dependencies['@openstapps/core'],
externalRequestTimeout: 5000, externalRequestTimeout: 5000,
hiddenTypes: [ hiddenTypes: [
SCThingType.DateSeries, SCThingType.DateSeries,

View File

@@ -19,6 +19,7 @@ import {StorageProvider} from '../storage/storage.provider';
import {ConfigProvider, STORAGE_KEY_CONFIG} from './config.provider'; import {ConfigProvider, STORAGE_KEY_CONFIG} from './config.provider';
import {ConfigFetchError, ConfigInitError, SavedConfigNotAvailable, WrongConfigVersionInStorage,} from './errors'; import {ConfigFetchError, ConfigInitError, SavedConfigNotAvailable, WrongConfigVersionInStorage,} from './errors';
import {NGXLogger} from "ngx-logger"; import {NGXLogger} from "ngx-logger";
import {dependencies} from '../../../../package.json';
describe('ConfigProvider', () => { describe('ConfigProvider', () => {
let configProvider: ConfigProvider; let configProvider: ConfigProvider;
@@ -122,7 +123,7 @@ describe('ConfigProvider', () => {
} catch (err) { } catch (err) {
error = err; error = err;
} }
expect(error).toEqual(new WrongConfigVersionInStorage('2.0.0', '0.1.0')); expect(error).toEqual(new WrongConfigVersionInStorage(scVersion, '0.1.0'));
}); });
it('should throw error on saved app configuration not available', async () => { it('should throw error on saved app configuration not available', async () => {
@@ -162,6 +163,8 @@ describe('ConfigProvider', () => {
}); });
}); });
const scVersion = dependencies["@openstapps/core"];
const sampleIndexResponse: SCIndexResponse = { const sampleIndexResponse: SCIndexResponse = {
app: { app: {
campusPolygon: { campusPolygon: {
@@ -230,7 +233,7 @@ const sampleIndexResponse: SCIndexResponse = {
], ],
}, },
backend: { backend: {
SCVersion: '2.0.0', SCVersion: scVersion,
externalRequestTimeout: 5000, externalRequestTimeout: 5000,
hiddenTypes: [ hiddenTypes: [
SCThingType.DateSeries, SCThingType.DateSeries,

View File

@@ -16,6 +16,7 @@ import {Injectable} from '@angular/core';
import {Client} from '@openstapps/api/lib/client'; import {Client} from '@openstapps/api/lib/client';
import {SCAppConfiguration, SCIndexResponse} from '@openstapps/core'; import {SCAppConfiguration, SCIndexResponse} from '@openstapps/core';
import {NGXLogger} from 'ngx-logger'; import {NGXLogger} from 'ngx-logger';
import {dependencies} from '../../../../package.json';
import {environment} from '../../../environments/environment'; import {environment} from '../../../environments/environment';
import {StAppsWebHttpClient} from '../data/stapps-web-http-client.provider'; import {StAppsWebHttpClient} from '../data/stapps-web-http-client.provider';
import {StorageProvider} from '../storage/storage.provider'; import {StorageProvider} from '../storage/storage.provider';
@@ -52,6 +53,11 @@ export class ConfigProvider {
*/ */
initialised = false; initialised = false;
/**
* Version of the @openstapps/core package that app is using
*/
scVersion = dependencies['@openstapps/core'];
/** /**
* Constructor, initialise api client * Constructor, initialise api client
* *
@@ -70,7 +76,7 @@ export class ConfigProvider {
*/ */
async fetch(): Promise<SCIndexResponse> { async fetch(): Promise<SCIndexResponse> {
try { try {
return await this.client.handshake(environment.backend_version); return await this.client.handshake(this.scVersion);
} catch (error) { } catch (error) {
throw new ConfigFetchError(); throw new ConfigFetchError();
} }
@@ -113,8 +119,8 @@ export class ConfigProvider {
this.config = await this.loadLocal(); this.config = await this.loadLocal();
this.initialised = true; this.initialised = true;
this.logger.log(`initialised configuration from storage`); this.logger.log(`initialised configuration from storage`);
if (this.config.backend.SCVersion !== environment.backend_version) { if (this.config.backend.SCVersion !== this.scVersion) {
loadError = new WrongConfigVersionInStorage(environment.backend_version, this.config.backend.SCVersion); loadError = new WrongConfigVersionInStorage(this.scVersion, this.config.backend.SCVersion);
this.logger.warn(loadError); this.logger.warn(loadError);
} }
} catch (error) { } catch (error) {

View File

@@ -6,6 +6,7 @@
"declaration": false, "declaration": false,
"emitDecoratorMetadata": true, "emitDecoratorMetadata": true,
"strictPropertyInitialization": false, "strictPropertyInitialization": false,
"resolveJsonModule": true,
"lib": [ "lib": [
"es2017", "es2017",
"dom" "dom"