diff --git a/libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts b/libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts index bb34126673..67da958a92 100644 --- a/libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts +++ b/libs/api/repository/src/lib/gn4/platform/gn4-platform.mapper.ts @@ -37,6 +37,6 @@ export class Gn4PlatformMapper { credentialsNonExpired, ...user } = apiUser - return { ...apiUser, id: id + '' } as UserModel + return { ...apiUser, id: id.toString() } as UserModel } } diff --git a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.spec.ts b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.spec.ts index 4d42efc935..7580f52018 100644 --- a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.spec.ts +++ b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.spec.ts @@ -5,7 +5,7 @@ import { } from '@geonetwork-ui/data-access/gn4' import { TestBed } from '@angular/core/testing' import { Gn4PlatformService } from './gn4-platform.service' -import { firstValueFrom, lastValueFrom, of, Subject } from 'rxjs' +import { firstValueFrom, of, Subject } from 'rxjs' import { AvatarServiceInterface } from '../auth/avatar.service.interface' import { Gn4PlatformMapper } from './gn4-platform.mapper' @@ -31,6 +31,7 @@ class MeApiMock { getMe() { return this._me$ } + _me$ = new Subject() } @@ -46,6 +47,7 @@ class SiteApiServiceMock { }) ) } + class UsersApiServiceMock { getUsers() { return of([ @@ -98,11 +100,32 @@ describe('Gn4PlatformService', () => { expect(service).toBeTruthy() }) - it('fetches version from settings', async () => { - geonetworkVersion = '4.2.0' - const version = await firstValueFrom(service.getApiVersion()) - expect(version).toEqual('4.2.0') + describe('version', () => { + describe('when version is lower than 4.2.2', () => { + beforeEach(() => { + geonetworkVersion = '4.2.0' + }) + it('throws an error', async () => { + let error + await firstValueFrom(service.getApiVersion()).catch((e) => (error = e)) + expect(error).toEqual( + new Error( + 'Gn4 API version is not compatible.\nMinimum: 4.2.2\nYour version: 4.2.0' + ) + ) + }) + }) + describe('when version is euqal or greater than 4.2.2', () => { + beforeEach(() => { + geonetworkVersion = '4.2.2' + }) + it('fetches version from settings', async () => { + const version = await firstValueFrom(service.getApiVersion()) + expect(version).toEqual('4.2.2') + }) + }) }) + it('fetches users from api', async () => { const users = await firstValueFrom(service.getUsers()) expect(users).toEqual([ diff --git a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts index b87eb9ef0f..0b4cfa1d3e 100644 --- a/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts +++ b/libs/api/repository/src/lib/gn4/platform/gn4-platform.service.ts @@ -10,8 +10,9 @@ import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform. import { UserModel } from '@geonetwork-ui/common/domain/model/user/user.model' import { Organization } from '@geonetwork-ui/common/domain/model/record' import { Gn4PlatformMapper } from './gn4-platform.mapper' +import { ltr } from 'semver' -const minApiVersion = '4.2.0' +const minApiVersion = '4.2.2' @Injectable() export class Gn4PlatformService implements PlatformServiceInterface { private readonly type = 'GeoNetwork'