mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-10 19:52:53 +00:00
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:
@@ -13,18 +13,19 @@
|
||||
* this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
import {
|
||||
HTTP_INTERCEPTORS,
|
||||
HttpClient,
|
||||
HttpEvent,
|
||||
HttpHandler,
|
||||
HttpInterceptor,
|
||||
HttpRequest,
|
||||
HttpResponse,
|
||||
HTTP_INTERCEPTORS,
|
||||
} from '@angular/common/http';
|
||||
import {Injectable} from '@angular/core';
|
||||
import {SCIndexResponse, SCSettingInputType, SCThingOriginType, SCThingType} from '@openstapps/core';
|
||||
import {Observable, of} from 'rxjs';
|
||||
import {delay, map} from 'rxjs/operators';
|
||||
import {dependencies} from '../../../package.json';
|
||||
import {facetsMock} from './data/sample-facets';
|
||||
import {SampleThings} from './data/sample-things';
|
||||
|
||||
@@ -268,7 +269,7 @@ export const sampleIndexResponse: SCIndexResponse = {
|
||||
],
|
||||
},
|
||||
backend: {
|
||||
SCVersion: '2.0.0',
|
||||
SCVersion: dependencies['@openstapps/core'],
|
||||
externalRequestTimeout: 5000,
|
||||
hiddenTypes: [
|
||||
SCThingType.DateSeries,
|
||||
|
||||
@@ -19,6 +19,7 @@ import {StorageProvider} from '../storage/storage.provider';
|
||||
import {ConfigProvider, STORAGE_KEY_CONFIG} from './config.provider';
|
||||
import {ConfigFetchError, ConfigInitError, SavedConfigNotAvailable, WrongConfigVersionInStorage,} from './errors';
|
||||
import {NGXLogger} from "ngx-logger";
|
||||
import {dependencies} from '../../../../package.json';
|
||||
|
||||
describe('ConfigProvider', () => {
|
||||
let configProvider: ConfigProvider;
|
||||
@@ -122,7 +123,7 @@ describe('ConfigProvider', () => {
|
||||
} catch (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 () => {
|
||||
@@ -162,6 +163,8 @@ describe('ConfigProvider', () => {
|
||||
});
|
||||
});
|
||||
|
||||
const scVersion = dependencies["@openstapps/core"];
|
||||
|
||||
const sampleIndexResponse: SCIndexResponse = {
|
||||
app: {
|
||||
campusPolygon: {
|
||||
@@ -230,7 +233,7 @@ const sampleIndexResponse: SCIndexResponse = {
|
||||
],
|
||||
},
|
||||
backend: {
|
||||
SCVersion: '2.0.0',
|
||||
SCVersion: scVersion,
|
||||
externalRequestTimeout: 5000,
|
||||
hiddenTypes: [
|
||||
SCThingType.DateSeries,
|
||||
|
||||
@@ -16,6 +16,7 @@ import {Injectable} from '@angular/core';
|
||||
import {Client} from '@openstapps/api/lib/client';
|
||||
import {SCAppConfiguration, SCIndexResponse} from '@openstapps/core';
|
||||
import {NGXLogger} from 'ngx-logger';
|
||||
import {dependencies} from '../../../../package.json';
|
||||
import {environment} from '../../../environments/environment';
|
||||
import {StAppsWebHttpClient} from '../data/stapps-web-http-client.provider';
|
||||
import {StorageProvider} from '../storage/storage.provider';
|
||||
@@ -52,6 +53,11 @@ export class ConfigProvider {
|
||||
*/
|
||||
initialised = false;
|
||||
|
||||
/**
|
||||
* Version of the @openstapps/core package that app is using
|
||||
*/
|
||||
scVersion = dependencies['@openstapps/core'];
|
||||
|
||||
/**
|
||||
* Constructor, initialise api client
|
||||
*
|
||||
@@ -70,7 +76,7 @@ export class ConfigProvider {
|
||||
*/
|
||||
async fetch(): Promise<SCIndexResponse> {
|
||||
try {
|
||||
return await this.client.handshake(environment.backend_version);
|
||||
return await this.client.handshake(this.scVersion);
|
||||
} catch (error) {
|
||||
throw new ConfigFetchError();
|
||||
}
|
||||
@@ -113,8 +119,8 @@ export class ConfigProvider {
|
||||
this.config = await this.loadLocal();
|
||||
this.initialised = true;
|
||||
this.logger.log(`initialised configuration from storage`);
|
||||
if (this.config.backend.SCVersion !== environment.backend_version) {
|
||||
loadError = new WrongConfigVersionInStorage(environment.backend_version, this.config.backend.SCVersion);
|
||||
if (this.config.backend.SCVersion !== this.scVersion) {
|
||||
loadError = new WrongConfigVersionInStorage(this.scVersion, this.config.backend.SCVersion);
|
||||
this.logger.warn(loadError);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
"declaration": false,
|
||||
"emitDecoratorMetadata": true,
|
||||
"strictPropertyInitialization": false,
|
||||
"resolveJsonModule": true,
|
||||
"lib": [
|
||||
"es2017",
|
||||
"dom"
|
||||
|
||||
Reference in New Issue
Block a user