From 1454fda3f91d5764e18489d5ca12e46810c7e06a Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Thu, 23 Nov 2023 08:50:44 +0100 Subject: [PATCH 01/19] N21-1494 WIP --- .../common/enum/tool-configuration-status.ts | 22 ++- .../mapper/tool-status-response.mapper.ts | 16 +- .../service/common-tool.service.spec.ts | 84 +++++++++-- .../common/service/common-tool.service.ts | 14 +- .../dto/tool-configuration-status.response.ts | 29 +++- .../controller/dto/tool-reference.response.ts | 4 +- .../controller/tool-reference.controller.ts | 3 +- .../service/tool-reference.service.ts | 3 +- .../service/tool-version-service.spec.ts | 140 +++++++++++++++++- .../service/tool-version-service.ts | 20 ++- .../dto/school-external-tool.response.ts | 2 +- .../school-external-tool-response.mapper.ts | 10 +- .../service/school-external-tool.service.ts | 32 +++- .../service/tool-launch.service.spec.ts | 31 +++- .../service/tool-launch.service.ts | 4 +- .../tool/school-external-tool.factory.ts | 8 +- 16 files changed, 368 insertions(+), 54 deletions(-) diff --git a/apps/server/src/modules/tool/common/enum/tool-configuration-status.ts b/apps/server/src/modules/tool/common/enum/tool-configuration-status.ts index de0db175c49..c84a5ecc3a5 100644 --- a/apps/server/src/modules/tool/common/enum/tool-configuration-status.ts +++ b/apps/server/src/modules/tool/common/enum/tool-configuration-status.ts @@ -1,5 +1,19 @@ -export enum ToolConfigurationStatus { - LATEST = 'Latest', - OUTDATED = 'Outdated', - UNKNOWN = 'Unknown', +export class ToolConfigurationStatus { + latest: boolean; + + isDisabled: boolean; + + isOutdatedOnScopeSchool: boolean; + + isOutdatedOnScopeContext: boolean; + + isUnkown: boolean; + + constructor(props: ToolConfigurationStatus) { + this.latest = props.latest; + this.isDisabled = props.isDisabled; + this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool; + this.isOutdatedOnScopeContext = props.isOutdatedOnScopeContext; + this.isUnkown = props.isUnkown; + } } diff --git a/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts b/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts index 0c16ca50e9a..2287bcc29aa 100644 --- a/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts +++ b/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts @@ -1,14 +1,16 @@ import { ToolConfigurationStatusResponse } from '../../context-external-tool/controller/dto'; import { ToolConfigurationStatus } from '../enum'; -export const statusMapping: Record = { - [ToolConfigurationStatus.LATEST]: ToolConfigurationStatusResponse.LATEST, - [ToolConfigurationStatus.OUTDATED]: ToolConfigurationStatusResponse.OUTDATED, - [ToolConfigurationStatus.UNKNOWN]: ToolConfigurationStatusResponse.UNKNOWN, -}; - export class ToolStatusResponseMapper { static mapToResponse(status: ToolConfigurationStatus): ToolConfigurationStatusResponse { - return statusMapping[status]; + const configurationStatus: ToolConfigurationStatusResponse = new ToolConfigurationStatusResponse({ + latest: status.latest, + isDisabled: status.isDisabled, + isOutdatedOnScopeSchool: status.isOutdatedOnScopeSchool, + isOutdatedOnScopeContext: status.isOutdatedOnScopeContext, + isUnkown: status.isUnkown, + }); + + return configurationStatus; } } diff --git a/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts b/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts index 11677e6e916..081896c3a5e 100644 --- a/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts +++ b/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts @@ -36,7 +36,7 @@ describe('CommonToolService', () => { }; }; - it('should return ToolConfigurationStatus.LATEST', () => { + it('should return is latest', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( @@ -45,7 +45,15 @@ describe('CommonToolService', () => { contextExternalTool ); - expect(result).toBe(ToolConfigurationStatus.LATEST); + expect(result).toStrictEqual( + new ToolConfigurationStatus({ + latest: true, + isUnkown: false, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + }) + ); }); }); @@ -62,7 +70,7 @@ describe('CommonToolService', () => { }; }; - it('should return ToolConfigurationStatus.OUTDATED', () => { + it('should return isOutdatedOnScopeContext and isOutdatedOnScopeSchool true', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( @@ -71,7 +79,15 @@ describe('CommonToolService', () => { contextExternalTool ); - expect(result).toBe(ToolConfigurationStatus.OUTDATED); + expect(result).toStrictEqual( + new ToolConfigurationStatus({ + latest: false, + isUnkown: false, + isDisabled: false, + isOutdatedOnScopeContext: true, + isOutdatedOnScopeSchool: true, + }) + ); }); }); @@ -88,7 +104,7 @@ describe('CommonToolService', () => { }; }; - it('should return ToolConfigurationStatus.OUTDATED', () => { + it('should return isOutdatedOnScopeContext true', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( @@ -97,7 +113,15 @@ describe('CommonToolService', () => { contextExternalTool ); - expect(result).toBe(ToolConfigurationStatus.OUTDATED); + expect(result).toStrictEqual( + new ToolConfigurationStatus({ + latest: false, + isUnkown: false, + isDisabled: false, + isOutdatedOnScopeContext: true, + isOutdatedOnScopeSchool: false, + }) + ); }); }); @@ -114,7 +138,7 @@ describe('CommonToolService', () => { }; }; - it('should return ToolConfigurationStatus.OUTDATED', () => { + it('should return isOutdatedOnScopeContext true', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( @@ -123,7 +147,15 @@ describe('CommonToolService', () => { contextExternalTool ); - expect(result).toBe(ToolConfigurationStatus.OUTDATED); + expect(result).toStrictEqual( + new ToolConfigurationStatus({ + latest: false, + isUnkown: false, + isDisabled: false, + isOutdatedOnScopeContext: true, + isOutdatedOnScopeSchool: false, + }) + ); }); }); @@ -140,7 +172,7 @@ describe('CommonToolService', () => { }; }; - it('should return ToolConfigurationStatus.LATEST', () => { + it('should return is latest', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( @@ -149,7 +181,15 @@ describe('CommonToolService', () => { contextExternalTool ); - expect(result).toBe(ToolConfigurationStatus.LATEST); + expect(result).toStrictEqual( + new ToolConfigurationStatus({ + latest: true, + isUnkown: false, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + }) + ); }); }); @@ -166,7 +206,7 @@ describe('CommonToolService', () => { }; }; - it('should return ToolConfigurationStatus.LATEST', () => { + it('should return is latest', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( @@ -175,7 +215,15 @@ describe('CommonToolService', () => { contextExternalTool ); - expect(result).toBe(ToolConfigurationStatus.LATEST); + expect(result).toStrictEqual( + new ToolConfigurationStatus({ + latest: true, + isUnkown: false, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + }) + ); }); }); @@ -192,7 +240,7 @@ describe('CommonToolService', () => { }; }; - it('should return ToolConfigurationStatus.LATEST', () => { + it('should return is latest', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( @@ -201,7 +249,15 @@ describe('CommonToolService', () => { contextExternalTool ); - expect(result).toBe(ToolConfigurationStatus.LATEST); + expect(result).toStrictEqual( + new ToolConfigurationStatus({ + latest: true, + isUnkown: false, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + }) + ); }); }); }); diff --git a/apps/server/src/modules/tool/common/service/common-tool.service.ts b/apps/server/src/modules/tool/common/service/common-tool.service.ts index 1dccc42ab1f..48e96ff059f 100644 --- a/apps/server/src/modules/tool/common/service/common-tool.service.ts +++ b/apps/server/src/modules/tool/common/service/common-tool.service.ts @@ -16,15 +16,25 @@ export class CommonToolService { schoolExternalTool: SchoolExternalTool, contextExternalTool: ContextExternalTool ): ToolConfigurationStatus { + const configurationStatus: ToolConfigurationStatus = new ToolConfigurationStatus({ + latest: false, + isDisabled: false, + isOutdatedOnScopeContext: true, + isOutdatedOnScopeSchool: true, + isUnkown: false, + }); + if ( this.isLatest(schoolExternalTool, externalTool) && this.isLatest(contextExternalTool, schoolExternalTool) && this.isLatest(contextExternalTool, externalTool) ) { - return ToolConfigurationStatus.LATEST; + configurationStatus.latest = true; + configurationStatus.isOutdatedOnScopeContext = false; + configurationStatus.isOutdatedOnScopeSchool = false; } - return ToolConfigurationStatus.OUTDATED; + return configurationStatus; } private isLatest(tool1: ToolVersion, tool2: ToolVersion): boolean { diff --git a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-configuration-status.response.ts b/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-configuration-status.response.ts index 200ac12e101..e0f76646c6f 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-configuration-status.response.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-configuration-status.response.ts @@ -1,5 +1,26 @@ -export enum ToolConfigurationStatusResponse { - LATEST = 'Latest', - OUTDATED = 'Outdated', - UNKNOWN = 'Unknown', +import { ApiProperty } from '@nestjs/swagger'; + +export class ToolConfigurationStatusResponse { + @ApiProperty() + latest: boolean; + + @ApiProperty() + isDisabled: boolean; + + @ApiProperty() + isOutdatedOnScopeSchool: boolean; + + @ApiProperty() + isOutdatedOnScopeContext: boolean; + + @ApiProperty() + isUnkown: boolean; + + constructor(props: ToolConfigurationStatusResponse) { + this.latest = props.latest; + this.isDisabled = props.isDisabled; + this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool; + this.isOutdatedOnScopeContext = props.isOutdatedOnScopeContext; + this.isUnkown = props.isUnkown; + } } diff --git a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts b/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts index 0ccefffa6ae..6e10e2cd980 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts @@ -19,10 +19,8 @@ export class ToolReferenceResponse { openInNewTab: boolean; @ApiProperty({ - enum: ToolConfigurationStatusResponse, - enumName: 'ToolConfigurationStatusResponse', + type: ToolConfigurationStatusResponse, nullable: false, - required: true, description: 'The status of the tool', }) status: ToolConfigurationStatusResponse; diff --git a/apps/server/src/modules/tool/context-external-tool/controller/tool-reference.controller.ts b/apps/server/src/modules/tool/context-external-tool/controller/tool-reference.controller.ts index 3c00d30e6e2..de491c763c9 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/tool-reference.controller.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/tool-reference.controller.ts @@ -60,7 +60,8 @@ export class ToolReferenceController { const toolReferenceResponses: ToolReferenceResponse[] = ContextExternalToolResponseMapper.mapToToolReferenceResponses(toolReferences); - const toolReferenceListResponse = new ToolReferenceListResponse(toolReferenceResponses); + + const toolReferenceListResponse: ToolReferenceListResponse = new ToolReferenceListResponse(toolReferenceResponses); return toolReferenceListResponse; } diff --git a/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.ts b/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.ts index 1f677e3e159..4cf2bcf5c41 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.ts @@ -1,5 +1,6 @@ import { Injectable } from '@nestjs/common'; import { EntityId } from '@shared/domain'; +import { ToolConfigurationStatus } from '../../common/enum'; import { ExternalTool } from '../../external-tool/domain'; import { ExternalToolLogoService, ExternalToolService } from '../../external-tool/service'; import { SchoolExternalTool } from '../../school-external-tool/domain'; @@ -28,7 +29,7 @@ export class ToolReferenceService { ); const externalTool: ExternalTool = await this.externalToolService.findById(schoolExternalTool.toolId); - const status = await this.toolVersionService.determineToolConfigurationStatus( + const status: ToolConfigurationStatus = await this.toolVersionService.determineToolConfigurationStatus( externalTool, schoolExternalTool, contextExternalTool diff --git a/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts b/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts index 33c77ecb7ea..59c7397591e 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts @@ -122,7 +122,15 @@ describe('ToolVersionService', () => { contextExternalTool ); - expect(status).toEqual(ToolConfigurationStatus.LATEST); + expect(status).toEqual( + new ToolConfigurationStatus({ + latest: true, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + isUnkown: false, + }) + ); }); it('should call schoolExternalToolValidationService', async () => { @@ -142,7 +150,66 @@ describe('ToolVersionService', () => { }); }); - describe('when FEATURE_COMPUTE_TOOL_STATUS_WITHOUT_VERSIONS_ENABLED is true and validation throws an error', () => { + describe('when FEATURE_COMPUTE_TOOL_STATUS_WITHOUT_VERSIONS_ENABLED is true and validation of SchoolExternalTool throws an error', () => { + const setup = () => { + const externalTool = externalToolFactory.buildWithId(); + const schoolExternalTool = schoolExternalToolFactory.buildWithId({ + toolId: externalTool.id as string, + }); + const contextExternalTool = contextExternalToolFactory + .withSchoolExternalToolRef(schoolExternalTool.id as string) + .buildWithId(); + + toolFeatures.toolStatusWithoutVersions = true; + + schoolExternalToolValidationService.validate.mockRejectedValueOnce(ApiValidationError); + contextExternalToolValidationService.validate.mockResolvedValue(); + + return { + externalTool, + schoolExternalTool, + contextExternalTool, + }; + }; + + it('should return outdated tool status', async () => { + const { externalTool, schoolExternalTool, contextExternalTool } = setup(); + + const status: ToolConfigurationStatus = await service.determineToolConfigurationStatus( + externalTool, + schoolExternalTool, + contextExternalTool + ); + + expect(status).toEqual( + new ToolConfigurationStatus({ + latest: false, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: true, + isUnkown: false, + }) + ); + }); + + it('should call schoolExternalToolValidationService', async () => { + const { externalTool, schoolExternalTool, contextExternalTool } = setup(); + + await service.determineToolConfigurationStatus(externalTool, schoolExternalTool, contextExternalTool); + + expect(schoolExternalToolValidationService.validate).toHaveBeenCalledWith(schoolExternalTool); + }); + + it('should call contextExternalToolValidationService', async () => { + const { externalTool, schoolExternalTool, contextExternalTool } = setup(); + + await service.determineToolConfigurationStatus(externalTool, schoolExternalTool, contextExternalTool); + + expect(contextExternalToolValidationService.validate).toHaveBeenCalledWith(contextExternalTool); + }); + }); + + describe('when FEATURE_COMPUTE_TOOL_STATUS_WITHOUT_VERSIONS_ENABLED is true and validation of ContextExternalTool throws an error', () => { const setup = () => { const externalTool = externalToolFactory.buildWithId(); const schoolExternalTool = schoolExternalToolFactory.buildWithId({ @@ -173,7 +240,74 @@ describe('ToolVersionService', () => { contextExternalTool ); - expect(status).toEqual(ToolConfigurationStatus.OUTDATED); + expect(status).toEqual( + new ToolConfigurationStatus({ + latest: false, + isDisabled: false, + isOutdatedOnScopeContext: true, + isOutdatedOnScopeSchool: false, + isUnkown: false, + }) + ); + }); + + it('should call schoolExternalToolValidationService', async () => { + const { externalTool, schoolExternalTool, contextExternalTool } = setup(); + + await service.determineToolConfigurationStatus(externalTool, schoolExternalTool, contextExternalTool); + + expect(schoolExternalToolValidationService.validate).toHaveBeenCalledWith(schoolExternalTool); + }); + + it('should call contextExternalToolValidationService', async () => { + const { externalTool, schoolExternalTool, contextExternalTool } = setup(); + + await service.determineToolConfigurationStatus(externalTool, schoolExternalTool, contextExternalTool); + + expect(contextExternalToolValidationService.validate).toHaveBeenCalledWith(contextExternalTool); + }); + }); + + describe('when FEATURE_COMPUTE_TOOL_STATUS_WITHOUT_VERSIONS_ENABLED is true and validation of SchoolExternalTool and ContextExternalTool throws an error', () => { + const setup = () => { + const externalTool = externalToolFactory.buildWithId(); + const schoolExternalTool = schoolExternalToolFactory.buildWithId({ + toolId: externalTool.id as string, + }); + const contextExternalTool = contextExternalToolFactory + .withSchoolExternalToolRef(schoolExternalTool.id as string) + .buildWithId(); + + toolFeatures.toolStatusWithoutVersions = true; + + schoolExternalToolValidationService.validate.mockRejectedValueOnce(ApiValidationError); + contextExternalToolValidationService.validate.mockRejectedValueOnce(ApiValidationError); + + return { + externalTool, + schoolExternalTool, + contextExternalTool, + }; + }; + + it('should return outdated tool status', async () => { + const { externalTool, schoolExternalTool, contextExternalTool } = setup(); + + const status: ToolConfigurationStatus = await service.determineToolConfigurationStatus( + externalTool, + schoolExternalTool, + contextExternalTool + ); + + expect(status).toEqual( + new ToolConfigurationStatus({ + latest: false, + isDisabled: false, + isOutdatedOnScopeContext: true, + isOutdatedOnScopeSchool: true, + isUnkown: false, + }) + ); }); it('should call schoolExternalToolValidationService', async () => { diff --git a/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts b/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts index 2ba0709372a..9a1c77f460e 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts @@ -25,13 +25,29 @@ export class ToolVersionService { ): Promise { // TODO N21-1337 remove if statement, when feature flag is removed if (this.toolFeatures.toolStatusWithoutVersions) { + const configurationStatus: ToolConfigurationStatus = new ToolConfigurationStatus({ + latest: true, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + isUnkown: false, + }); + try { await this.schoolExternalToolValidationService.validate(schoolExternalTool); + } catch (err) { + configurationStatus.latest = false; + configurationStatus.isOutdatedOnScopeSchool = true; + } + + try { await this.contextExternalToolValidationService.validate(contextExternalTool); - return ToolConfigurationStatus.LATEST; } catch (err) { - return ToolConfigurationStatus.OUTDATED; + configurationStatus.latest = false; + configurationStatus.isOutdatedOnScopeContext = true; } + + return configurationStatus; } const status: ToolConfigurationStatus = this.commonToolService.determineToolConfigurationStatus( externalTool, diff --git a/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool.response.ts b/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool.response.ts index 32dd35f10bd..015a59aa7e8 100644 --- a/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool.response.ts +++ b/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool.response.ts @@ -21,7 +21,7 @@ export class SchoolExternalToolResponse { @ApiProperty() toolVersion: number; - @ApiProperty({ enum: ToolConfigurationStatusResponse }) + @ApiProperty({ type: ToolConfigurationStatusResponse }) status: ToolConfigurationStatusResponse; @ApiPropertyOptional() diff --git a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.ts b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.ts index 7388b1a6a41..b9115308c8f 100644 --- a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.ts +++ b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { CustomParameterEntry } from '../../common/domain'; -import { ToolStatusResponseMapper } from '../../common/mapper/tool-status-response.mapper'; +import { ToolStatusResponseMapper } from '../../common/mapper'; import { ToolConfigurationStatusResponse } from '../../context-external-tool/controller/dto'; import { CustomParameterEntryResponse, @@ -28,7 +28,13 @@ export class SchoolExternalToolResponseMapper { toolVersion: schoolExternalTool.toolVersion, status: schoolExternalTool.status ? ToolStatusResponseMapper.mapToResponse(schoolExternalTool.status) - : ToolConfigurationStatusResponse.UNKNOWN, + : new ToolConfigurationStatusResponse({ + latest: false, + isUnkown: true, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + }), }; } diff --git a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts index e654f82f96a..bbc30bddebf 100644 --- a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts +++ b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts @@ -57,20 +57,44 @@ export class SchoolExternalToolService { tool: SchoolExternalTool, externalTool: ExternalTool ): Promise { + let configurationStatus: ToolConfigurationStatus = new ToolConfigurationStatus({ + latest: false, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: true, + isUnkown: false, + }); + if (this.toolFeatures.toolStatusWithoutVersions) { try { await this.schoolExternalToolValidationService.validate(tool); - return ToolConfigurationStatus.LATEST; + configurationStatus = new ToolConfigurationStatus({ + latest: true, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + isUnkown: false, + }); + + return configurationStatus; } catch (err) { - return ToolConfigurationStatus.OUTDATED; + return configurationStatus; } } if (externalTool.version <= tool.toolVersion) { - return ToolConfigurationStatus.LATEST; + configurationStatus = new ToolConfigurationStatus({ + latest: true, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + isUnkown: false, + }); + + return configurationStatus; } - return ToolConfigurationStatus.OUTDATED; + return configurationStatus; } async deleteSchoolExternalToolById(schoolExternalToolId: EntityId): Promise { diff --git a/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.spec.ts b/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.spec.ts index 16e8e093e9e..176f2c3c598 100644 --- a/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.spec.ts +++ b/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.spec.ts @@ -1,3 +1,4 @@ +import { tr } from '@faker-js/faker'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { InternalServerErrorException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; @@ -107,7 +108,15 @@ describe('ToolLaunchService', () => { schoolExternalToolService.findById.mockResolvedValue(schoolExternalTool); externalToolService.findById.mockResolvedValue(externalTool); basicToolLaunchStrategy.createLaunchData.mockResolvedValue(launchDataDO); - toolVersionService.determineToolConfigurationStatus.mockResolvedValueOnce(ToolConfigurationStatus.LATEST); + toolVersionService.determineToolConfigurationStatus.mockResolvedValueOnce( + new ToolConfigurationStatus({ + latest: true, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + isUnkown: false, + }) + ); return { launchDataDO, @@ -173,7 +182,15 @@ describe('ToolLaunchService', () => { schoolExternalToolService.findById.mockResolvedValue(schoolExternalTool); externalToolService.findById.mockResolvedValue(externalTool); - toolVersionService.determineToolConfigurationStatus.mockResolvedValueOnce(ToolConfigurationStatus.LATEST); + toolVersionService.determineToolConfigurationStatus.mockResolvedValueOnce( + new ToolConfigurationStatus({ + latest: true, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + isUnkown: false, + }) + ); return { launchParams, @@ -218,7 +235,15 @@ describe('ToolLaunchService', () => { schoolExternalToolService.findById.mockResolvedValue(schoolExternalTool); externalToolService.findById.mockResolvedValue(externalTool); basicToolLaunchStrategy.createLaunchData.mockResolvedValue(launchDataDO); - toolVersionService.determineToolConfigurationStatus.mockResolvedValueOnce(ToolConfigurationStatus.OUTDATED); + toolVersionService.determineToolConfigurationStatus.mockResolvedValueOnce( + new ToolConfigurationStatus({ + latest: false, + isDisabled: false, + isOutdatedOnScopeContext: true, + isOutdatedOnScopeSchool: true, + isUnkown: false, + }) + ); return { launchParams, diff --git a/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.ts b/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.ts index 5b090f9778a..69a44cc09b3 100644 --- a/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.ts +++ b/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.ts @@ -89,13 +89,13 @@ export class ToolLaunchService { schoolExternalTool: SchoolExternalTool, contextExternalTool: ContextExternalTool ): Promise { - const status = await this.toolVersionService.determineToolConfigurationStatus( + const status: ToolConfigurationStatus = await this.toolVersionService.determineToolConfigurationStatus( externalTool, schoolExternalTool, contextExternalTool ); - if (status !== ToolConfigurationStatus.LATEST) { + if (!status.latest) { throw new ToolStatusOutdatedLoggableException(userId, contextExternalTool.id ?? ''); } } diff --git a/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool.factory.ts b/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool.factory.ts index a10ae7797fe..c99534ed137 100644 --- a/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool.factory.ts +++ b/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool.factory.ts @@ -24,6 +24,12 @@ export const schoolExternalToolFactory = SchoolExternalToolFactory.define(School }), ], toolId: 'toolId', - status: ToolConfigurationStatus.LATEST, + status: new ToolConfigurationStatus({ + latest: true, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + isUnkown: false, + }), }; }); From b28bdd02b43713e4e4ae0b447751cca5422bfd63 Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Thu, 23 Nov 2023 08:51:39 +0100 Subject: [PATCH 02/19] N21-1494 remove import --- .../modules/tool/tool-launch/service/tool-launch.service.spec.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.spec.ts b/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.spec.ts index 176f2c3c598..a5e5c57cf92 100644 --- a/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.spec.ts +++ b/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.spec.ts @@ -1,4 +1,3 @@ -import { tr } from '@faker-js/faker'; import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { InternalServerErrorException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; From 6659d213f51ef71813e3f7a77139f22443c8de84 Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Thu, 23 Nov 2023 14:48:40 +0100 Subject: [PATCH 03/19] N21-1494 move toolConfiguration status --- .../src/modules/tool/common/domain/index.ts | 2 +- .../tool-configuration-status.ts | 0 .../src/modules/tool/common/enum/index.ts | 2 +- .../service/tool-reference.service.spec.ts | 18 +++++++++-- .../api-test/tool-school.api.spec.ts | 32 ++++++++++++++++--- 5 files changed, 46 insertions(+), 8 deletions(-) rename apps/server/src/modules/tool/common/{enum => domain}/tool-configuration-status.ts (100%) diff --git a/apps/server/src/modules/tool/common/domain/index.ts b/apps/server/src/modules/tool/common/domain/index.ts index ae59ec3f2a3..155961be0d3 100644 --- a/apps/server/src/modules/tool/common/domain/index.ts +++ b/apps/server/src/modules/tool/common/domain/index.ts @@ -1,3 +1,3 @@ export * from './custom-parameter.do'; export * from './custom-parameter-entry.do'; -export * from '../enum/tool-configuration-status'; +export * from './tool-configuration-status'; diff --git a/apps/server/src/modules/tool/common/enum/tool-configuration-status.ts b/apps/server/src/modules/tool/common/domain/tool-configuration-status.ts similarity index 100% rename from apps/server/src/modules/tool/common/enum/tool-configuration-status.ts rename to apps/server/src/modules/tool/common/domain/tool-configuration-status.ts diff --git a/apps/server/src/modules/tool/common/enum/index.ts b/apps/server/src/modules/tool/common/enum/index.ts index 24628ac19f5..950593fc6b9 100644 --- a/apps/server/src/modules/tool/common/enum/index.ts +++ b/apps/server/src/modules/tool/common/enum/index.ts @@ -10,4 +10,4 @@ export * from './tool-context-type.enum'; export * from './custom-parameter-location.enum'; export * from './custom-parameter-scope.enum'; export * from './custom-parameter-type.enum'; -export * from './tool-configuration-status'; +export * from '../domain/tool-configuration-status'; diff --git a/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.spec.ts b/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.spec.ts index 1796b2f681d..22683f78c18 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.spec.ts @@ -79,7 +79,15 @@ describe('ToolReferenceService', () => { contextExternalToolService.findById.mockResolvedValueOnce(contextExternalTool); schoolExternalToolService.findById.mockResolvedValueOnce(schoolExternalTool); externalToolService.findById.mockResolvedValueOnce(externalTool); - toolVersionService.determineToolConfigurationStatus.mockResolvedValue(ToolConfigurationStatus.OUTDATED); + toolVersionService.determineToolConfigurationStatus.mockResolvedValue( + new ToolConfigurationStatus({ + latest: false, + isDisabled: false, + isOutdatedOnScopeSchool: true, + isOutdatedOnScopeContext: false, + isUnkown: false, + }) + ); externalToolLogoService.buildLogoUrl.mockReturnValue(logoUrl); return { @@ -123,7 +131,13 @@ describe('ToolReferenceService', () => { logoUrl, displayName: contextExternalTool.displayName as string, openInNewTab: externalTool.openNewTab, - status: ToolConfigurationStatus.OUTDATED, + status: new ToolConfigurationStatus({ + latest: false, + isDisabled: false, + isOutdatedOnScopeSchool: true, + isOutdatedOnScopeContext: false, + isUnkown: false, + }), contextToolId: contextExternalToolId, }); }); diff --git a/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts b/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts index 274bd289edf..632456bdb9a 100644 --- a/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts +++ b/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts @@ -140,7 +140,13 @@ describe('ToolSchoolController (API)', () => { name: externalToolEntity.name, schoolId: postParams.schoolId, toolId: postParams.toolId, - status: ToolConfigurationStatusResponse.LATEST, + status: new ToolConfigurationStatusResponse({ + latest: true, + isDisabled: false, + isOutdatedOnScopeSchool: false, + isOutdatedOnScopeContext: false, + isUnkown: false, + }), toolVersion: postParams.version, parameters: [ { name: 'param1', value: 'value' }, @@ -297,7 +303,13 @@ describe('ToolSchoolController (API)', () => { name: externalToolEntity.name, schoolId: school.id, toolId: externalToolEntity.id, - status: ToolConfigurationStatusResponse.OUTDATED, + status: new ToolConfigurationStatusResponse({ + latest: false, + isDisabled: false, + isOutdatedOnScopeSchool: true, + isOutdatedOnScopeContext: false, + isUnkown: false, + }), toolVersion: schoolExternalToolEntity.toolVersion, parameters: [ { @@ -340,7 +352,13 @@ describe('ToolSchoolController (API)', () => { name: '', schoolId: school.id, toolId: externalToolEntity.id, - status: ToolConfigurationStatusResponse.UNKNOWN, + status: new ToolConfigurationStatusResponse({ + latest: false, + isDisabled: false, + isOutdatedOnScopeSchool: false, + isOutdatedOnScopeContext: false, + isUnkown: true, + }), toolVersion: schoolExternalToolEntity.toolVersion, parameters: [ { @@ -466,7 +484,13 @@ describe('ToolSchoolController (API)', () => { name: externalToolEntity.name, schoolId: postParamsUpdate.schoolId, toolId: postParamsUpdate.toolId, - status: ToolConfigurationStatusResponse.LATEST, + status: new ToolConfigurationStatusResponse({ + latest: true, + isDisabled: false, + isOutdatedOnScopeSchool: false, + isOutdatedOnScopeContext: false, + isUnkown: false, + }), toolVersion: postParamsUpdate.version, parameters: [ { From 988deaf8304739a167df47cabe2f61c5ac13b3e0 Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Thu, 23 Nov 2023 14:57:13 +0100 Subject: [PATCH 04/19] N21-1494 fix tests --- .../api-test/tool-reference.api.spec.ts | 16 ++++++++++++++-- .../uc/tool-reference.uc.spec.ts | 16 ++++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts b/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts index 9eae3c7298e..b6e9bd49c78 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts @@ -160,7 +160,13 @@ describe('ToolReferenceController (API)', () => { { contextToolId: contextExternalToolEntity.id, displayName: contextExternalToolEntity.displayName as string, - status: ToolConfigurationStatusResponse.LATEST, + status: new ToolConfigurationStatusResponse({ + latest: true, + isDisabled: false, + isOutdatedOnScopeSchool: false, + isOutdatedOnScopeContext: false, + isUnkown: false, + }), logoUrl: `http://localhost:3030/api/v3/tools/external-tools/${externalToolEntity.id}/logo`, openInNewTab: externalToolEntity.openNewTab, }, @@ -277,7 +283,13 @@ describe('ToolReferenceController (API)', () => { expect(response.body).toEqual({ contextToolId: contextExternalToolEntity.id, displayName: contextExternalToolEntity.displayName as string, - status: ToolConfigurationStatusResponse.LATEST, + status: new ToolConfigurationStatusResponse({ + latest: true, + isDisabled: false, + isOutdatedOnScopeSchool: false, + isOutdatedOnScopeContext: false, + isUnkown: false, + }), logoUrl: `http://localhost:3030/api/v3/tools/external-tools/${externalToolEntity.id}/logo`, openInNewTab: externalToolEntity.openNewTab, }); diff --git a/apps/server/src/modules/tool/context-external-tool/uc/tool-reference.uc.spec.ts b/apps/server/src/modules/tool/context-external-tool/uc/tool-reference.uc.spec.ts index 9b18e7ffd3b..b73df6a0ad4 100644 --- a/apps/server/src/modules/tool/context-external-tool/uc/tool-reference.uc.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/uc/tool-reference.uc.spec.ts @@ -60,7 +60,13 @@ describe('ToolReferenceUc', () => { logoUrl: externalTool.logoUrl, contextToolId: contextExternalTool.id as string, displayName: contextExternalTool.displayName as string, - status: ToolConfigurationStatus.LATEST, + status: new ToolConfigurationStatus({ + latest: true, + isDisabled: false, + isOutdatedOnScopeSchool: false, + isOutdatedOnScopeContext: false, + isUnkown: false, + }), openInNewTab: externalTool.openNewTab, }); @@ -146,7 +152,13 @@ describe('ToolReferenceUc', () => { logoUrl: externalTool.logoUrl, contextToolId: contextExternalTool.id as string, displayName: contextExternalTool.displayName as string, - status: ToolConfigurationStatus.LATEST, + status: new ToolConfigurationStatus({ + latest: true, + isDisabled: false, + isOutdatedOnScopeSchool: false, + isOutdatedOnScopeContext: false, + isUnkown: false, + }), openInNewTab: externalTool.openNewTab, }); From 43fbf923fbed988799d54ecca0aa2b8f2889bb6a Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Thu, 23 Nov 2023 15:33:09 +0100 Subject: [PATCH 05/19] N21-1494 fix tests --- .../service/common-tool.service.spec.ts | 4 +- ...hool-external-tool-response.mapper.spec.ts | 24 +++++++-- .../school-external-tool.service.spec.ts | 50 +++++++++++++++++-- 3 files changed, 68 insertions(+), 10 deletions(-) diff --git a/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts b/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts index 081896c3a5e..ae0a2a3a248 100644 --- a/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts +++ b/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts @@ -119,7 +119,7 @@ describe('CommonToolService', () => { isUnkown: false, isDisabled: false, isOutdatedOnScopeContext: true, - isOutdatedOnScopeSchool: false, + isOutdatedOnScopeSchool: true, }) ); }); @@ -153,7 +153,7 @@ describe('CommonToolService', () => { isUnkown: false, isDisabled: false, isOutdatedOnScopeContext: true, - isOutdatedOnScopeSchool: false, + isOutdatedOnScopeSchool: true, }) ); }); diff --git a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts index ca2296e6df7..5110b78a726 100644 --- a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts +++ b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts @@ -52,7 +52,13 @@ describe('SchoolExternalToolResponseMapper', () => { value: do1.parameters[0].value, }, ], - status: ToolConfigurationStatusResponse.LATEST, + status: new ToolConfigurationStatusResponse({ + latest: true, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + isUnkown: false, + }), }, { id: do2.id as string, @@ -66,7 +72,13 @@ describe('SchoolExternalToolResponseMapper', () => { value: do2.parameters[0].value, }, ], - status: ToolConfigurationStatusResponse.UNKNOWN, + status: new ToolConfigurationStatusResponse({ + latest: false, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + isUnkown: true, + }), }, ]) ); @@ -98,7 +110,13 @@ describe('SchoolExternalToolResponseMapper', () => { expect.objectContaining({ id: '', name: '', - status: ToolConfigurationStatusResponse.UNKNOWN, + status: new ToolConfigurationStatusResponse({ + latest: false, + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + isUnkown: true, + }), }) ); }); diff --git a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts index 1def9935806..eaf31cfadd0 100644 --- a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts +++ b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts @@ -112,7 +112,15 @@ describe('SchoolExternalToolService', () => { schoolExternalTool ); - expect(schoolExternalToolDOs[0].status).toEqual(ToolConfigurationStatus.OUTDATED); + expect(schoolExternalToolDOs[0].status).toEqual( + new ToolConfigurationStatus({ + latest: false, + isDisabled: false, + isOutdatedOnScopeSchool: true, + isOutdatedOnScopeContext: false, + isUnkown: false, + }) + ); }); }); @@ -128,7 +136,15 @@ describe('SchoolExternalToolService', () => { schoolExternalTool ); - expect(schoolExternalToolDOs[0].status).toEqual(ToolConfigurationStatus.LATEST); + expect(schoolExternalToolDOs[0].status).toEqual( + new ToolConfigurationStatus({ + latest: true, + isDisabled: false, + isOutdatedOnScopeSchool: false, + isOutdatedOnScopeContext: false, + isUnkown: false, + }) + ); }); }); @@ -144,7 +160,15 @@ describe('SchoolExternalToolService', () => { schoolExternalTool ); - expect(schoolExternalToolDOs[0].status).toEqual(ToolConfigurationStatus.LATEST); + expect(schoolExternalToolDOs[0].status).toEqual( + new ToolConfigurationStatus({ + latest: true, + isDisabled: false, + isOutdatedOnScopeSchool: false, + isOutdatedOnScopeContext: false, + isUnkown: false, + }) + ); }); }); }); @@ -170,7 +194,15 @@ describe('SchoolExternalToolService', () => { const schoolExternalToolDOs: SchoolExternalTool[] = await service.findSchoolExternalTools(schoolExternalTool); expect(schoolExternalToolValidationService.validate).toHaveBeenCalledWith(schoolExternalTool); - expect(schoolExternalToolDOs[0].status).toEqual(ToolConfigurationStatus.LATEST); + expect(schoolExternalToolDOs[0].status).toEqual( + new ToolConfigurationStatus({ + latest: true, + isDisabled: false, + isOutdatedOnScopeSchool: false, + isOutdatedOnScopeContext: false, + isUnkown: false, + }) + ); }); }); @@ -195,7 +227,15 @@ describe('SchoolExternalToolService', () => { const schoolExternalToolDOs: SchoolExternalTool[] = await service.findSchoolExternalTools(schoolExternalTool); expect(schoolExternalToolValidationService.validate).toHaveBeenCalledWith(schoolExternalTool); - expect(schoolExternalToolDOs[0].status).toEqual(ToolConfigurationStatus.OUTDATED); + expect(schoolExternalToolDOs[0].status).toEqual( + new ToolConfigurationStatus({ + latest: false, + isDisabled: false, + isOutdatedOnScopeSchool: true, + isOutdatedOnScopeContext: false, + isUnkown: false, + }) + ); }); }); }); From 3926f0ff001e339927d433a07ea2cf3d626a065f Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Fri, 24 Nov 2023 17:01:48 +0100 Subject: [PATCH 06/19] N21-1494 review changes --- .../domain/tool-configuration-status.ts | 6 -- .../src/modules/tool/common/enum/index.ts | 1 - .../mapper/tool-status-response.mapper.ts | 4 +- .../service/common-tool.service.spec.ts | 64 +++++++------------ .../common/service/common-tool.service.ts | 20 +++--- .../api-test/tool-reference.api.spec.ts | 11 +--- .../dto/tool-configuration-status.response.ts | 22 +++---- .../controller/dto/tool-reference.response.ts | 1 + .../domain/tool-reference.ts | 2 +- .../mapper/tool-reference.mapper.ts | 2 +- .../service/tool-reference.service.spec.ts | 18 +++--- .../service/tool-reference.service.ts | 2 +- .../service/tool-version-service.spec.ts | 28 ++++---- .../service/tool-version-service.ts | 6 +- .../uc/tool-reference.uc.spec.ts | 14 ++-- .../api-test/tool-school.api.spec.ts | 19 ++---- .../domain/school-external-tool.do.ts | 3 +- ...hool-external-tool-response.mapper.spec.ts | 16 ++--- .../school-external-tool-response.mapper.ts | 2 - .../school-external-tool.service.spec.ts | 27 ++------ .../service/school-external-tool.service.ts | 31 +++------ .../service/tool-launch.service.spec.ts | 18 ++---- .../service/tool-launch.service.ts | 5 +- .../factory/domainobject/tool/index.ts | 1 + .../tool/school-external-tool.factory.ts | 11 +--- .../tool/tool-configuration-status.factory.ts | 14 ++++ ...l-configuration-status-response.factory.ts | 13 ++++ 27 files changed, 143 insertions(+), 218 deletions(-) create mode 100644 apps/server/src/shared/testing/factory/domainobject/tool/tool-configuration-status.factory.ts create mode 100644 apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts diff --git a/apps/server/src/modules/tool/common/domain/tool-configuration-status.ts b/apps/server/src/modules/tool/common/domain/tool-configuration-status.ts index c84a5ecc3a5..b21f330f372 100644 --- a/apps/server/src/modules/tool/common/domain/tool-configuration-status.ts +++ b/apps/server/src/modules/tool/common/domain/tool-configuration-status.ts @@ -1,19 +1,13 @@ export class ToolConfigurationStatus { - latest: boolean; - isDisabled: boolean; isOutdatedOnScopeSchool: boolean; isOutdatedOnScopeContext: boolean; - isUnkown: boolean; - constructor(props: ToolConfigurationStatus) { - this.latest = props.latest; this.isDisabled = props.isDisabled; this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool; this.isOutdatedOnScopeContext = props.isOutdatedOnScopeContext; - this.isUnkown = props.isUnkown; } } diff --git a/apps/server/src/modules/tool/common/enum/index.ts b/apps/server/src/modules/tool/common/enum/index.ts index 950593fc6b9..0be1ea98eb8 100644 --- a/apps/server/src/modules/tool/common/enum/index.ts +++ b/apps/server/src/modules/tool/common/enum/index.ts @@ -10,4 +10,3 @@ export * from './tool-context-type.enum'; export * from './custom-parameter-location.enum'; export * from './custom-parameter-scope.enum'; export * from './custom-parameter-type.enum'; -export * from '../domain/tool-configuration-status'; diff --git a/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts b/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts index 2287bcc29aa..34c527ec3bb 100644 --- a/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts +++ b/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts @@ -1,14 +1,12 @@ import { ToolConfigurationStatusResponse } from '../../context-external-tool/controller/dto'; -import { ToolConfigurationStatus } from '../enum'; +import { ToolConfigurationStatus } from '../domain'; export class ToolStatusResponseMapper { static mapToResponse(status: ToolConfigurationStatus): ToolConfigurationStatusResponse { const configurationStatus: ToolConfigurationStatusResponse = new ToolConfigurationStatusResponse({ - latest: status.latest, isDisabled: status.isDisabled, isOutdatedOnScopeSchool: status.isOutdatedOnScopeSchool, isOutdatedOnScopeContext: status.isOutdatedOnScopeContext, - isUnkown: status.isUnkown, }); return configurationStatus; diff --git a/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts b/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts index ae0a2a3a248..2185629a752 100644 --- a/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts +++ b/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts @@ -1,9 +1,14 @@ import { Test, TestingModule } from '@nestjs/testing'; -import { contextExternalToolFactory, externalToolFactory, schoolExternalToolFactory } from '@shared/testing'; +import { + contextExternalToolFactory, + externalToolFactory, + schoolExternalToolFactory, + toolConfigurationStatusFactory, +} from '@shared/testing'; +import { ToolConfigurationStatus } from '../domain'; import { CommonToolService } from './common-tool.service'; import { ExternalTool } from '../../external-tool/domain'; import { SchoolExternalTool } from '../../school-external-tool/domain'; -import { ToolConfigurationStatus } from '../enum'; import { ContextExternalTool } from '../../context-external-tool/domain'; describe('CommonToolService', () => { @@ -36,7 +41,7 @@ describe('CommonToolService', () => { }; }; - it('should return is latest', () => { + it('should return a configuration status with latest true', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( @@ -46,10 +51,7 @@ describe('CommonToolService', () => { ); expect(result).toStrictEqual( - new ToolConfigurationStatus({ - latest: true, - isUnkown: false, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, }) @@ -70,7 +72,7 @@ describe('CommonToolService', () => { }; }; - it('should return isOutdatedOnScopeContext and isOutdatedOnScopeSchool true', () => { + it('should return outdated status for school level', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( @@ -80,11 +82,8 @@ describe('CommonToolService', () => { ); expect(result).toStrictEqual( - new ToolConfigurationStatus({ - latest: false, - isUnkown: false, - isDisabled: false, - isOutdatedOnScopeContext: true, + toolConfigurationStatusFactory.build({ + isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: true, }) ); @@ -104,7 +103,7 @@ describe('CommonToolService', () => { }; }; - it('should return isOutdatedOnScopeContext true', () => { + it('should return outdated status for context level', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( @@ -114,12 +113,9 @@ describe('CommonToolService', () => { ); expect(result).toStrictEqual( - new ToolConfigurationStatus({ - latest: false, - isUnkown: false, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: true, - isOutdatedOnScopeSchool: true, + isOutdatedOnScopeSchool: false, }) ); }); @@ -138,7 +134,7 @@ describe('CommonToolService', () => { }; }; - it('should return isOutdatedOnScopeContext true', () => { + it('should return outdated status for context and school level', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( @@ -148,12 +144,9 @@ describe('CommonToolService', () => { ); expect(result).toStrictEqual( - new ToolConfigurationStatus({ - latest: false, - isUnkown: false, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: true, - isOutdatedOnScopeSchool: true, + isOutdatedOnScopeSchool: false, }) ); }); @@ -172,7 +165,7 @@ describe('CommonToolService', () => { }; }; - it('should return is latest', () => { + it('should return a configuration status with latest true', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( @@ -182,10 +175,7 @@ describe('CommonToolService', () => { ); expect(result).toStrictEqual( - new ToolConfigurationStatus({ - latest: true, - isUnkown: false, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, }) @@ -206,7 +196,7 @@ describe('CommonToolService', () => { }; }; - it('should return is latest', () => { + it('should return a configuration status with latest true', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( @@ -216,10 +206,7 @@ describe('CommonToolService', () => { ); expect(result).toStrictEqual( - new ToolConfigurationStatus({ - latest: true, - isUnkown: false, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, }) @@ -240,7 +227,7 @@ describe('CommonToolService', () => { }; }; - it('should return is latest', () => { + it('should return a configuration status with latest true', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( @@ -250,10 +237,7 @@ describe('CommonToolService', () => { ); expect(result).toStrictEqual( - new ToolConfigurationStatus({ - latest: true, - isUnkown: false, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, }) diff --git a/apps/server/src/modules/tool/common/service/common-tool.service.ts b/apps/server/src/modules/tool/common/service/common-tool.service.ts index 48e96ff059f..9b0bb1bdce8 100644 --- a/apps/server/src/modules/tool/common/service/common-tool.service.ts +++ b/apps/server/src/modules/tool/common/service/common-tool.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common'; import { ExternalTool } from '../../external-tool/domain'; import { SchoolExternalTool } from '../../school-external-tool/domain'; import { ContextExternalTool } from '../../context-external-tool/domain'; -import { ToolConfigurationStatus } from '../enum'; +import { ToolConfigurationStatus } from '../domain'; import { ToolVersion } from '../interface'; // TODO N21-1337 remove class when tool versioning is removed @@ -17,19 +17,21 @@ export class CommonToolService { contextExternalTool: ContextExternalTool ): ToolConfigurationStatus { const configurationStatus: ToolConfigurationStatus = new ToolConfigurationStatus({ - latest: false, isDisabled: false, isOutdatedOnScopeContext: true, isOutdatedOnScopeSchool: true, - isUnkown: false, }); - if ( - this.isLatest(schoolExternalTool, externalTool) && - this.isLatest(contextExternalTool, schoolExternalTool) && - this.isLatest(contextExternalTool, externalTool) - ) { - configurationStatus.latest = true; + if (!this.isLatest(schoolExternalTool, externalTool)) { + configurationStatus.isOutdatedOnScopeContext = false; + configurationStatus.isOutdatedOnScopeSchool = true; + } else if (!this.isLatest(contextExternalTool, schoolExternalTool)) { + configurationStatus.isOutdatedOnScopeContext = true; + configurationStatus.isOutdatedOnScopeSchool = false; + } else if (!this.isLatest(contextExternalTool, externalTool)) { + configurationStatus.isOutdatedOnScopeContext = true; + configurationStatus.isOutdatedOnScopeSchool = true; + } else { configurationStatus.isOutdatedOnScopeContext = false; configurationStatus.isOutdatedOnScopeSchool = false; } diff --git a/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts b/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts index b6e9bd49c78..e5c5b25ee0d 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts @@ -13,13 +13,13 @@ import { UserAndAccountTestFactory, } from '@shared/testing'; import { ServerTestModule } from '@modules/server'; +import { toolConfigurationStatusResponseFactory } from '@shared/testing/factory/tool-configuration-status-response.factory'; import { Response } from 'supertest'; import { ToolContextType } from '../../../common/enum'; import { ExternalToolEntity } from '../../../external-tool/entity'; import { SchoolExternalToolEntity } from '../../../school-external-tool/entity'; import { ContextExternalToolEntity, ContextExternalToolType } from '../../entity'; import { ContextExternalToolContextParams, ToolReferenceListResponse, ToolReferenceResponse } from '../dto'; -import { ToolConfigurationStatusResponse } from '../dto/tool-configuration-status.response'; describe('ToolReferenceController (API)', () => { let app: INestApplication; @@ -160,12 +160,10 @@ describe('ToolReferenceController (API)', () => { { contextToolId: contextExternalToolEntity.id, displayName: contextExternalToolEntity.displayName as string, - status: new ToolConfigurationStatusResponse({ - latest: true, + status: toolConfigurationStatusResponseFactory.build({ isDisabled: false, isOutdatedOnScopeSchool: false, isOutdatedOnScopeContext: false, - isUnkown: false, }), logoUrl: `http://localhost:3030/api/v3/tools/external-tools/${externalToolEntity.id}/logo`, openInNewTab: externalToolEntity.openNewTab, @@ -283,12 +281,9 @@ describe('ToolReferenceController (API)', () => { expect(response.body).toEqual({ contextToolId: contextExternalToolEntity.id, displayName: contextExternalToolEntity.displayName as string, - status: new ToolConfigurationStatusResponse({ - latest: true, - isDisabled: false, + status: toolConfigurationStatusResponseFactory.build({ isOutdatedOnScopeSchool: false, isOutdatedOnScopeContext: false, - isUnkown: false, }), logoUrl: `http://localhost:3030/api/v3/tools/external-tools/${externalToolEntity.id}/logo`, openInNewTab: externalToolEntity.openNewTab, diff --git a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-configuration-status.response.ts b/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-configuration-status.response.ts index e0f76646c6f..68d186116ed 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-configuration-status.response.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-configuration-status.response.ts @@ -1,26 +1,26 @@ import { ApiProperty } from '@nestjs/swagger'; export class ToolConfigurationStatusResponse { - @ApiProperty() - latest: boolean; - - @ApiProperty() + @ApiProperty({ type: Boolean, description: 'Is the tool disabled for context?' }) isDisabled: boolean; - @ApiProperty() + @ApiProperty({ + type: Boolean, + description: + 'Is the tool outdated on school scope, because of non matching versions or required parameter changes on ExternalTool?', + }) isOutdatedOnScopeSchool: boolean; - @ApiProperty() + @ApiProperty({ + type: Boolean, + description: + 'Is the tool outdated on context scope, because of non matching versions or required parameter changes on SchoolExternalTool?', + }) isOutdatedOnScopeContext: boolean; - @ApiProperty() - isUnkown: boolean; - constructor(props: ToolConfigurationStatusResponse) { - this.latest = props.latest; this.isDisabled = props.isDisabled; this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool; this.isOutdatedOnScopeContext = props.isOutdatedOnScopeContext; - this.isUnkown = props.isUnkown; } } diff --git a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts b/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts index 6e10e2cd980..a2a6f3b63e0 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts @@ -21,6 +21,7 @@ export class ToolReferenceResponse { @ApiProperty({ type: ToolConfigurationStatusResponse, nullable: false, + required: true, description: 'The status of the tool', }) status: ToolConfigurationStatusResponse; diff --git a/apps/server/src/modules/tool/context-external-tool/domain/tool-reference.ts b/apps/server/src/modules/tool/context-external-tool/domain/tool-reference.ts index b3ab846d2b0..296c359818d 100644 --- a/apps/server/src/modules/tool/context-external-tool/domain/tool-reference.ts +++ b/apps/server/src/modules/tool/context-external-tool/domain/tool-reference.ts @@ -1,4 +1,4 @@ -import { ToolConfigurationStatus } from '../../common/enum'; +import { ToolConfigurationStatus } from '../../common/domain'; export class ToolReference { contextToolId: string; diff --git a/apps/server/src/modules/tool/context-external-tool/mapper/tool-reference.mapper.ts b/apps/server/src/modules/tool/context-external-tool/mapper/tool-reference.mapper.ts index be6e6b8ab12..58c35fbb7be 100644 --- a/apps/server/src/modules/tool/context-external-tool/mapper/tool-reference.mapper.ts +++ b/apps/server/src/modules/tool/context-external-tool/mapper/tool-reference.mapper.ts @@ -1,4 +1,4 @@ -import { ToolConfigurationStatus } from '../../common/enum'; +import { ToolConfigurationStatus } from '../../common/domain'; import { ExternalTool } from '../../external-tool/domain'; import { ContextExternalTool, ToolReference } from '../domain'; diff --git a/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.spec.ts b/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.spec.ts index 22683f78c18..15543ad03a1 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.spec.ts @@ -1,8 +1,12 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { ObjectId } from '@mikro-orm/mongodb'; import { Test, TestingModule } from '@nestjs/testing'; -import { contextExternalToolFactory, externalToolFactory, schoolExternalToolFactory } from '@shared/testing'; -import { ToolConfigurationStatus } from '../../common/enum'; +import { + contextExternalToolFactory, + externalToolFactory, + schoolExternalToolFactory, + toolConfigurationStatusFactory, +} from '@shared/testing'; import { ExternalToolLogoService, ExternalToolService } from '../../external-tool/service'; import { SchoolExternalToolService } from '../../school-external-tool/service'; import { ToolReference } from '../domain'; @@ -80,12 +84,9 @@ describe('ToolReferenceService', () => { schoolExternalToolService.findById.mockResolvedValueOnce(schoolExternalTool); externalToolService.findById.mockResolvedValueOnce(externalTool); toolVersionService.determineToolConfigurationStatus.mockResolvedValue( - new ToolConfigurationStatus({ - latest: false, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: true, isOutdatedOnScopeContext: false, - isUnkown: false, }) ); externalToolLogoService.buildLogoUrl.mockReturnValue(logoUrl); @@ -131,12 +132,9 @@ describe('ToolReferenceService', () => { logoUrl, displayName: contextExternalTool.displayName as string, openInNewTab: externalTool.openNewTab, - status: new ToolConfigurationStatus({ - latest: false, - isDisabled: false, + status: toolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: true, isOutdatedOnScopeContext: false, - isUnkown: false, }), contextToolId: contextExternalToolId, }); diff --git a/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.ts b/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.ts index 4cf2bcf5c41..57096b3ea4d 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.ts @@ -1,6 +1,6 @@ import { Injectable } from '@nestjs/common'; import { EntityId } from '@shared/domain'; -import { ToolConfigurationStatus } from '../../common/enum'; +import { ToolConfigurationStatus } from '../../common/domain'; import { ExternalTool } from '../../external-tool/domain'; import { ExternalToolLogoService, ExternalToolService } from '../../external-tool/service'; import { SchoolExternalTool } from '../../school-external-tool/domain'; diff --git a/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts b/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts index 3a29f9d3ec5..f7b767da364 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts @@ -1,8 +1,13 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; -import { contextExternalToolFactory, externalToolFactory, schoolExternalToolFactory } from '@shared/testing'; -import { ToolConfigurationStatus } from '../../common/enum'; +import { + contextExternalToolFactory, + externalToolFactory, + schoolExternalToolFactory, + toolConfigurationStatusFactory, +} from '@shared/testing'; +import { ToolConfigurationStatus } from '../../common/domain'; import { CommonToolService } from '../../common/service'; import { SchoolExternalToolValidationService } from '../../school-external-tool/service'; import { IToolFeatures, ToolFeatures } from '../../tool-config'; @@ -123,12 +128,9 @@ describe('ToolVersionService', () => { ); expect(status).toEqual( - new ToolConfigurationStatus({ - latest: true, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, - isUnkown: false, }) ); }); @@ -182,12 +184,9 @@ describe('ToolVersionService', () => { ); expect(status).toEqual( - new ToolConfigurationStatus({ - latest: false, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: true, - isUnkown: false, }) ); }); @@ -241,12 +240,9 @@ describe('ToolVersionService', () => { ); expect(status).toEqual( - new ToolConfigurationStatus({ - latest: false, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: true, isOutdatedOnScopeSchool: false, - isUnkown: false, }) ); }); @@ -300,12 +296,10 @@ describe('ToolVersionService', () => { ); expect(status).toEqual( - new ToolConfigurationStatus({ - latest: false, + toolConfigurationStatusFactory.build({ isDisabled: false, isOutdatedOnScopeContext: true, isOutdatedOnScopeSchool: true, - isUnkown: false, }) ); }); diff --git a/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts b/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts index 37e07cab414..2d2a519766b 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts @@ -1,6 +1,6 @@ import { Inject } from '@nestjs/common'; import { Injectable } from '@nestjs/common/decorators/core/injectable.decorator'; -import { ToolConfigurationStatus } from '../../common/enum'; +import { ToolConfigurationStatus } from '../../common/domain'; import { CommonToolService } from '../../common/service'; import { ExternalTool } from '../../external-tool/domain'; import { SchoolExternalTool } from '../../school-external-tool/domain'; @@ -26,24 +26,20 @@ export class ToolVersionService { // TODO N21-1337 remove if statement, when feature flag is removed if (this.toolFeatures.toolStatusWithoutVersions) { const configurationStatus: ToolConfigurationStatus = new ToolConfigurationStatus({ - latest: true, isDisabled: false, isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, - isUnkown: false, }); try { await this.schoolExternalToolValidationService.validate(schoolExternalTool); } catch (err) { - configurationStatus.latest = false; configurationStatus.isOutdatedOnScopeSchool = true; } try { await this.contextExternalToolValidationService.validate(contextExternalTool); } catch (err) { - configurationStatus.latest = false; configurationStatus.isOutdatedOnScopeContext = true; } diff --git a/apps/server/src/modules/tool/context-external-tool/uc/tool-reference.uc.spec.ts b/apps/server/src/modules/tool/context-external-tool/uc/tool-reference.uc.spec.ts index b73df6a0ad4..68ca7044f1e 100644 --- a/apps/server/src/modules/tool/context-external-tool/uc/tool-reference.uc.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/uc/tool-reference.uc.spec.ts @@ -2,9 +2,9 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { ForbiddenException } from '@nestjs/common'; import { Test, TestingModule } from '@nestjs/testing'; import { Permission } from '@shared/domain'; -import { contextExternalToolFactory, externalToolFactory } from '@shared/testing'; +import { contextExternalToolFactory, externalToolFactory, toolConfigurationStatusFactory } from '@shared/testing'; import { AuthorizationContextBuilder } from '@modules/authorization'; -import { ToolConfigurationStatus, ToolContextType } from '../../common/enum'; +import { ToolContextType } from '../../common/enum'; import { ToolPermissionHelper } from '../../common/uc/tool-permission-helper'; import { ExternalTool } from '../../external-tool/domain'; import { ContextExternalTool, ToolReference } from '../domain'; @@ -60,12 +60,9 @@ describe('ToolReferenceUc', () => { logoUrl: externalTool.logoUrl, contextToolId: contextExternalTool.id as string, displayName: contextExternalTool.displayName as string, - status: new ToolConfigurationStatus({ - latest: true, - isDisabled: false, + status: toolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: false, isOutdatedOnScopeContext: false, - isUnkown: false, }), openInNewTab: externalTool.openNewTab, }); @@ -152,12 +149,9 @@ describe('ToolReferenceUc', () => { logoUrl: externalTool.logoUrl, contextToolId: contextExternalTool.id as string, displayName: contextExternalTool.displayName as string, - status: new ToolConfigurationStatus({ - latest: true, - isDisabled: false, + status: toolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: false, isOutdatedOnScopeContext: false, - isUnkown: false, }), openInNewTab: externalTool.openNewTab, }); diff --git a/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts b/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts index 632456bdb9a..2ff96b0806c 100644 --- a/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts +++ b/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts @@ -15,6 +15,7 @@ import { UserAndAccountTestFactory, userFactory, } from '@shared/testing'; +import { toolConfigurationStatusResponseFactory } from '@shared/testing/factory/tool-configuration-status-response.factory'; import { ToolConfigurationStatusResponse } from '../../../context-external-tool/controller/dto'; import { ContextExternalToolEntity, ContextExternalToolType } from '../../../context-external-tool/entity'; import { CustomParameterScope, CustomParameterType, ExternalToolEntity } from '../../../external-tool/entity'; @@ -140,12 +141,10 @@ describe('ToolSchoolController (API)', () => { name: externalToolEntity.name, schoolId: postParams.schoolId, toolId: postParams.toolId, - status: new ToolConfigurationStatusResponse({ - latest: true, + status: toolConfigurationStatusResponseFactory.build({ isDisabled: false, isOutdatedOnScopeSchool: false, isOutdatedOnScopeContext: false, - isUnkown: false, }), toolVersion: postParams.version, parameters: [ @@ -303,12 +302,9 @@ describe('ToolSchoolController (API)', () => { name: externalToolEntity.name, schoolId: school.id, toolId: externalToolEntity.id, - status: new ToolConfigurationStatusResponse({ - latest: false, - isDisabled: false, + status: toolConfigurationStatusResponseFactory.build({ isOutdatedOnScopeSchool: true, isOutdatedOnScopeContext: false, - isUnkown: false, }), toolVersion: schoolExternalToolEntity.toolVersion, parameters: [ @@ -352,12 +348,9 @@ describe('ToolSchoolController (API)', () => { name: '', schoolId: school.id, toolId: externalToolEntity.id, - status: new ToolConfigurationStatusResponse({ - latest: false, - isDisabled: false, + status: toolConfigurationStatusResponseFactory.build({ isOutdatedOnScopeSchool: false, isOutdatedOnScopeContext: false, - isUnkown: true, }), toolVersion: schoolExternalToolEntity.toolVersion, parameters: [ @@ -484,12 +477,10 @@ describe('ToolSchoolController (API)', () => { name: externalToolEntity.name, schoolId: postParamsUpdate.schoolId, toolId: postParamsUpdate.toolId, - status: new ToolConfigurationStatusResponse({ - latest: true, + status: toolConfigurationStatusResponseFactory.build({ isDisabled: false, isOutdatedOnScopeSchool: false, isOutdatedOnScopeContext: false, - isUnkown: false, }), toolVersion: postParamsUpdate.version, parameters: [ diff --git a/apps/server/src/modules/tool/school-external-tool/domain/school-external-tool.do.ts b/apps/server/src/modules/tool/school-external-tool/domain/school-external-tool.do.ts index 621ea1f6366..c8fb433bbb8 100644 --- a/apps/server/src/modules/tool/school-external-tool/domain/school-external-tool.do.ts +++ b/apps/server/src/modules/tool/school-external-tool/domain/school-external-tool.do.ts @@ -1,6 +1,5 @@ import { BaseDO } from '@shared/domain/domainobject/base.do'; -import { CustomParameterEntry } from '../../common/domain'; -import { ToolConfigurationStatus } from '../../common/enum'; +import { CustomParameterEntry, ToolConfigurationStatus } from '../../common/domain'; import { ToolVersion } from '../../common/interface'; export interface SchoolExternalToolProps { diff --git a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts index 5110b78a726..92987eb4557 100644 --- a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts +++ b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts @@ -1,4 +1,5 @@ import { schoolExternalToolFactory } from '@shared/testing/factory'; +import { toolConfigurationStatusResponseFactory } from '@shared/testing/factory/tool-configuration-status-response.factory'; import { ToolConfigurationStatusResponse } from '../../context-external-tool/controller/dto'; import { SchoolExternalToolResponse, SchoolExternalToolSearchListResponse } from '../controller/dto'; import { SchoolExternalTool } from '../domain'; @@ -52,12 +53,9 @@ describe('SchoolExternalToolResponseMapper', () => { value: do1.parameters[0].value, }, ], - status: new ToolConfigurationStatusResponse({ - latest: true, - isDisabled: false, + status: toolConfigurationStatusResponseFactory.build({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, - isUnkown: false, }), }, { @@ -72,12 +70,9 @@ describe('SchoolExternalToolResponseMapper', () => { value: do2.parameters[0].value, }, ], - status: new ToolConfigurationStatusResponse({ - latest: false, - isDisabled: false, + status: toolConfigurationStatusResponseFactory.build({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, - isUnkown: true, }), }, ]) @@ -110,12 +105,9 @@ describe('SchoolExternalToolResponseMapper', () => { expect.objectContaining({ id: '', name: '', - status: new ToolConfigurationStatusResponse({ - latest: false, - isDisabled: false, + status: toolConfigurationStatusResponseFactory.build({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, - isUnkown: true, }), }) ); diff --git a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.ts b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.ts index b9115308c8f..8f6d8058d12 100644 --- a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.ts +++ b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.ts @@ -29,8 +29,6 @@ export class SchoolExternalToolResponseMapper { status: schoolExternalTool.status ? ToolStatusResponseMapper.mapToResponse(schoolExternalTool.status) : new ToolConfigurationStatusResponse({ - latest: false, - isUnkown: true, isDisabled: false, isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, diff --git a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts index eaf31cfadd0..3f653fac5df 100644 --- a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts +++ b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts @@ -2,9 +2,9 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; import { SchoolExternalToolRepo } from '@shared/repo'; +import { toolConfigurationStatusFactory } from '@shared/testing'; import { externalToolFactory } from '@shared/testing/factory/domainobject/tool/external-tool.factory'; import { schoolExternalToolFactory } from '@shared/testing/factory/domainobject/tool/school-external-tool.factory'; -import { ToolConfigurationStatus } from '../../common/enum'; import { ExternalTool } from '../../external-tool/domain'; import { ExternalToolService } from '../../external-tool/service'; import { IToolFeatures, ToolFeatures } from '../../tool-config'; @@ -113,12 +113,9 @@ describe('SchoolExternalToolService', () => { ); expect(schoolExternalToolDOs[0].status).toEqual( - new ToolConfigurationStatus({ - latest: false, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: true, isOutdatedOnScopeContext: false, - isUnkown: false, }) ); }); @@ -137,12 +134,9 @@ describe('SchoolExternalToolService', () => { ); expect(schoolExternalToolDOs[0].status).toEqual( - new ToolConfigurationStatus({ - latest: true, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: false, isOutdatedOnScopeContext: false, - isUnkown: false, }) ); }); @@ -161,12 +155,9 @@ describe('SchoolExternalToolService', () => { ); expect(schoolExternalToolDOs[0].status).toEqual( - new ToolConfigurationStatus({ - latest: true, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: false, isOutdatedOnScopeContext: false, - isUnkown: false, }) ); }); @@ -195,12 +186,9 @@ describe('SchoolExternalToolService', () => { expect(schoolExternalToolValidationService.validate).toHaveBeenCalledWith(schoolExternalTool); expect(schoolExternalToolDOs[0].status).toEqual( - new ToolConfigurationStatus({ - latest: true, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: false, isOutdatedOnScopeContext: false, - isUnkown: false, }) ); }); @@ -228,12 +216,9 @@ describe('SchoolExternalToolService', () => { expect(schoolExternalToolValidationService.validate).toHaveBeenCalledWith(schoolExternalTool); expect(schoolExternalToolDOs[0].status).toEqual( - new ToolConfigurationStatus({ - latest: false, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: true, isOutdatedOnScopeContext: false, - isUnkown: false, }) ); }); diff --git a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts index f4c31c4820d..37f3a002272 100644 --- a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts +++ b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts @@ -1,7 +1,7 @@ import { Inject, Injectable } from '@nestjs/common'; import { EntityId } from '@shared/domain'; import { SchoolExternalToolRepo } from '@shared/repo'; -import { ToolConfigurationStatus } from '../../common/enum'; +import { ToolConfigurationStatus } from '../../common/domain'; import { ExternalTool } from '../../external-tool/domain'; import { ExternalToolService } from '../../external-tool/service'; import { IToolFeatures, ToolFeatures } from '../../tool-config'; @@ -57,41 +57,30 @@ export class SchoolExternalToolService { tool: SchoolExternalTool, externalTool: ExternalTool ): Promise { - let configurationStatus: ToolConfigurationStatus = new ToolConfigurationStatus({ - latest: false, + const configurationStatus: ToolConfigurationStatus = new ToolConfigurationStatus({ isDisabled: false, isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: true, - isUnkown: false, + }); + + const latestConfigurationStatus: ToolConfigurationStatus = new ToolConfigurationStatus({ + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, }); if (this.toolFeatures.toolStatusWithoutVersions) { try { await this.schoolExternalToolValidationService.validate(tool); - configurationStatus = new ToolConfigurationStatus({ - latest: true, - isDisabled: false, - isOutdatedOnScopeContext: false, - isOutdatedOnScopeSchool: false, - isUnkown: false, - }); - return configurationStatus; + return latestConfigurationStatus; } catch (err) { return configurationStatus; } } if (externalTool.version <= tool.toolVersion) { - configurationStatus = new ToolConfigurationStatus({ - latest: true, - isDisabled: false, - isOutdatedOnScopeContext: false, - isOutdatedOnScopeSchool: false, - isUnkown: false, - }); - - return configurationStatus; + return latestConfigurationStatus; } return configurationStatus; diff --git a/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.spec.ts b/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.spec.ts index f768152a275..1f6d80900ef 100644 --- a/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.spec.ts +++ b/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.spec.ts @@ -6,8 +6,9 @@ import { contextExternalToolFactory, externalToolFactory, schoolExternalToolFactory, + toolConfigurationStatusFactory, } from '@shared/testing'; -import { ToolConfigType, ToolConfigurationStatus } from '../../common/enum'; +import { ToolConfigType } from '../../common/enum'; import { ContextExternalTool } from '../../context-external-tool/domain'; import { BasicToolConfig, ExternalTool } from '../../external-tool/domain'; import { ExternalToolService } from '../../external-tool/service'; @@ -108,12 +109,9 @@ describe('ToolLaunchService', () => { externalToolService.findById.mockResolvedValue(externalTool); basicToolLaunchStrategy.createLaunchData.mockResolvedValue(launchDataDO); toolVersionService.determineToolConfigurationStatus.mockResolvedValueOnce( - new ToolConfigurationStatus({ - latest: true, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, - isUnkown: false, }) ); @@ -182,12 +180,9 @@ describe('ToolLaunchService', () => { schoolExternalToolService.findById.mockResolvedValue(schoolExternalTool); externalToolService.findById.mockResolvedValue(externalTool); toolVersionService.determineToolConfigurationStatus.mockResolvedValueOnce( - new ToolConfigurationStatus({ - latest: true, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, - isUnkown: false, }) ); @@ -235,12 +230,9 @@ describe('ToolLaunchService', () => { externalToolService.findById.mockResolvedValue(externalTool); basicToolLaunchStrategy.createLaunchData.mockResolvedValue(launchDataDO); toolVersionService.determineToolConfigurationStatus.mockResolvedValueOnce( - new ToolConfigurationStatus({ - latest: false, - isDisabled: false, + toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: true, isOutdatedOnScopeSchool: true, - isUnkown: false, }) ); diff --git a/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.ts b/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.ts index 1fdd03a38e7..d44d57611a9 100644 --- a/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.ts +++ b/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.ts @@ -1,6 +1,7 @@ import { Injectable, InternalServerErrorException } from '@nestjs/common'; import { EntityId } from '@shared/domain'; -import { ToolConfigType, ToolConfigurationStatus } from '../../common/enum'; +import { ToolConfigurationStatus } from '../../common/domain'; +import { ToolConfigType } from '../../common/enum'; import { ContextExternalTool } from '../../context-external-tool/domain'; import { ExternalTool } from '../../external-tool/domain'; import { ExternalToolService } from '../../external-tool/service'; @@ -95,7 +96,7 @@ export class ToolLaunchService { contextExternalTool ); - if (!status.latest) { + if (status.isOutdatedOnScopeSchool || status.isOutdatedOnScopeContext) { throw new ToolStatusOutdatedLoggableException(userId, contextExternalTool.id ?? ''); } } diff --git a/apps/server/src/shared/testing/factory/domainobject/tool/index.ts b/apps/server/src/shared/testing/factory/domainobject/tool/index.ts index 61ca058e8a7..4765cef90d5 100644 --- a/apps/server/src/shared/testing/factory/domainobject/tool/index.ts +++ b/apps/server/src/shared/testing/factory/domainobject/tool/index.ts @@ -1,3 +1,4 @@ export * from './context-external-tool.factory'; export * from './external-tool.factory'; export * from './school-external-tool.factory'; +export * from './tool-configuration-status.factory'; diff --git a/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool.factory.ts b/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool.factory.ts index c99534ed137..1cc6e3f94b8 100644 --- a/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool.factory.ts +++ b/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool.factory.ts @@ -1,7 +1,8 @@ -import { CustomParameterEntry, ToolConfigurationStatus } from '@modules/tool/common/domain'; +import { CustomParameterEntry } from '@modules/tool/common/domain'; import { SchoolExternalTool, SchoolExternalToolProps } from '@modules/tool/school-external-tool/domain'; import { DeepPartial } from 'fishery'; import { DoBaseFactory } from '../do-base.factory'; +import { toolConfigurationStatusFactory } from './tool-configuration-status.factory'; class SchoolExternalToolFactory extends DoBaseFactory { withSchoolId(schoolId: string): this { @@ -24,12 +25,6 @@ export const schoolExternalToolFactory = SchoolExternalToolFactory.define(School }), ], toolId: 'toolId', - status: new ToolConfigurationStatus({ - latest: true, - isDisabled: false, - isOutdatedOnScopeContext: false, - isOutdatedOnScopeSchool: false, - isUnkown: false, - }), + status: toolConfigurationStatusFactory.build(), }; }); diff --git a/apps/server/src/shared/testing/factory/domainobject/tool/tool-configuration-status.factory.ts b/apps/server/src/shared/testing/factory/domainobject/tool/tool-configuration-status.factory.ts new file mode 100644 index 00000000000..37858579901 --- /dev/null +++ b/apps/server/src/shared/testing/factory/domainobject/tool/tool-configuration-status.factory.ts @@ -0,0 +1,14 @@ +import { ToolConfigurationStatus } from '@modules/tool/common/domain'; + +import { DoBaseFactory } from '../do-base.factory'; + +export const toolConfigurationStatusFactory = DoBaseFactory.define( + ToolConfigurationStatus, + () => { + return { + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + }; + } +); diff --git a/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts b/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts new file mode 100644 index 00000000000..7155895e5e0 --- /dev/null +++ b/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts @@ -0,0 +1,13 @@ +import { ToolConfigurationStatusResponse } from '@modules/tool/context-external-tool/controller/dto'; +import { DoBaseFactory } from './domainobject'; + +export const toolConfigurationStatusResponseFactory = DoBaseFactory.define< + ToolConfigurationStatusResponse, + ToolConfigurationStatusResponse +>(ToolConfigurationStatusResponse, () => { + return { + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + }; +}); From d6d912585779f04b073e2d232633d4b237bffef6 Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Fri, 24 Nov 2023 17:03:02 +0100 Subject: [PATCH 07/19] N21-1494 remove unused imports --- .../controller/api-test/tool-school.api.spec.ts | 1 - .../mapper/school-external-tool-response.mapper.spec.ts | 1 - 2 files changed, 2 deletions(-) diff --git a/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts b/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts index 2ff96b0806c..8739cd89539 100644 --- a/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts +++ b/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts @@ -16,7 +16,6 @@ import { userFactory, } from '@shared/testing'; import { toolConfigurationStatusResponseFactory } from '@shared/testing/factory/tool-configuration-status-response.factory'; -import { ToolConfigurationStatusResponse } from '../../../context-external-tool/controller/dto'; import { ContextExternalToolEntity, ContextExternalToolType } from '../../../context-external-tool/entity'; import { CustomParameterScope, CustomParameterType, ExternalToolEntity } from '../../../external-tool/entity'; import { SchoolExternalToolEntity } from '../../entity'; diff --git a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts index 92987eb4557..c6aac03750d 100644 --- a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts +++ b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts @@ -1,6 +1,5 @@ import { schoolExternalToolFactory } from '@shared/testing/factory'; import { toolConfigurationStatusResponseFactory } from '@shared/testing/factory/tool-configuration-status-response.factory'; -import { ToolConfigurationStatusResponse } from '../../context-external-tool/controller/dto'; import { SchoolExternalToolResponse, SchoolExternalToolSearchListResponse } from '../controller/dto'; import { SchoolExternalTool } from '../domain'; import { SchoolExternalToolResponseMapper } from './school-external-tool-response.mapper'; From 0e82ad6fa4b3888b2efa1ed38ed48a17534032fc Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Mon, 27 Nov 2023 17:05:45 +0100 Subject: [PATCH 08/19] N21-1494 review changes --- .../domain/tool-configuration-status.ts | 5 +++++ .../service/common-tool.service.spec.ts | 14 ++++++------- .../api-test/tool-reference.api.spec.ts | 1 - .../service/tool-version-service.spec.ts | 1 - .../api-test/tool-school.api.spec.ts | 2 -- .../service/school-external-tool.service.ts | 18 +++++++---------- ...status-outdated.loggable-exception.spec.ts | 11 +++++++++- ...tool-status-outdated.loggable-exception.ts | 9 ++++++++- .../service/tool-launch.service.spec.ts | 4 +++- .../service/tool-launch.service.ts | 7 ++++++- .../tool/tool-configuration-status.factory.ts | 20 ++++++++----------- ...l-configuration-status-response.factory.ts | 7 ++----- 12 files changed, 56 insertions(+), 43 deletions(-) diff --git a/apps/server/src/modules/tool/common/domain/tool-configuration-status.ts b/apps/server/src/modules/tool/common/domain/tool-configuration-status.ts index b21f330f372..eaf33c3fae3 100644 --- a/apps/server/src/modules/tool/common/domain/tool-configuration-status.ts +++ b/apps/server/src/modules/tool/common/domain/tool-configuration-status.ts @@ -1,8 +1,13 @@ +import { ApiProperty } from '@nestjs/swagger'; + export class ToolConfigurationStatus { + @ApiProperty({ default: false }) isDisabled: boolean; + @ApiProperty({ default: false }) isOutdatedOnScopeSchool: boolean; + @ApiProperty({ default: false }) isOutdatedOnScopeContext: boolean; constructor(props: ToolConfigurationStatus) { diff --git a/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts b/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts index 2185629a752..c3f6d824ffe 100644 --- a/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts +++ b/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts @@ -50,7 +50,7 @@ describe('CommonToolService', () => { contextExternalTool ); - expect(result).toStrictEqual( + expect(result).toEqual( toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, @@ -81,7 +81,7 @@ describe('CommonToolService', () => { contextExternalTool ); - expect(result).toStrictEqual( + expect(result).toEqual( toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: true, @@ -112,7 +112,7 @@ describe('CommonToolService', () => { contextExternalTool ); - expect(result).toStrictEqual( + expect(result).toEqual( toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: true, isOutdatedOnScopeSchool: false, @@ -143,7 +143,7 @@ describe('CommonToolService', () => { contextExternalTool ); - expect(result).toStrictEqual( + expect(result).toEqual( toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: true, isOutdatedOnScopeSchool: false, @@ -174,7 +174,7 @@ describe('CommonToolService', () => { contextExternalTool ); - expect(result).toStrictEqual( + expect(result).toEqual( toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, @@ -205,7 +205,7 @@ describe('CommonToolService', () => { contextExternalTool ); - expect(result).toStrictEqual( + expect(result).toEqual( toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, @@ -236,7 +236,7 @@ describe('CommonToolService', () => { contextExternalTool ); - expect(result).toStrictEqual( + expect(result).toEqual( toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, diff --git a/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts b/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts index e5c5b25ee0d..41210a8e2de 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts @@ -161,7 +161,6 @@ describe('ToolReferenceController (API)', () => { contextToolId: contextExternalToolEntity.id, displayName: contextExternalToolEntity.displayName as string, status: toolConfigurationStatusResponseFactory.build({ - isDisabled: false, isOutdatedOnScopeSchool: false, isOutdatedOnScopeContext: false, }), diff --git a/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts b/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts index f7b767da364..c992cd4ee91 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts @@ -297,7 +297,6 @@ describe('ToolVersionService', () => { expect(status).toEqual( toolConfigurationStatusFactory.build({ - isDisabled: false, isOutdatedOnScopeContext: true, isOutdatedOnScopeSchool: true, }) diff --git a/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts b/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts index 8739cd89539..94d3d6250dd 100644 --- a/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts +++ b/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts @@ -141,7 +141,6 @@ describe('ToolSchoolController (API)', () => { schoolId: postParams.schoolId, toolId: postParams.toolId, status: toolConfigurationStatusResponseFactory.build({ - isDisabled: false, isOutdatedOnScopeSchool: false, isOutdatedOnScopeContext: false, }), @@ -477,7 +476,6 @@ describe('ToolSchoolController (API)', () => { schoolId: postParamsUpdate.schoolId, toolId: postParamsUpdate.toolId, status: toolConfigurationStatusResponseFactory.build({ - isDisabled: false, isOutdatedOnScopeSchool: false, isOutdatedOnScopeContext: false, }), diff --git a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts index 37f3a002272..eb340f078a9 100644 --- a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts +++ b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts @@ -57,33 +57,29 @@ export class SchoolExternalToolService { tool: SchoolExternalTool, externalTool: ExternalTool ): Promise { - const configurationStatus: ToolConfigurationStatus = new ToolConfigurationStatus({ + const toolConfigStatus: ToolConfigurationStatus = new ToolConfigurationStatus({ isDisabled: false, isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: true, }); - const latestConfigurationStatus: ToolConfigurationStatus = new ToolConfigurationStatus({ - isDisabled: false, - isOutdatedOnScopeContext: false, - isOutdatedOnScopeSchool: false, - }); - if (this.toolFeatures.toolStatusWithoutVersions) { try { await this.schoolExternalToolValidationService.validate(tool); - return latestConfigurationStatus; + return ToolConfigurationStatus.prototype; } catch (err) { - return configurationStatus; + return toolConfigStatus; } } if (externalTool.version <= tool.toolVersion) { - return latestConfigurationStatus; + toolConfigStatus.isOutdatedOnScopeSchool = false; + toolConfigStatus.isOutdatedOnScopeContext = false; + return toolConfigStatus; } - return configurationStatus; + return toolConfigStatus; } async deleteSchoolExternalToolById(schoolExternalToolId: EntityId): Promise { diff --git a/apps/server/src/modules/tool/tool-launch/error/tool-status-outdated.loggable-exception.spec.ts b/apps/server/src/modules/tool/tool-launch/error/tool-status-outdated.loggable-exception.spec.ts index c20249fd69f..168d32e1f12 100644 --- a/apps/server/src/modules/tool/tool-launch/error/tool-status-outdated.loggable-exception.spec.ts +++ b/apps/server/src/modules/tool/tool-launch/error/tool-status-outdated.loggable-exception.spec.ts @@ -1,3 +1,4 @@ +import { toolConfigurationStatusFactory } from '@shared/testing'; import { ToolStatusOutdatedLoggableException } from './tool-status-outdated.loggable-exception'; describe('ToolStatusOutdatedLoggableException', () => { @@ -5,8 +6,14 @@ describe('ToolStatusOutdatedLoggableException', () => { const setup = () => { const toolId = 'toolId'; const userId = 'userId'; + const toolConfigStatus = toolConfigurationStatusFactory.build(); - const exception = new ToolStatusOutdatedLoggableException(userId, toolId); + const exception = new ToolStatusOutdatedLoggableException( + userId, + toolId, + toolConfigStatus.isOutdatedOnScopeSchool, + toolConfigStatus.isOutdatedOnScopeContext + ); return { exception, @@ -25,6 +32,8 @@ describe('ToolStatusOutdatedLoggableException', () => { data: { userId: 'userId', toolId: 'toolId', + isOutdatedOnScopeSchool: false, + isOutdatedOnScopeContext: false, }, }); }); diff --git a/apps/server/src/modules/tool/tool-launch/error/tool-status-outdated.loggable-exception.ts b/apps/server/src/modules/tool/tool-launch/error/tool-status-outdated.loggable-exception.ts index 1b97042eea4..a3a0a57a554 100644 --- a/apps/server/src/modules/tool/tool-launch/error/tool-status-outdated.loggable-exception.ts +++ b/apps/server/src/modules/tool/tool-launch/error/tool-status-outdated.loggable-exception.ts @@ -3,7 +3,12 @@ import { EntityId } from '@shared/domain'; import { ErrorLogMessage, Loggable, LogMessage, ValidationErrorLogMessage } from '@src/core/logger'; export class ToolStatusOutdatedLoggableException extends BadRequestException implements Loggable { - constructor(private readonly userId: EntityId, private readonly toolId: EntityId) { + constructor( + private readonly userId: EntityId, + private readonly toolId: EntityId, + private readonly isOutdatedOnScopeSchool: boolean, + private readonly isOutdatedOnScopeContext: boolean + ) { super(); } @@ -15,6 +20,8 @@ export class ToolStatusOutdatedLoggableException extends BadRequestException imp data: { userId: this.userId, toolId: this.toolId, + isOutdatedOnScopeSchool: this.isOutdatedOnScopeSchool, + isOutdatedOnScopeContext: this.isOutdatedOnScopeContext, }, }; } diff --git a/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.spec.ts b/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.spec.ts index 1f6d80900ef..8bfae71cce1 100644 --- a/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.spec.ts +++ b/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.spec.ts @@ -248,7 +248,9 @@ describe('ToolLaunchService', () => { const func = () => service.getLaunchData(userId, launchParams.contextExternalTool); - await expect(func).rejects.toThrow(new ToolStatusOutdatedLoggableException(userId, contextExternalToolId)); + await expect(func).rejects.toThrow( + new ToolStatusOutdatedLoggableException(userId, contextExternalToolId, true, true) + ); }); }); }); diff --git a/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.ts b/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.ts index d44d57611a9..a3a7d3ddc7a 100644 --- a/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.ts +++ b/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.ts @@ -97,7 +97,12 @@ export class ToolLaunchService { ); if (status.isOutdatedOnScopeSchool || status.isOutdatedOnScopeContext) { - throw new ToolStatusOutdatedLoggableException(userId, contextExternalTool.id ?? ''); + throw new ToolStatusOutdatedLoggableException( + userId, + contextExternalTool.id ?? '', + status.isOutdatedOnScopeSchool, + status.isOutdatedOnScopeContext + ); } } } diff --git a/apps/server/src/shared/testing/factory/domainobject/tool/tool-configuration-status.factory.ts b/apps/server/src/shared/testing/factory/domainobject/tool/tool-configuration-status.factory.ts index 37858579901..3d655632ead 100644 --- a/apps/server/src/shared/testing/factory/domainobject/tool/tool-configuration-status.factory.ts +++ b/apps/server/src/shared/testing/factory/domainobject/tool/tool-configuration-status.factory.ts @@ -1,14 +1,10 @@ import { ToolConfigurationStatus } from '@modules/tool/common/domain'; +import { Factory } from 'fishery'; -import { DoBaseFactory } from '../do-base.factory'; - -export const toolConfigurationStatusFactory = DoBaseFactory.define( - ToolConfigurationStatus, - () => { - return { - isDisabled: false, - isOutdatedOnScopeContext: false, - isOutdatedOnScopeSchool: false, - }; - } -); +export const toolConfigurationStatusFactory = Factory.define(() => { + return { + isDisabled: false, + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + }; +}); diff --git a/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts b/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts index 7155895e5e0..36e99ab6b74 100644 --- a/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts +++ b/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts @@ -1,10 +1,7 @@ import { ToolConfigurationStatusResponse } from '@modules/tool/context-external-tool/controller/dto'; -import { DoBaseFactory } from './domainobject'; +import { Factory } from 'fishery'; -export const toolConfigurationStatusResponseFactory = DoBaseFactory.define< - ToolConfigurationStatusResponse, - ToolConfigurationStatusResponse ->(ToolConfigurationStatusResponse, () => { +export const toolConfigurationStatusResponseFactory = Factory.define(() => { return { isDisabled: false, isOutdatedOnScopeContext: false, From 3f57ec961d5c7dd30af1bca3a52effad4b5a96d0 Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Tue, 28 Nov 2023 08:10:21 +0100 Subject: [PATCH 09/19] N21-1494 fix test --- .../service/school-external-tool.service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts index eb340f078a9..f40c8f68435 100644 --- a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts +++ b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts @@ -67,7 +67,9 @@ export class SchoolExternalToolService { try { await this.schoolExternalToolValidationService.validate(tool); - return ToolConfigurationStatus.prototype; + toolConfigStatus.isOutdatedOnScopeContext = false; + toolConfigStatus.isOutdatedOnScopeSchool = false; + return toolConfigStatus; } catch (err) { return toolConfigStatus; } From 4028fea2d6a6814cd4a4656da80e5c704848293a Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Thu, 30 Nov 2023 17:01:32 +0100 Subject: [PATCH 10/19] N21-1494 cypress test data --- backup/setup/context-external-tools.json | 64 +++++++++++++++++ backup/setup/external-tools.json | 87 ++++++++++++++++++++++++ backup/setup/school-external-tools.json | 64 +++++++++++++++++ 3 files changed, 215 insertions(+) diff --git a/backup/setup/context-external-tools.json b/backup/setup/context-external-tools.json index 88bb98d33ec..d3328e572cb 100644 --- a/backup/setup/context-external-tools.json +++ b/backup/setup/context-external-tools.json @@ -34,5 +34,69 @@ "$oid": "647de374cf6a427b9d39e5ba" }, "toolVersion": 2 + }, + { + "_id": { + "$oid": "647de3cfab79fd5bd57e68f5" + }, + "createdAt": { + "$date": "2023-11-30T15:25:00.241Z" + }, + "updatedAt": { + "$date": "2023-11-30T15:25:00.241Z" + }, + "schoolTool": { + "$oid": "647de374cf6a427b9d39e5bc" + }, + "contextId": "0000dcfbfb5c7a3f00bf21ab", + "contextType": "course", + "displayName": "Cypress Test Tool School Scope", + "parameters": [], + "toolVersion": 1 + }, + { + "_id": { + "$oid": "647de3cfab79fd5bd57e68f7" + }, + "createdAt": { + "$date": "2023-11-30T15:29:54.630Z" + }, + "updatedAt": { + "$date": "2023-11-30T15:29:54.630Z" + }, + "schoolTool": { + "$oid": "647de374cf6a427b9d39e5bd" + }, + "contextId": "0000dcfbfb5c7a3f00bf21ab", + "contextType": "course", + "displayName": "Cypress Test Tool Context Scope", + "parameters": [{ + "name": "search", + "value": "test" + }], + "toolVersion": 1 + }, + { + "_id": { + "$oid": "647de3cfab79fd5bd57e68f9" + }, + "createdAt": { + "$date": "2023-11-30T15:30:08.532Z" + }, + "updatedAt": { + "$date": "2023-11-30T15:30:08.532Z" + }, + "schoolTool": { + "$oid": "647de374cf6a427b9d39e5be" + }, + "contextId": "0000dcfbfb5c7a3f00bf21ab", + "contextType": "course", + "displayName": "Cypress Test Tool School and Context Scope", + "parameters": [{ + "name": "contextparam", + "value": "test" + }], + "toolVersion": 1 } + ] diff --git a/backup/setup/external-tools.json b/backup/setup/external-tools.json index 2a3fd937a37..98a893c3938 100644 --- a/backup/setup/external-tools.json +++ b/backup/setup/external-tools.json @@ -99,5 +99,92 @@ "isHidden": false, "openNewTab": false, "version": 2 + }, + { + "_id": { + "$oid": "647de247cf6a427b9d39e5b10" + }, + "createdAt": { + "$date": "2023-11-30T12:37:54.977Z" + }, + "updatedAt": { + "$date": "2023-11-30T15:31:47.749Z" + }, + "name": "Cypress Test Tool School Scope", + "config_type": "basic", + "config_baseUrl": "http:google.com", + "parameters": [{ + "name": "searchparam", + "displayName": "searchparameter", + "description": "", + "scope": "school", + "location": "path", + "type": "string", + "isOptional": false + }], + "isHidden": false, + "openNewTab": false, + "version": 2 + }, + { + "_id": { + "$oid": "647de247cf6a427b9d39e5b11" + }, + "createdAt": { + "$date": "2023-11-30T12:40:29.049Z" + }, + "updatedAt": { + "$date": "2023-11-30T15:32:05.991Z" + }, + "name": "Cypress Test Tool Context Scope", + "config_type": "basic", + "config_baseUrl": "https:google.com", + "parameters": [{ + "name": "searchparam", + "displayName": "searchparameter", + "description": "", + "scope": "context", + "location": "path", + "type": "string", + "isOptional": false + }], + "isHidden": false, + "openNewTab": false, + "version": 2 + }, + { + "_id": { + "$oid": "647de247cf6a427b9d39e5b12" + }, + "createdAt": { + "$date": "2023-11-30T15:28:04.733Z" + }, + "updatedAt": { + "$date": "2023-11-30T15:32:42.888Z" + }, + "name": "Cypress Test Tool School and Context Scope", + "config_type": "basic", + "config_baseUrl": "https:google.com", + "parameters": [{ + "name": "schoolParam", + "displayName": "cypress test school", + "description": "", + "scope": "school", + "location": "path", + "type": "string", + "isOptional": false + }, { + "name": "contextparammm", + "displayName": "cypress test context", + "description": "", + "scope": "context", + "location": "path", + "type": "string", + "isOptional": false + }], + "isHidden": false, + "openNewTab": false, + "version": 2 } + ] diff --git a/backup/setup/school-external-tools.json b/backup/setup/school-external-tools.json index 59befc464af..d222f0b9292 100644 --- a/backup/setup/school-external-tools.json +++ b/backup/setup/school-external-tools.json @@ -68,5 +68,69 @@ }, "schoolParameters": [], "toolVersion": 2 + }, + { + "_id": { + "$oid": "647de374cf6a427b9d39e5bc" + }, + "createdAt": { + "$date": "2023-11-30T15:23:31.370Z" + }, + "updatedAt": { + "$date": "2023-11-30T15:23:31.370Z" + }, + "tool": { + "$oid": "647de247cf6a427b9d39e5b10" + }, + "school": { + "$oid": "5f2987e020834114b8efd6f8" + }, + "schoolParameters": [{ + "name": "search", + "value": "xxx" + }], + "toolVersion": 1 + }, + { + "_id": { + "$oid": "647de374cf6a427b9d39e5bd" + }, + "createdAt": { + "$date": "2023-11-30T15:23:45.423Z" + }, + "updatedAt": { + "$date": "2023-11-30T15:23:45.423Z" + }, + "tool": { + "$oid": "647de247cf6a427b9d39e5b11" + }, + "school": { + "$oid": "5f2987e020834114b8efd6f8" + }, + "schoolParameters": [], + "toolVersion": 1 + }, + { + "_id": { + "$oid": "647de374cf6a427b9d39e5be" + }, + "createdAt": { + "$date": "2023-11-30T15:29:00.061Z" + }, + "updatedAt": { + "$date": "2023-11-30T15:29:00.061Z" + }, + "tool": { + "$oid": "647de247cf6a427b9d39e5b12" + }, + "school": { + "$oid": "5f2987e020834114b8efd6f8" + }, + "schoolParameters": [{ + "name": "schoolParan", + "value": "test" + }], + "toolVersion": 1 } + ] From 96b047a65ce94931cd534df70bffa2b0a465e61a Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Fri, 1 Dec 2023 08:27:52 +0100 Subject: [PATCH 11/19] N21-1494 review changes --- .../domain/tool-configuration-status.ts | 8 ------ .../mapper/tool-status-response.mapper.ts | 1 - .../common/service/common-tool.service.ts | 1 - .../dto/tool-configuration-status.response.ts | 4 --- .../service/tool-version-service.ts | 1 - .../api-test/tool-school.api.spec.ts | 14 ++++------ ...hool-external-tool-configuration-status.ts | 7 +++++ .../controller/dto/index.ts | 1 + ...ol-external-tool-configuration.response.ts | 14 ++++++++++ .../dto/school-external-tool.response.ts | 6 ++-- .../domain/school-external-tool.do.ts | 7 +++-- .../tool/school-external-tool/mapper/index.ts | 1 + ...hool-external-tool-response.mapper.spec.ts | 12 ++++---- .../school-external-tool-response.mapper.ts | 13 +++------ ...ol-external-tool-status-response.mapper.ts | 12 ++++++++ .../school-external-tool.service.spec.ts | 20 ++++++------- .../service/school-external-tool.service.ts | 28 +++++++++---------- .../factory/domainobject/tool/index.ts | 1 + ...ernal-tool-configuration-status.factory.ts | 8 ++++++ .../tool/school-external-tool.factory.ts | 4 +-- .../tool/tool-configuration-status.factory.ts | 1 - .../src/shared/testing/factory/index.ts | 2 ++ ...l-configuration-status-response.factory.ts | 10 +++++++ ...l-configuration-status-response.factory.ts | 1 - 24 files changed, 100 insertions(+), 77 deletions(-) create mode 100644 apps/server/src/modules/tool/school-external-tool/controller/domain/school-external-tool-configuration-status.ts create mode 100644 apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool-configuration.response.ts create mode 100644 apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-status-response.mapper.ts create mode 100644 apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool-configuration-status.factory.ts create mode 100644 apps/server/src/shared/testing/factory/school-tool-configuration-status-response.factory.ts diff --git a/apps/server/src/modules/tool/common/domain/tool-configuration-status.ts b/apps/server/src/modules/tool/common/domain/tool-configuration-status.ts index eaf33c3fae3..507b2c84650 100644 --- a/apps/server/src/modules/tool/common/domain/tool-configuration-status.ts +++ b/apps/server/src/modules/tool/common/domain/tool-configuration-status.ts @@ -1,17 +1,9 @@ -import { ApiProperty } from '@nestjs/swagger'; - export class ToolConfigurationStatus { - @ApiProperty({ default: false }) - isDisabled: boolean; - - @ApiProperty({ default: false }) isOutdatedOnScopeSchool: boolean; - @ApiProperty({ default: false }) isOutdatedOnScopeContext: boolean; constructor(props: ToolConfigurationStatus) { - this.isDisabled = props.isDisabled; this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool; this.isOutdatedOnScopeContext = props.isOutdatedOnScopeContext; } diff --git a/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts b/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts index 34c527ec3bb..555818e5544 100644 --- a/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts +++ b/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts @@ -4,7 +4,6 @@ import { ToolConfigurationStatus } from '../domain'; export class ToolStatusResponseMapper { static mapToResponse(status: ToolConfigurationStatus): ToolConfigurationStatusResponse { const configurationStatus: ToolConfigurationStatusResponse = new ToolConfigurationStatusResponse({ - isDisabled: status.isDisabled, isOutdatedOnScopeSchool: status.isOutdatedOnScopeSchool, isOutdatedOnScopeContext: status.isOutdatedOnScopeContext, }); diff --git a/apps/server/src/modules/tool/common/service/common-tool.service.ts b/apps/server/src/modules/tool/common/service/common-tool.service.ts index 9b0bb1bdce8..cced2fef5a5 100644 --- a/apps/server/src/modules/tool/common/service/common-tool.service.ts +++ b/apps/server/src/modules/tool/common/service/common-tool.service.ts @@ -17,7 +17,6 @@ export class CommonToolService { contextExternalTool: ContextExternalTool ): ToolConfigurationStatus { const configurationStatus: ToolConfigurationStatus = new ToolConfigurationStatus({ - isDisabled: false, isOutdatedOnScopeContext: true, isOutdatedOnScopeSchool: true, }); diff --git a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-configuration-status.response.ts b/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-configuration-status.response.ts index 68d186116ed..760bb41e40e 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-configuration-status.response.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-configuration-status.response.ts @@ -1,9 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; export class ToolConfigurationStatusResponse { - @ApiProperty({ type: Boolean, description: 'Is the tool disabled for context?' }) - isDisabled: boolean; - @ApiProperty({ type: Boolean, description: @@ -19,7 +16,6 @@ export class ToolConfigurationStatusResponse { isOutdatedOnScopeContext: boolean; constructor(props: ToolConfigurationStatusResponse) { - this.isDisabled = props.isDisabled; this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool; this.isOutdatedOnScopeContext = props.isOutdatedOnScopeContext; } diff --git a/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts b/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts index 2d2a519766b..bcc0dea40f0 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts @@ -26,7 +26,6 @@ export class ToolVersionService { // TODO N21-1337 remove if statement, when feature flag is removed if (this.toolFeatures.toolStatusWithoutVersions) { const configurationStatus: ToolConfigurationStatus = new ToolConfigurationStatus({ - isDisabled: false, isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, }); diff --git a/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts b/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts index 94d3d6250dd..a2d9fef570a 100644 --- a/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts +++ b/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts @@ -15,7 +15,7 @@ import { UserAndAccountTestFactory, userFactory, } from '@shared/testing'; -import { toolConfigurationStatusResponseFactory } from '@shared/testing/factory/tool-configuration-status-response.factory'; +import { schoolToolConfigurationStatusFactory } from '@shared/testing/factory/domainobject/tool/school-external-tool-configuration-status.factory'; import { ContextExternalToolEntity, ContextExternalToolType } from '../../../context-external-tool/entity'; import { CustomParameterScope, CustomParameterType, ExternalToolEntity } from '../../../external-tool/entity'; import { SchoolExternalToolEntity } from '../../entity'; @@ -140,9 +140,8 @@ describe('ToolSchoolController (API)', () => { name: externalToolEntity.name, schoolId: postParams.schoolId, toolId: postParams.toolId, - status: toolConfigurationStatusResponseFactory.build({ + status: schoolToolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: false, - isOutdatedOnScopeContext: false, }), toolVersion: postParams.version, parameters: [ @@ -300,9 +299,8 @@ describe('ToolSchoolController (API)', () => { name: externalToolEntity.name, schoolId: school.id, toolId: externalToolEntity.id, - status: toolConfigurationStatusResponseFactory.build({ + status: schoolToolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: true, - isOutdatedOnScopeContext: false, }), toolVersion: schoolExternalToolEntity.toolVersion, parameters: [ @@ -346,9 +344,8 @@ describe('ToolSchoolController (API)', () => { name: '', schoolId: school.id, toolId: externalToolEntity.id, - status: toolConfigurationStatusResponseFactory.build({ + status: schoolToolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: false, - isOutdatedOnScopeContext: false, }), toolVersion: schoolExternalToolEntity.toolVersion, parameters: [ @@ -475,9 +472,8 @@ describe('ToolSchoolController (API)', () => { name: externalToolEntity.name, schoolId: postParamsUpdate.schoolId, toolId: postParamsUpdate.toolId, - status: toolConfigurationStatusResponseFactory.build({ + status: schoolToolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: false, - isOutdatedOnScopeContext: false, }), toolVersion: postParamsUpdate.version, parameters: [ diff --git a/apps/server/src/modules/tool/school-external-tool/controller/domain/school-external-tool-configuration-status.ts b/apps/server/src/modules/tool/school-external-tool/controller/domain/school-external-tool-configuration-status.ts new file mode 100644 index 00000000000..d9c05434274 --- /dev/null +++ b/apps/server/src/modules/tool/school-external-tool/controller/domain/school-external-tool-configuration-status.ts @@ -0,0 +1,7 @@ +export class SchoolToolConfigurationStatus { + isOutdatedOnScopeSchool: boolean; + + constructor(props: SchoolToolConfigurationStatus) { + this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool; + } +} diff --git a/apps/server/src/modules/tool/school-external-tool/controller/dto/index.ts b/apps/server/src/modules/tool/school-external-tool/controller/dto/index.ts index 595b16d7f9c..3631b6989b4 100644 --- a/apps/server/src/modules/tool/school-external-tool/controller/dto/index.ts +++ b/apps/server/src/modules/tool/school-external-tool/controller/dto/index.ts @@ -6,3 +6,4 @@ export * from './school-external-tool-post.params'; export * from './school-external-tool-search.params'; export * from './school-external-tool-search-list.response'; export * from './school-external-tool-metadata.response'; +export * from '../domain/school-external-tool-configuration-status'; diff --git a/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool-configuration.response.ts b/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool-configuration.response.ts new file mode 100644 index 00000000000..665bf1f345e --- /dev/null +++ b/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool-configuration.response.ts @@ -0,0 +1,14 @@ +import { ApiProperty } from '@nestjs/swagger'; + +export class SchoolToolConfigurationStatusResponse { + @ApiProperty({ + type: Boolean, + description: + 'Is the tool outdated on school scope, because of non matching versions or required parameter changes on ExternalTool?', + }) + isOutdatedOnScopeSchool: boolean; + + constructor(props: SchoolToolConfigurationStatusResponse) { + this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool; + } +} diff --git a/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool.response.ts b/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool.response.ts index 015a59aa7e8..cc4be437f54 100644 --- a/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool.response.ts +++ b/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool.response.ts @@ -1,6 +1,6 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; -import { ToolConfigurationStatusResponse } from '../../../context-external-tool/controller/dto/tool-configuration-status.response'; import { CustomParameterEntryResponse } from './custom-parameter-entry.response'; +import { SchoolToolConfigurationStatusResponse } from './school-external-tool-configuration.response'; export class SchoolExternalToolResponse { @ApiProperty() @@ -21,8 +21,8 @@ export class SchoolExternalToolResponse { @ApiProperty() toolVersion: number; - @ApiProperty({ type: ToolConfigurationStatusResponse }) - status: ToolConfigurationStatusResponse; + @ApiProperty({ type: SchoolToolConfigurationStatusResponse }) + status: SchoolToolConfigurationStatusResponse; @ApiPropertyOptional() logoUrl?: string; diff --git a/apps/server/src/modules/tool/school-external-tool/domain/school-external-tool.do.ts b/apps/server/src/modules/tool/school-external-tool/domain/school-external-tool.do.ts index c8fb433bbb8..37eaa4d1daf 100644 --- a/apps/server/src/modules/tool/school-external-tool/domain/school-external-tool.do.ts +++ b/apps/server/src/modules/tool/school-external-tool/domain/school-external-tool.do.ts @@ -1,6 +1,7 @@ import { BaseDO } from '@shared/domain/domainobject/base.do'; -import { CustomParameterEntry, ToolConfigurationStatus } from '../../common/domain'; +import { CustomParameterEntry } from '../../common/domain'; import { ToolVersion } from '../../common/interface'; +import { SchoolToolConfigurationStatus } from '../controller/dto'; export interface SchoolExternalToolProps { id?: string; @@ -15,7 +16,7 @@ export interface SchoolExternalToolProps { toolVersion: number; - status?: ToolConfigurationStatus; + status?: SchoolToolConfigurationStatus; } export class SchoolExternalTool extends BaseDO implements ToolVersion { @@ -29,7 +30,7 @@ export class SchoolExternalTool extends BaseDO implements ToolVersion { toolVersion: number; - status?: ToolConfigurationStatus; + status?: SchoolToolConfigurationStatus; constructor(props: SchoolExternalToolProps) { super(props.id); diff --git a/apps/server/src/modules/tool/school-external-tool/mapper/index.ts b/apps/server/src/modules/tool/school-external-tool/mapper/index.ts index 48cd0b13a20..4b663b7b50b 100644 --- a/apps/server/src/modules/tool/school-external-tool/mapper/index.ts +++ b/apps/server/src/modules/tool/school-external-tool/mapper/index.ts @@ -1,3 +1,4 @@ export * from './school-external-tool-request.mapper'; export * from './school-external-tool-response.mapper'; export * from './school-external-tool-metadata.mapper'; +export * from './school-external-tool-status-response.mapper'; diff --git a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts index c6aac03750d..b9d5480b030 100644 --- a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts +++ b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts @@ -1,5 +1,6 @@ import { schoolExternalToolFactory } from '@shared/testing/factory'; -import { toolConfigurationStatusResponseFactory } from '@shared/testing/factory/tool-configuration-status-response.factory'; +import { schoolToolConfigurationStatusFactory } from '@shared/testing/factory/domainobject/tool/school-external-tool-configuration-status.factory'; +import { schoolToolConfigurationStatusResponseFactory } from '@shared/testing/factory/school-tool-configuration-status-response.factory'; import { SchoolExternalToolResponse, SchoolExternalToolSearchListResponse } from '../controller/dto'; import { SchoolExternalTool } from '../domain'; import { SchoolExternalToolResponseMapper } from './school-external-tool-response.mapper'; @@ -52,8 +53,7 @@ describe('SchoolExternalToolResponseMapper', () => { value: do1.parameters[0].value, }, ], - status: toolConfigurationStatusResponseFactory.build({ - isOutdatedOnScopeContext: false, + status: schoolToolConfigurationStatusResponseFactory.build({ isOutdatedOnScopeSchool: false, }), }, @@ -69,8 +69,7 @@ describe('SchoolExternalToolResponseMapper', () => { value: do2.parameters[0].value, }, ], - status: toolConfigurationStatusResponseFactory.build({ - isOutdatedOnScopeContext: false, + status: schoolToolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: false, }), }, @@ -104,8 +103,7 @@ describe('SchoolExternalToolResponseMapper', () => { expect.objectContaining({ id: '', name: '', - status: toolConfigurationStatusResponseFactory.build({ - isOutdatedOnScopeContext: false, + status: schoolToolConfigurationStatusResponseFactory.build({ isOutdatedOnScopeSchool: false, }), }) diff --git a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.ts b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.ts index 8f6d8058d12..7f48f554003 100644 --- a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.ts +++ b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.ts @@ -1,13 +1,12 @@ import { Injectable } from '@nestjs/common'; import { CustomParameterEntry } from '../../common/domain'; -import { ToolStatusResponseMapper } from '../../common/mapper'; -import { ToolConfigurationStatusResponse } from '../../context-external-tool/controller/dto'; import { CustomParameterEntryResponse, SchoolExternalToolResponse, SchoolExternalToolSearchListResponse, } from '../controller/dto'; import { SchoolExternalTool } from '../domain'; +import { SchoolToolConfigurationStatusResponseMapper } from './school-external-tool-status-response.mapper'; @Injectable() export class SchoolExternalToolResponseMapper { @@ -26,13 +25,9 @@ export class SchoolExternalToolResponseMapper { schoolId: schoolExternalTool.schoolId, parameters: this.mapToCustomParameterEntryResponse(schoolExternalTool.parameters), toolVersion: schoolExternalTool.toolVersion, - status: schoolExternalTool.status - ? ToolStatusResponseMapper.mapToResponse(schoolExternalTool.status) - : new ToolConfigurationStatusResponse({ - isDisabled: false, - isOutdatedOnScopeContext: false, - isOutdatedOnScopeSchool: false, - }), + status: SchoolToolConfigurationStatusResponseMapper.mapToResponse( + schoolExternalTool.status ?? { isOutdatedOnScopeSchool: false } + ), }; } diff --git a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-status-response.mapper.ts b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-status-response.mapper.ts new file mode 100644 index 00000000000..18b3ae59e71 --- /dev/null +++ b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-status-response.mapper.ts @@ -0,0 +1,12 @@ +import { SchoolToolConfigurationStatus } from '../controller/dto'; +import { SchoolToolConfigurationStatusResponse } from '../controller/dto/school-external-tool-configuration.response'; + +export class SchoolToolConfigurationStatusResponseMapper { + static mapToResponse(status: SchoolToolConfigurationStatus): SchoolToolConfigurationStatusResponse { + const configurationStatus: SchoolToolConfigurationStatusResponse = new SchoolToolConfigurationStatusResponse({ + isOutdatedOnScopeSchool: status.isOutdatedOnScopeSchool, + }); + + return configurationStatus; + } +} diff --git a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts index 3f653fac5df..6d80eb3e91a 100644 --- a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts +++ b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts @@ -2,12 +2,13 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; import { SchoolExternalToolRepo } from '@shared/repo'; -import { toolConfigurationStatusFactory } from '@shared/testing'; import { externalToolFactory } from '@shared/testing/factory/domainobject/tool/external-tool.factory'; +import { schoolToolConfigurationStatusFactory } from '@shared/testing/factory/domainobject/tool/school-external-tool-configuration-status.factory'; import { schoolExternalToolFactory } from '@shared/testing/factory/domainobject/tool/school-external-tool.factory'; import { ExternalTool } from '../../external-tool/domain'; import { ExternalToolService } from '../../external-tool/service'; import { IToolFeatures, ToolFeatures } from '../../tool-config'; +import { SchoolToolConfigurationStatus } from '../controller/domain/school-external-tool-configuration-status'; import { SchoolExternalTool } from '../domain'; import { SchoolExternalToolValidationService } from './school-external-tool-validation.service'; import { SchoolExternalToolService } from './school-external-tool.service'; @@ -112,10 +113,9 @@ describe('SchoolExternalToolService', () => { schoolExternalTool ); - expect(schoolExternalToolDOs[0].status).toEqual( - toolConfigurationStatusFactory.build({ + expect(schoolExternalToolDOs[0].status).toEqual( + schoolToolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: true, - isOutdatedOnScopeContext: false, }) ); }); @@ -134,9 +134,8 @@ describe('SchoolExternalToolService', () => { ); expect(schoolExternalToolDOs[0].status).toEqual( - toolConfigurationStatusFactory.build({ + schoolToolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: false, - isOutdatedOnScopeContext: false, }) ); }); @@ -155,9 +154,8 @@ describe('SchoolExternalToolService', () => { ); expect(schoolExternalToolDOs[0].status).toEqual( - toolConfigurationStatusFactory.build({ + schoolToolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: false, - isOutdatedOnScopeContext: false, }) ); }); @@ -186,9 +184,8 @@ describe('SchoolExternalToolService', () => { expect(schoolExternalToolValidationService.validate).toHaveBeenCalledWith(schoolExternalTool); expect(schoolExternalToolDOs[0].status).toEqual( - toolConfigurationStatusFactory.build({ + schoolToolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: false, - isOutdatedOnScopeContext: false, }) ); }); @@ -216,9 +213,8 @@ describe('SchoolExternalToolService', () => { expect(schoolExternalToolValidationService.validate).toHaveBeenCalledWith(schoolExternalTool); expect(schoolExternalToolDOs[0].status).toEqual( - toolConfigurationStatusFactory.build({ + schoolToolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: true, - isOutdatedOnScopeContext: false, }) ); }); diff --git a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts index f40c8f68435..33117588d75 100644 --- a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts +++ b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts @@ -1,10 +1,10 @@ import { Inject, Injectable } from '@nestjs/common'; import { EntityId } from '@shared/domain'; import { SchoolExternalToolRepo } from '@shared/repo'; -import { ToolConfigurationStatus } from '../../common/domain'; import { ExternalTool } from '../../external-tool/domain'; import { ExternalToolService } from '../../external-tool/service'; import { IToolFeatures, ToolFeatures } from '../../tool-config'; +import { SchoolToolConfigurationStatus } from '../controller/dto'; import { SchoolExternalTool } from '../domain'; import { SchoolExternalToolQuery } from '../uc/dto/school-external-tool.types'; import { SchoolExternalToolValidationService } from './school-external-tool-validation.service'; @@ -43,7 +43,7 @@ export class SchoolExternalToolService { private async enrichDataFromExternalTool(tool: SchoolExternalTool): Promise { const externalTool: ExternalTool = await this.externalToolService.findById(tool.toolId); - const status: ToolConfigurationStatus = await this.determineStatus(tool, externalTool); + const status: SchoolToolConfigurationStatus = await this.determineSchoolToolStatus(tool, externalTool); const schoolExternalTool: SchoolExternalTool = new SchoolExternalTool({ ...tool, status, @@ -53,13 +53,11 @@ export class SchoolExternalToolService { return schoolExternalTool; } - private async determineStatus( + private async determineSchoolToolStatus( tool: SchoolExternalTool, externalTool: ExternalTool - ): Promise { - const toolConfigStatus: ToolConfigurationStatus = new ToolConfigurationStatus({ - isDisabled: false, - isOutdatedOnScopeContext: false, + ): Promise { + const status: SchoolToolConfigurationStatus = new SchoolToolConfigurationStatus({ isOutdatedOnScopeSchool: true, }); @@ -67,21 +65,21 @@ export class SchoolExternalToolService { try { await this.schoolExternalToolValidationService.validate(tool); - toolConfigStatus.isOutdatedOnScopeContext = false; - toolConfigStatus.isOutdatedOnScopeSchool = false; - return toolConfigStatus; + status.isOutdatedOnScopeSchool = false; + + return status; } catch (err) { - return toolConfigStatus; + return status; } } if (externalTool.version <= tool.toolVersion) { - toolConfigStatus.isOutdatedOnScopeSchool = false; - toolConfigStatus.isOutdatedOnScopeContext = false; - return toolConfigStatus; + status.isOutdatedOnScopeSchool = false; + + return status; } - return toolConfigStatus; + return status; } async deleteSchoolExternalToolById(schoolExternalToolId: EntityId): Promise { diff --git a/apps/server/src/shared/testing/factory/domainobject/tool/index.ts b/apps/server/src/shared/testing/factory/domainobject/tool/index.ts index 4765cef90d5..2baa19dc715 100644 --- a/apps/server/src/shared/testing/factory/domainobject/tool/index.ts +++ b/apps/server/src/shared/testing/factory/domainobject/tool/index.ts @@ -2,3 +2,4 @@ export * from './context-external-tool.factory'; export * from './external-tool.factory'; export * from './school-external-tool.factory'; export * from './tool-configuration-status.factory'; +export * from './school-external-tool-configuration-status.factory'; diff --git a/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool-configuration-status.factory.ts b/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool-configuration-status.factory.ts new file mode 100644 index 00000000000..5d9655e4b8b --- /dev/null +++ b/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool-configuration-status.factory.ts @@ -0,0 +1,8 @@ +import { SchoolToolConfigurationStatus } from '@modules/tool/school-external-tool/controller/dto'; +import { Factory } from 'fishery'; + +export const schoolToolConfigurationStatusFactory = Factory.define(() => { + return { + isOutdatedOnScopeSchool: false, + }; +}); diff --git a/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool.factory.ts b/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool.factory.ts index 1cc6e3f94b8..94ea7e8b392 100644 --- a/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool.factory.ts +++ b/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool.factory.ts @@ -2,7 +2,7 @@ import { CustomParameterEntry } from '@modules/tool/common/domain'; import { SchoolExternalTool, SchoolExternalToolProps } from '@modules/tool/school-external-tool/domain'; import { DeepPartial } from 'fishery'; import { DoBaseFactory } from '../do-base.factory'; -import { toolConfigurationStatusFactory } from './tool-configuration-status.factory'; +import { schoolToolConfigurationStatusFactory } from './school-external-tool-configuration-status.factory'; class SchoolExternalToolFactory extends DoBaseFactory { withSchoolId(schoolId: string): this { @@ -25,6 +25,6 @@ export const schoolExternalToolFactory = SchoolExternalToolFactory.define(School }), ], toolId: 'toolId', - status: toolConfigurationStatusFactory.build(), + status: schoolToolConfigurationStatusFactory.build(), }; }); diff --git a/apps/server/src/shared/testing/factory/domainobject/tool/tool-configuration-status.factory.ts b/apps/server/src/shared/testing/factory/domainobject/tool/tool-configuration-status.factory.ts index 3d655632ead..a753572946a 100644 --- a/apps/server/src/shared/testing/factory/domainobject/tool/tool-configuration-status.factory.ts +++ b/apps/server/src/shared/testing/factory/domainobject/tool/tool-configuration-status.factory.ts @@ -3,7 +3,6 @@ import { Factory } from 'fishery'; export const toolConfigurationStatusFactory = Factory.define(() => { return { - isDisabled: false, isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, }; diff --git a/apps/server/src/shared/testing/factory/index.ts b/apps/server/src/shared/testing/factory/index.ts index f4d5e0050ce..95910b413ce 100644 --- a/apps/server/src/shared/testing/factory/index.ts +++ b/apps/server/src/shared/testing/factory/index.ts @@ -40,3 +40,5 @@ export * from './user.factory'; export * from './legacy-file-entity-mock.factory'; export * from './jwt.test.factory'; export * from './axios-error.factory'; +export * from './tool-configuration-status-response.factory'; +export * from './school-tool-configuration-status-response.factory'; diff --git a/apps/server/src/shared/testing/factory/school-tool-configuration-status-response.factory.ts b/apps/server/src/shared/testing/factory/school-tool-configuration-status-response.factory.ts new file mode 100644 index 00000000000..9191d1732fd --- /dev/null +++ b/apps/server/src/shared/testing/factory/school-tool-configuration-status-response.factory.ts @@ -0,0 +1,10 @@ +import { SchoolToolConfigurationStatusResponse } from '@modules/tool/school-external-tool/controller/dto/school-external-tool-configuration.response'; +import { Factory } from 'fishery'; + +export const schoolToolConfigurationStatusResponseFactory = Factory.define( + () => { + return { + isOutdatedOnScopeSchool: false, + }; + } +); diff --git a/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts b/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts index 36e99ab6b74..a6e79680ff0 100644 --- a/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts +++ b/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts @@ -3,7 +3,6 @@ import { Factory } from 'fishery'; export const toolConfigurationStatusResponseFactory = Factory.define(() => { return { - isDisabled: false, isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, }; From 6312b9e4e8fec1472d7a15bdb30c793441228d1b Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Fri, 1 Dec 2023 09:52:19 +0100 Subject: [PATCH 12/19] N21-1494 refactoring --- .../controller/dto/tool-configuration-status.response.ts | 0 .../modules/tool/common/mapper/tool-status-response.mapper.ts | 2 +- .../modules/tool/context-external-tool/controller/dto/index.ts | 1 - .../controller/dto/tool-reference.response.ts | 2 +- 4 files changed, 2 insertions(+), 3 deletions(-) rename apps/server/src/modules/tool/{context-external-tool => common}/controller/dto/tool-configuration-status.response.ts (100%) diff --git a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-configuration-status.response.ts b/apps/server/src/modules/tool/common/controller/dto/tool-configuration-status.response.ts similarity index 100% rename from apps/server/src/modules/tool/context-external-tool/controller/dto/tool-configuration-status.response.ts rename to apps/server/src/modules/tool/common/controller/dto/tool-configuration-status.response.ts diff --git a/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts b/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts index 555818e5544..785eea8491c 100644 --- a/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts +++ b/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts @@ -1,4 +1,4 @@ -import { ToolConfigurationStatusResponse } from '../../context-external-tool/controller/dto'; +import { ToolConfigurationStatusResponse } from '../controller/dto/tool-configuration-status.response'; import { ToolConfigurationStatus } from '../domain'; export class ToolStatusResponseMapper { diff --git a/apps/server/src/modules/tool/context-external-tool/controller/dto/index.ts b/apps/server/src/modules/tool/context-external-tool/controller/dto/index.ts index e6da4bb909f..89922cda255 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/dto/index.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/dto/index.ts @@ -5,4 +5,3 @@ export * from './context-external-tool-context.params'; export * from './context-external-tool.response'; export * from './tool-reference-list.response'; export * from './tool-reference.response'; -export * from './tool-configuration-status.response'; diff --git a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts b/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts index a2a6f3b63e0..6efac3ec4cd 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts @@ -1,5 +1,5 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; -import { ToolConfigurationStatusResponse } from './tool-configuration-status.response'; +import { ToolConfigurationStatusResponse } from '../../../common/controller/dto/tool-configuration-status.response'; export class ToolReferenceResponse { @ApiProperty({ nullable: false, required: true, description: 'The id of the tool in the context' }) From 7135aed9644359a84b9f24b63ec7b4abb27baad2 Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Fri, 1 Dec 2023 10:00:01 +0100 Subject: [PATCH 13/19] N21-1494 fix import --- .../factory/tool-configuration-status-response.factory.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts b/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts index a6e79680ff0..15c5d7b0ec0 100644 --- a/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts +++ b/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts @@ -1,4 +1,4 @@ -import { ToolConfigurationStatusResponse } from '@modules/tool/context-external-tool/controller/dto'; +import { ToolConfigurationStatusResponse } from '@modules/tool/common/controller/dto/tool-configuration-status.response'; import { Factory } from 'fishery'; export const toolConfigurationStatusResponseFactory = Factory.define(() => { From 08caca4857598935c98d73aa06fa9a680635f1cc Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Fri, 1 Dec 2023 11:13:13 +0100 Subject: [PATCH 14/19] N21-1494 fix import --- .../controller/api-test/tool-reference.api.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts b/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts index 80f5ac3f0dd..0b6380b5842 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts @@ -14,7 +14,7 @@ import { schoolExternalToolEntityFactory, schoolFactory, } from '@shared/testing'; -import { ServerTestModule } from '@modules/server'; + import { toolConfigurationStatusResponseFactory } from '@shared/testing/factory/tool-configuration-status-response.factory'; import { Response } from 'supertest'; import { ToolContextType } from '../../../common/enum'; From 17cd00448f9aaf6bfbb454d9fcc3c75dc78a39c6 Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Fri, 1 Dec 2023 11:58:42 +0100 Subject: [PATCH 15/19] N21-1494 fix cy data --- backup/setup/external-tools.json | 12 ++++++------ backup/setup/school-external-tools.json | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/backup/setup/external-tools.json b/backup/setup/external-tools.json index 98a893c3938..4fb8e52c042 100644 --- a/backup/setup/external-tools.json +++ b/backup/setup/external-tools.json @@ -102,7 +102,7 @@ }, { "_id": { - "$oid": "647de247cf6a427b9d39e5b10" + "$oid": "647de247cf6a427b9d39e5b1" }, "createdAt": { "$date": "2023-11-30T12:37:54.977Z" @@ -110,7 +110,7 @@ "updatedAt": { "$date": "2023-11-30T15:31:47.749Z" }, - "name": "Cypress Test Tool School Scope", + "name": "Cy Test Tool School Scope", "config_type": "basic", "config_baseUrl": "http:google.com", "parameters": [{ @@ -128,7 +128,7 @@ }, { "_id": { - "$oid": "647de247cf6a427b9d39e5b11" + "$oid": "647de247cf6a427b9d39e5c2" }, "createdAt": { "$date": "2023-11-30T12:40:29.049Z" @@ -136,7 +136,7 @@ "updatedAt": { "$date": "2023-11-30T15:32:05.991Z" }, - "name": "Cypress Test Tool Context Scope", + "name": "CY Test Tool Context Scope", "config_type": "basic", "config_baseUrl": "https:google.com", "parameters": [{ @@ -154,7 +154,7 @@ }, { "_id": { - "$oid": "647de247cf6a427b9d39e5b12" + "$oid": "647de247cf6a427b9d39e5c3" }, "createdAt": { "$date": "2023-11-30T15:28:04.733Z" @@ -162,7 +162,7 @@ "updatedAt": { "$date": "2023-11-30T15:32:42.888Z" }, - "name": "Cypress Test Tool School and Context Scope", + "name": "CY Test Tool School and Context Scope", "config_type": "basic", "config_baseUrl": "https:google.com", "parameters": [{ diff --git a/backup/setup/school-external-tools.json b/backup/setup/school-external-tools.json index d222f0b9292..2cc88dddd05 100644 --- a/backup/setup/school-external-tools.json +++ b/backup/setup/school-external-tools.json @@ -80,7 +80,7 @@ "$date": "2023-11-30T15:23:31.370Z" }, "tool": { - "$oid": "647de247cf6a427b9d39e5b10" + "$oid": "647de247cf6a427b9d39e5b1" }, "school": { "$oid": "5f2987e020834114b8efd6f8" @@ -102,7 +102,7 @@ "$date": "2023-11-30T15:23:45.423Z" }, "tool": { - "$oid": "647de247cf6a427b9d39e5b11" + "$oid": "647de247cf6a427b9d39e5c2" }, "school": { "$oid": "5f2987e020834114b8efd6f8" @@ -121,7 +121,7 @@ "$date": "2023-11-30T15:29:00.061Z" }, "tool": { - "$oid": "647de247cf6a427b9d39e5b12" + "$oid": "647de247cf6a427b9d39e5c3" }, "school": { "$oid": "5f2987e020834114b8efd6f8" From 169ee5034162fe9b14bf65e0037e468a991a63b7 Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Mon, 4 Dec 2023 08:04:41 +0100 Subject: [PATCH 16/19] N21-1494 review changes --- ...ternal-tool-configuration-status.response.ts} | 4 ++-- .../modules/tool/common/controller/dto/index.ts | 1 + ...ontext-external-tool-configuration-status.ts} | 4 ++-- .../src/modules/tool/common/domain/index.ts | 2 +- .../common/mapper/tool-status-response.mapper.ts | 15 ++++++++------- .../common/service/common-tool.service.spec.ts | 16 ++++++++-------- .../tool/common/service/common-tool.service.ts | 6 +++--- .../api-test/tool-reference.api.spec.ts | 6 +++--- .../controller/dto/tool-reference.response.ts | 6 +++--- .../domain/tool-reference.ts | 4 ++-- .../mapper/tool-reference.mapper.ts | 4 ++-- .../service/tool-reference.service.ts | 13 +++++++------ .../service/tool-version-service.spec.ts | 10 +++++----- .../service/tool-version-service.ts | 8 ++++---- .../school-external-tool-configuration-status.ts | 4 ++-- ...chool-external-tool-configuration.response.ts | 4 ++-- .../dto/school-external-tool.response.ts | 6 +++--- .../domain/school-external-tool.do.ts | 6 +++--- ...chool-external-tool-status-response.mapper.ts | 13 +++++++------ .../service/school-external-tool.service.spec.ts | 4 ++-- .../service/school-external-tool.service.ts | 8 ++++---- .../tool-launch/service/tool-launch.service.ts | 13 +++++++------ ...tool-configuration-status-response.factory.ts | 10 ++++++++++ ...external-tool-configuration-status.factory.ts | 4 ++-- .../tool/tool-configuration-status.factory.ts | 4 ++-- apps/server/src/shared/testing/factory/index.ts | 2 +- ...tool-configuration-status-response.factory.ts | 9 ++++----- ...tool-configuration-status-response.factory.ts | 9 --------- 28 files changed, 100 insertions(+), 95 deletions(-) rename apps/server/src/modules/tool/common/controller/dto/{tool-configuration-status.response.ts => context-external-tool-configuration-status.response.ts} (82%) rename apps/server/src/modules/tool/common/domain/{tool-configuration-status.ts => context-external-tool-configuration-status.ts} (64%) create mode 100644 apps/server/src/shared/testing/factory/context-external-tool-configuration-status-response.factory.ts delete mode 100644 apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts diff --git a/apps/server/src/modules/tool/common/controller/dto/tool-configuration-status.response.ts b/apps/server/src/modules/tool/common/controller/dto/context-external-tool-configuration-status.response.ts similarity index 82% rename from apps/server/src/modules/tool/common/controller/dto/tool-configuration-status.response.ts rename to apps/server/src/modules/tool/common/controller/dto/context-external-tool-configuration-status.response.ts index 760bb41e40e..ca64669c166 100644 --- a/apps/server/src/modules/tool/common/controller/dto/tool-configuration-status.response.ts +++ b/apps/server/src/modules/tool/common/controller/dto/context-external-tool-configuration-status.response.ts @@ -1,6 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; -export class ToolConfigurationStatusResponse { +export class ContextExternalToolConfigurationStatusResponse { @ApiProperty({ type: Boolean, description: @@ -15,7 +15,7 @@ export class ToolConfigurationStatusResponse { }) isOutdatedOnScopeContext: boolean; - constructor(props: ToolConfigurationStatusResponse) { + constructor(props: ContextExternalToolConfigurationStatusResponse) { this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool; this.isOutdatedOnScopeContext = props.isOutdatedOnScopeContext; } diff --git a/apps/server/src/modules/tool/common/controller/dto/index.ts b/apps/server/src/modules/tool/common/controller/dto/index.ts index 87fa450d468..e4f13ca8151 100644 --- a/apps/server/src/modules/tool/common/controller/dto/index.ts +++ b/apps/server/src/modules/tool/common/controller/dto/index.ts @@ -1 +1,2 @@ export { ContextExternalToolCountPerContextResponse } from './context-external-tool-count-per-context.response'; +export { ContextExternalToolConfigurationStatusResponse } from './context-external-tool-configuration-status.response'; diff --git a/apps/server/src/modules/tool/common/domain/tool-configuration-status.ts b/apps/server/src/modules/tool/common/domain/context-external-tool-configuration-status.ts similarity index 64% rename from apps/server/src/modules/tool/common/domain/tool-configuration-status.ts rename to apps/server/src/modules/tool/common/domain/context-external-tool-configuration-status.ts index 507b2c84650..be533e50212 100644 --- a/apps/server/src/modules/tool/common/domain/tool-configuration-status.ts +++ b/apps/server/src/modules/tool/common/domain/context-external-tool-configuration-status.ts @@ -1,9 +1,9 @@ -export class ToolConfigurationStatus { +export class ContextExternalToolConfigurationStatus { isOutdatedOnScopeSchool: boolean; isOutdatedOnScopeContext: boolean; - constructor(props: ToolConfigurationStatus) { + constructor(props: ContextExternalToolConfigurationStatus) { this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool; this.isOutdatedOnScopeContext = props.isOutdatedOnScopeContext; } diff --git a/apps/server/src/modules/tool/common/domain/index.ts b/apps/server/src/modules/tool/common/domain/index.ts index 155961be0d3..27dd13a3fb5 100644 --- a/apps/server/src/modules/tool/common/domain/index.ts +++ b/apps/server/src/modules/tool/common/domain/index.ts @@ -1,3 +1,3 @@ export * from './custom-parameter.do'; export * from './custom-parameter-entry.do'; -export * from './tool-configuration-status'; +export * from './context-external-tool-configuration-status'; diff --git a/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts b/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts index 785eea8491c..7e75fdd81ae 100644 --- a/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts +++ b/apps/server/src/modules/tool/common/mapper/tool-status-response.mapper.ts @@ -1,12 +1,13 @@ -import { ToolConfigurationStatusResponse } from '../controller/dto/tool-configuration-status.response'; -import { ToolConfigurationStatus } from '../domain'; +import { ContextExternalToolConfigurationStatusResponse } from '../controller/dto'; +import { ContextExternalToolConfigurationStatus } from '../domain'; export class ToolStatusResponseMapper { - static mapToResponse(status: ToolConfigurationStatus): ToolConfigurationStatusResponse { - const configurationStatus: ToolConfigurationStatusResponse = new ToolConfigurationStatusResponse({ - isOutdatedOnScopeSchool: status.isOutdatedOnScopeSchool, - isOutdatedOnScopeContext: status.isOutdatedOnScopeContext, - }); + static mapToResponse(status: ContextExternalToolConfigurationStatus): ContextExternalToolConfigurationStatusResponse { + const configurationStatus: ContextExternalToolConfigurationStatusResponse = + new ContextExternalToolConfigurationStatusResponse({ + isOutdatedOnScopeSchool: status.isOutdatedOnScopeSchool, + isOutdatedOnScopeContext: status.isOutdatedOnScopeContext, + }); return configurationStatus; } diff --git a/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts b/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts index f5b02be9ca3..c8bc6c8bc70 100644 --- a/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts +++ b/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts @@ -9,7 +9,7 @@ import { CommonToolService } from './common-tool.service'; import { ExternalTool } from '../../external-tool/domain'; import { SchoolExternalTool } from '../../school-external-tool/domain'; import { ToolContextType } from '../enum'; -import { ToolConfigurationStatus } from '../domain'; +import { ContextExternalToolConfigurationStatus } from '../domain'; import { ContextExternalTool } from '../../context-external-tool/domain'; describe('CommonToolService', () => { @@ -45,7 +45,7 @@ describe('CommonToolService', () => { it('should return a configuration status with latest true', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); - const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( + const result: ContextExternalToolConfigurationStatus = service.determineToolConfigurationStatus( externalTool, schoolExternalTool, contextExternalTool @@ -76,7 +76,7 @@ describe('CommonToolService', () => { it('should return outdated status for school level', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); - const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( + const result: ContextExternalToolConfigurationStatus = service.determineToolConfigurationStatus( externalTool, schoolExternalTool, contextExternalTool @@ -107,7 +107,7 @@ describe('CommonToolService', () => { it('should return outdated status for context level', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); - const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( + const result: ContextExternalToolConfigurationStatus = service.determineToolConfigurationStatus( externalTool, schoolExternalTool, contextExternalTool @@ -138,7 +138,7 @@ describe('CommonToolService', () => { it('should return outdated status for context and school level', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); - const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( + const result: ContextExternalToolConfigurationStatus = service.determineToolConfigurationStatus( externalTool, schoolExternalTool, contextExternalTool @@ -169,7 +169,7 @@ describe('CommonToolService', () => { it('should return a configuration status with latest true', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); - const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( + const result: ContextExternalToolConfigurationStatus = service.determineToolConfigurationStatus( externalTool, schoolExternalTool, contextExternalTool @@ -200,7 +200,7 @@ describe('CommonToolService', () => { it('should return a configuration status with latest true', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); - const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( + const result: ContextExternalToolConfigurationStatus = service.determineToolConfigurationStatus( externalTool, schoolExternalTool, contextExternalTool @@ -231,7 +231,7 @@ describe('CommonToolService', () => { it('should return a configuration status with latest true', () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); - const result: ToolConfigurationStatus = service.determineToolConfigurationStatus( + const result: ContextExternalToolConfigurationStatus = service.determineToolConfigurationStatus( externalTool, schoolExternalTool, contextExternalTool diff --git a/apps/server/src/modules/tool/common/service/common-tool.service.ts b/apps/server/src/modules/tool/common/service/common-tool.service.ts index fca5933e4a4..e002d82d973 100644 --- a/apps/server/src/modules/tool/common/service/common-tool.service.ts +++ b/apps/server/src/modules/tool/common/service/common-tool.service.ts @@ -3,7 +3,7 @@ import { ExternalTool } from '../../external-tool/domain'; import { SchoolExternalTool } from '../../school-external-tool/domain'; import { ContextExternalTool } from '../../context-external-tool/domain'; import { ToolContextType } from '../enum'; -import { ToolConfigurationStatus } from '../domain'; +import { ContextExternalToolConfigurationStatus } from '../domain'; import { ToolVersion } from '../interface'; // TODO N21-1337 remove class when tool versioning is removed @@ -16,8 +16,8 @@ export class CommonToolService { externalTool: ExternalTool, schoolExternalTool: SchoolExternalTool, contextExternalTool: ContextExternalTool - ): ToolConfigurationStatus { - const configurationStatus: ToolConfigurationStatus = new ToolConfigurationStatus({ + ): ContextExternalToolConfigurationStatus { + const configurationStatus: ContextExternalToolConfigurationStatus = new ContextExternalToolConfigurationStatus({ isOutdatedOnScopeContext: true, isOutdatedOnScopeSchool: true, }); diff --git a/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts b/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts index f853774bedb..cda96bd03e0 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts @@ -16,7 +16,7 @@ import { schoolFactory, } from '@shared/testing'; -import { toolConfigurationStatusResponseFactory } from '@shared/testing/factory/tool-configuration-status-response.factory'; +import { contextExternalToolConfigurationStatusResponseFactory } from '@shared/testing/factory/context-external-tool-configuration-status-response.factory'; import { Response } from 'supertest'; import { CustomParameterLocation, CustomParameterScope, ToolContextType } from '../../../common/enum'; import { ExternalToolEntity } from '../../../external-tool/entity'; @@ -175,7 +175,7 @@ describe('ToolReferenceController (API)', () => { { contextToolId: contextExternalToolEntity.id, displayName: contextExternalToolEntity.displayName as string, - status: toolConfigurationStatusResponseFactory.build({ + status: contextExternalToolConfigurationStatusResponseFactory.build({ isOutdatedOnScopeSchool: false, isOutdatedOnScopeContext: false, }), @@ -307,7 +307,7 @@ describe('ToolReferenceController (API)', () => { expect(response.body).toEqual({ contextToolId: contextExternalToolEntity.id, displayName: contextExternalToolEntity.displayName as string, - status: toolConfigurationStatusResponseFactory.build({ + status: contextExternalToolConfigurationStatusResponseFactory.build({ isOutdatedOnScopeSchool: false, isOutdatedOnScopeContext: false, }), diff --git a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts b/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts index 6efac3ec4cd..91c945cbf91 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts @@ -1,5 +1,5 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; -import { ToolConfigurationStatusResponse } from '../../../common/controller/dto/tool-configuration-status.response'; +import { ContextExternalToolConfigurationStatusResponse } from '../../../common/controller/dto/context-external-tool-configuration-status.response'; export class ToolReferenceResponse { @ApiProperty({ nullable: false, required: true, description: 'The id of the tool in the context' }) @@ -19,12 +19,12 @@ export class ToolReferenceResponse { openInNewTab: boolean; @ApiProperty({ - type: ToolConfigurationStatusResponse, + type: ContextExternalToolConfigurationStatusResponse, nullable: false, required: true, description: 'The status of the tool', }) - status: ToolConfigurationStatusResponse; + status: ContextExternalToolConfigurationStatusResponse; constructor(toolReferenceResponse: ToolReferenceResponse) { this.contextToolId = toolReferenceResponse.contextToolId; diff --git a/apps/server/src/modules/tool/context-external-tool/domain/tool-reference.ts b/apps/server/src/modules/tool/context-external-tool/domain/tool-reference.ts index 296c359818d..9089e3596b3 100644 --- a/apps/server/src/modules/tool/context-external-tool/domain/tool-reference.ts +++ b/apps/server/src/modules/tool/context-external-tool/domain/tool-reference.ts @@ -1,4 +1,4 @@ -import { ToolConfigurationStatus } from '../../common/domain'; +import { ContextExternalToolConfigurationStatus } from '../../common/domain'; export class ToolReference { contextToolId: string; @@ -9,7 +9,7 @@ export class ToolReference { openInNewTab: boolean; - status: ToolConfigurationStatus; + status: ContextExternalToolConfigurationStatus; constructor(toolReference: ToolReference) { this.contextToolId = toolReference.contextToolId; diff --git a/apps/server/src/modules/tool/context-external-tool/mapper/tool-reference.mapper.ts b/apps/server/src/modules/tool/context-external-tool/mapper/tool-reference.mapper.ts index 58c35fbb7be..391a4a056bb 100644 --- a/apps/server/src/modules/tool/context-external-tool/mapper/tool-reference.mapper.ts +++ b/apps/server/src/modules/tool/context-external-tool/mapper/tool-reference.mapper.ts @@ -1,4 +1,4 @@ -import { ToolConfigurationStatus } from '../../common/domain'; +import { ContextExternalToolConfigurationStatus } from '../../common/domain'; import { ExternalTool } from '../../external-tool/domain'; import { ContextExternalTool, ToolReference } from '../domain'; @@ -6,7 +6,7 @@ export class ToolReferenceMapper { static mapToToolReference( externalTool: ExternalTool, contextExternalTool: ContextExternalTool, - status: ToolConfigurationStatus + status: ContextExternalToolConfigurationStatus ): ToolReference { const toolReference = new ToolReference({ contextToolId: contextExternalTool.id ?? '', diff --git a/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.ts b/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.ts index b62dfbb96d1..39894db0aa1 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/tool-reference.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common'; import { EntityId } from '@shared/domain/types'; import { ExternalTool } from '../../external-tool/domain'; import { ExternalToolLogoService, ExternalToolService } from '../../external-tool/service'; -import { ToolConfigurationStatus } from '../../common/domain'; +import { ContextExternalToolConfigurationStatus } from '../../common/domain'; import { SchoolExternalTool } from '../../school-external-tool/domain'; import { SchoolExternalToolService } from '../../school-external-tool/service'; import { ContextExternalTool, ToolReference } from '../domain'; @@ -29,11 +29,12 @@ export class ToolReferenceService { ); const externalTool: ExternalTool = await this.externalToolService.findById(schoolExternalTool.toolId); - const status: ToolConfigurationStatus = await this.toolVersionService.determineToolConfigurationStatus( - externalTool, - schoolExternalTool, - contextExternalTool - ); + const status: ContextExternalToolConfigurationStatus = + await this.toolVersionService.determineToolConfigurationStatus( + externalTool, + schoolExternalTool, + contextExternalTool + ); const toolReference: ToolReference = ToolReferenceMapper.mapToToolReference( externalTool, diff --git a/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts b/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts index c992cd4ee91..7edeca8459e 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts @@ -7,7 +7,7 @@ import { schoolExternalToolFactory, toolConfigurationStatusFactory, } from '@shared/testing'; -import { ToolConfigurationStatus } from '../../common/domain'; +import { ContextExternalToolConfigurationStatus } from '../../common/domain'; import { CommonToolService } from '../../common/service'; import { SchoolExternalToolValidationService } from '../../school-external-tool/service'; import { IToolFeatures, ToolFeatures } from '../../tool-config'; @@ -121,7 +121,7 @@ describe('ToolVersionService', () => { it('should return latest tool status', async () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); - const status: ToolConfigurationStatus = await service.determineToolConfigurationStatus( + const status: ContextExternalToolConfigurationStatus = await service.determineToolConfigurationStatus( externalTool, schoolExternalTool, contextExternalTool @@ -177,7 +177,7 @@ describe('ToolVersionService', () => { it('should return outdated tool status', async () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); - const status: ToolConfigurationStatus = await service.determineToolConfigurationStatus( + const status: ContextExternalToolConfigurationStatus = await service.determineToolConfigurationStatus( externalTool, schoolExternalTool, contextExternalTool @@ -233,7 +233,7 @@ describe('ToolVersionService', () => { it('should return outdated tool status', async () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); - const status: ToolConfigurationStatus = await service.determineToolConfigurationStatus( + const status: ContextExternalToolConfigurationStatus = await service.determineToolConfigurationStatus( externalTool, schoolExternalTool, contextExternalTool @@ -289,7 +289,7 @@ describe('ToolVersionService', () => { it('should return outdated tool status', async () => { const { externalTool, schoolExternalTool, contextExternalTool } = setup(); - const status: ToolConfigurationStatus = await service.determineToolConfigurationStatus( + const status: ContextExternalToolConfigurationStatus = await service.determineToolConfigurationStatus( externalTool, schoolExternalTool, contextExternalTool diff --git a/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts b/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts index bcc0dea40f0..191e1d0cc77 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts @@ -1,6 +1,6 @@ import { Inject } from '@nestjs/common'; import { Injectable } from '@nestjs/common/decorators/core/injectable.decorator'; -import { ToolConfigurationStatus } from '../../common/domain'; +import { ContextExternalToolConfigurationStatus } from '../../common/domain'; import { CommonToolService } from '../../common/service'; import { ExternalTool } from '../../external-tool/domain'; import { SchoolExternalTool } from '../../school-external-tool/domain'; @@ -22,10 +22,10 @@ export class ToolVersionService { externalTool: ExternalTool, schoolExternalTool: SchoolExternalTool, contextExternalTool: ContextExternalTool - ): Promise { + ): Promise { // TODO N21-1337 remove if statement, when feature flag is removed if (this.toolFeatures.toolStatusWithoutVersions) { - const configurationStatus: ToolConfigurationStatus = new ToolConfigurationStatus({ + const configurationStatus: ContextExternalToolConfigurationStatus = new ContextExternalToolConfigurationStatus({ isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, }); @@ -44,7 +44,7 @@ export class ToolVersionService { return configurationStatus; } - const status: ToolConfigurationStatus = this.commonToolService.determineToolConfigurationStatus( + const status: ContextExternalToolConfigurationStatus = this.commonToolService.determineToolConfigurationStatus( externalTool, schoolExternalTool, contextExternalTool diff --git a/apps/server/src/modules/tool/school-external-tool/controller/domain/school-external-tool-configuration-status.ts b/apps/server/src/modules/tool/school-external-tool/controller/domain/school-external-tool-configuration-status.ts index d9c05434274..8e86a8894e2 100644 --- a/apps/server/src/modules/tool/school-external-tool/controller/domain/school-external-tool-configuration-status.ts +++ b/apps/server/src/modules/tool/school-external-tool/controller/domain/school-external-tool-configuration-status.ts @@ -1,7 +1,7 @@ -export class SchoolToolConfigurationStatus { +export class SchoolExternalToolConfigurationStatus { isOutdatedOnScopeSchool: boolean; - constructor(props: SchoolToolConfigurationStatus) { + constructor(props: SchoolExternalToolConfigurationStatus) { this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool; } } diff --git a/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool-configuration.response.ts b/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool-configuration.response.ts index 665bf1f345e..b8bfe811f83 100644 --- a/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool-configuration.response.ts +++ b/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool-configuration.response.ts @@ -1,6 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; -export class SchoolToolConfigurationStatusResponse { +export class SchoolExternalToolConfigurationStatusResponse { @ApiProperty({ type: Boolean, description: @@ -8,7 +8,7 @@ export class SchoolToolConfigurationStatusResponse { }) isOutdatedOnScopeSchool: boolean; - constructor(props: SchoolToolConfigurationStatusResponse) { + constructor(props: SchoolExternalToolConfigurationStatusResponse) { this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool; } } diff --git a/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool.response.ts b/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool.response.ts index cc4be437f54..5d86bdcd186 100644 --- a/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool.response.ts +++ b/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool.response.ts @@ -1,6 +1,6 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; import { CustomParameterEntryResponse } from './custom-parameter-entry.response'; -import { SchoolToolConfigurationStatusResponse } from './school-external-tool-configuration.response'; +import { SchoolExternalToolConfigurationStatusResponse } from './school-external-tool-configuration.response'; export class SchoolExternalToolResponse { @ApiProperty() @@ -21,8 +21,8 @@ export class SchoolExternalToolResponse { @ApiProperty() toolVersion: number; - @ApiProperty({ type: SchoolToolConfigurationStatusResponse }) - status: SchoolToolConfigurationStatusResponse; + @ApiProperty({ type: SchoolExternalToolConfigurationStatusResponse }) + status: SchoolExternalToolConfigurationStatusResponse; @ApiPropertyOptional() logoUrl?: string; diff --git a/apps/server/src/modules/tool/school-external-tool/domain/school-external-tool.do.ts b/apps/server/src/modules/tool/school-external-tool/domain/school-external-tool.do.ts index 37eaa4d1daf..9fc769f6673 100644 --- a/apps/server/src/modules/tool/school-external-tool/domain/school-external-tool.do.ts +++ b/apps/server/src/modules/tool/school-external-tool/domain/school-external-tool.do.ts @@ -1,7 +1,7 @@ import { BaseDO } from '@shared/domain/domainobject/base.do'; import { CustomParameterEntry } from '../../common/domain'; import { ToolVersion } from '../../common/interface'; -import { SchoolToolConfigurationStatus } from '../controller/dto'; +import { SchoolExternalToolConfigurationStatus } from '../controller/dto'; export interface SchoolExternalToolProps { id?: string; @@ -16,7 +16,7 @@ export interface SchoolExternalToolProps { toolVersion: number; - status?: SchoolToolConfigurationStatus; + status?: SchoolExternalToolConfigurationStatus; } export class SchoolExternalTool extends BaseDO implements ToolVersion { @@ -30,7 +30,7 @@ export class SchoolExternalTool extends BaseDO implements ToolVersion { toolVersion: number; - status?: SchoolToolConfigurationStatus; + status?: SchoolExternalToolConfigurationStatus; constructor(props: SchoolExternalToolProps) { super(props.id); diff --git a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-status-response.mapper.ts b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-status-response.mapper.ts index 18b3ae59e71..290ad5c084a 100644 --- a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-status-response.mapper.ts +++ b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-status-response.mapper.ts @@ -1,11 +1,12 @@ -import { SchoolToolConfigurationStatus } from '../controller/dto'; -import { SchoolToolConfigurationStatusResponse } from '../controller/dto/school-external-tool-configuration.response'; +import { SchoolExternalToolConfigurationStatus } from '../controller/dto'; +import { SchoolExternalToolConfigurationStatusResponse } from '../controller/dto/school-external-tool-configuration.response'; export class SchoolToolConfigurationStatusResponseMapper { - static mapToResponse(status: SchoolToolConfigurationStatus): SchoolToolConfigurationStatusResponse { - const configurationStatus: SchoolToolConfigurationStatusResponse = new SchoolToolConfigurationStatusResponse({ - isOutdatedOnScopeSchool: status.isOutdatedOnScopeSchool, - }); + static mapToResponse(status: SchoolExternalToolConfigurationStatus): SchoolExternalToolConfigurationStatusResponse { + const configurationStatus: SchoolExternalToolConfigurationStatusResponse = + new SchoolExternalToolConfigurationStatusResponse({ + isOutdatedOnScopeSchool: status.isOutdatedOnScopeSchool, + }); return configurationStatus; } diff --git a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts index 6d80eb3e91a..1f8e1527e05 100644 --- a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts +++ b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts @@ -8,7 +8,7 @@ import { schoolExternalToolFactory } from '@shared/testing/factory/domainobject/ import { ExternalTool } from '../../external-tool/domain'; import { ExternalToolService } from '../../external-tool/service'; import { IToolFeatures, ToolFeatures } from '../../tool-config'; -import { SchoolToolConfigurationStatus } from '../controller/domain/school-external-tool-configuration-status'; +import { SchoolExternalToolConfigurationStatus } from '../controller/domain/school-external-tool-configuration-status'; import { SchoolExternalTool } from '../domain'; import { SchoolExternalToolValidationService } from './school-external-tool-validation.service'; import { SchoolExternalToolService } from './school-external-tool.service'; @@ -113,7 +113,7 @@ describe('SchoolExternalToolService', () => { schoolExternalTool ); - expect(schoolExternalToolDOs[0].status).toEqual( + expect(schoolExternalToolDOs[0].status).toEqual( schoolToolConfigurationStatusFactory.build({ isOutdatedOnScopeSchool: true, }) diff --git a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts index 6ac785ae64f..b396147e72c 100644 --- a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts +++ b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.ts @@ -4,7 +4,7 @@ import { SchoolExternalToolRepo } from '@shared/repo'; import { ExternalTool } from '../../external-tool/domain'; import { ExternalToolService } from '../../external-tool/service'; import { IToolFeatures, ToolFeatures } from '../../tool-config'; -import { SchoolToolConfigurationStatus } from '../controller/dto'; +import { SchoolExternalToolConfigurationStatus } from '../controller/dto'; import { SchoolExternalTool } from '../domain'; import { SchoolExternalToolQuery } from '../uc/dto/school-external-tool.types'; import { SchoolExternalToolValidationService } from './school-external-tool-validation.service'; @@ -43,7 +43,7 @@ export class SchoolExternalToolService { private async enrichDataFromExternalTool(tool: SchoolExternalTool): Promise { const externalTool: ExternalTool = await this.externalToolService.findById(tool.toolId); - const status: SchoolToolConfigurationStatus = await this.determineSchoolToolStatus(tool, externalTool); + const status: SchoolExternalToolConfigurationStatus = await this.determineSchoolToolStatus(tool, externalTool); const schoolExternalTool: SchoolExternalTool = new SchoolExternalTool({ ...tool, status, @@ -56,8 +56,8 @@ export class SchoolExternalToolService { private async determineSchoolToolStatus( tool: SchoolExternalTool, externalTool: ExternalTool - ): Promise { - const status: SchoolToolConfigurationStatus = new SchoolToolConfigurationStatus({ + ): Promise { + const status: SchoolExternalToolConfigurationStatus = new SchoolExternalToolConfigurationStatus({ isOutdatedOnScopeSchool: true, }); diff --git a/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.ts b/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.ts index ab4837aac85..bb323017967 100644 --- a/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.ts +++ b/apps/server/src/modules/tool/tool-launch/service/tool-launch.service.ts @@ -1,6 +1,6 @@ import { Injectable, InternalServerErrorException } from '@nestjs/common'; import { EntityId } from '@shared/domain/types'; -import { ToolConfigurationStatus } from '../../common/domain'; +import { ContextExternalToolConfigurationStatus } from '../../common/domain'; import { ToolConfigType } from '../../common/enum'; import { ContextExternalTool } from '../../context-external-tool/domain'; import { ToolVersionService } from '../../context-external-tool/service/tool-version-service'; @@ -90,11 +90,12 @@ export class ToolLaunchService { schoolExternalTool: SchoolExternalTool, contextExternalTool: ContextExternalTool ): Promise { - const status: ToolConfigurationStatus = await this.toolVersionService.determineToolConfigurationStatus( - externalTool, - schoolExternalTool, - contextExternalTool - ); + const status: ContextExternalToolConfigurationStatus = + await this.toolVersionService.determineToolConfigurationStatus( + externalTool, + schoolExternalTool, + contextExternalTool + ); if (status.isOutdatedOnScopeSchool || status.isOutdatedOnScopeContext) { throw new ToolStatusOutdatedLoggableException( diff --git a/apps/server/src/shared/testing/factory/context-external-tool-configuration-status-response.factory.ts b/apps/server/src/shared/testing/factory/context-external-tool-configuration-status-response.factory.ts new file mode 100644 index 00000000000..a2e9ec6c2d2 --- /dev/null +++ b/apps/server/src/shared/testing/factory/context-external-tool-configuration-status-response.factory.ts @@ -0,0 +1,10 @@ +import { ContextExternalToolConfigurationStatusResponse } from '@modules/tool/common/controller/dto/context-external-tool-configuration-status.response'; +import { Factory } from 'fishery'; + +export const contextExternalToolConfigurationStatusResponseFactory = + Factory.define(() => { + return { + isOutdatedOnScopeContext: false, + isOutdatedOnScopeSchool: false, + }; + }); diff --git a/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool-configuration-status.factory.ts b/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool-configuration-status.factory.ts index 5d9655e4b8b..1153fa87da2 100644 --- a/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool-configuration-status.factory.ts +++ b/apps/server/src/shared/testing/factory/domainobject/tool/school-external-tool-configuration-status.factory.ts @@ -1,7 +1,7 @@ -import { SchoolToolConfigurationStatus } from '@modules/tool/school-external-tool/controller/dto'; +import { SchoolExternalToolConfigurationStatus } from '@modules/tool/school-external-tool/controller/dto'; import { Factory } from 'fishery'; -export const schoolToolConfigurationStatusFactory = Factory.define(() => { +export const schoolToolConfigurationStatusFactory = Factory.define(() => { return { isOutdatedOnScopeSchool: false, }; diff --git a/apps/server/src/shared/testing/factory/domainobject/tool/tool-configuration-status.factory.ts b/apps/server/src/shared/testing/factory/domainobject/tool/tool-configuration-status.factory.ts index a753572946a..e9d6e4f25d4 100644 --- a/apps/server/src/shared/testing/factory/domainobject/tool/tool-configuration-status.factory.ts +++ b/apps/server/src/shared/testing/factory/domainobject/tool/tool-configuration-status.factory.ts @@ -1,7 +1,7 @@ -import { ToolConfigurationStatus } from '@modules/tool/common/domain'; +import { ContextExternalToolConfigurationStatus } from '@modules/tool/common/domain'; import { Factory } from 'fishery'; -export const toolConfigurationStatusFactory = Factory.define(() => { +export const toolConfigurationStatusFactory = Factory.define(() => { return { isOutdatedOnScopeContext: false, isOutdatedOnScopeSchool: false, diff --git a/apps/server/src/shared/testing/factory/index.ts b/apps/server/src/shared/testing/factory/index.ts index 355be4c60ae..645dcb56445 100644 --- a/apps/server/src/shared/testing/factory/index.ts +++ b/apps/server/src/shared/testing/factory/index.ts @@ -41,5 +41,5 @@ export * from './legacy-file-entity-mock.factory'; export * from './jwt.test.factory'; export * from './axios-error.factory'; export { externalSchoolDtoFactory } from './external-school-dto.factory'; -export * from './tool-configuration-status-response.factory'; +export * from './context-external-tool-configuration-status-response.factory'; export * from './school-tool-configuration-status-response.factory'; diff --git a/apps/server/src/shared/testing/factory/school-tool-configuration-status-response.factory.ts b/apps/server/src/shared/testing/factory/school-tool-configuration-status-response.factory.ts index 9191d1732fd..6dabc2148c0 100644 --- a/apps/server/src/shared/testing/factory/school-tool-configuration-status-response.factory.ts +++ b/apps/server/src/shared/testing/factory/school-tool-configuration-status-response.factory.ts @@ -1,10 +1,9 @@ -import { SchoolToolConfigurationStatusResponse } from '@modules/tool/school-external-tool/controller/dto/school-external-tool-configuration.response'; +import { SchoolExternalToolConfigurationStatusResponse } from '@modules/tool/school-external-tool/controller/dto/school-external-tool-configuration.response'; import { Factory } from 'fishery'; -export const schoolToolConfigurationStatusResponseFactory = Factory.define( - () => { +export const schoolToolConfigurationStatusResponseFactory = + Factory.define(() => { return { isOutdatedOnScopeSchool: false, }; - } -); + }); diff --git a/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts b/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts deleted file mode 100644 index 15c5d7b0ec0..00000000000 --- a/apps/server/src/shared/testing/factory/tool-configuration-status-response.factory.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { ToolConfigurationStatusResponse } from '@modules/tool/common/controller/dto/tool-configuration-status.response'; -import { Factory } from 'fishery'; - -export const toolConfigurationStatusResponseFactory = Factory.define(() => { - return { - isOutdatedOnScopeContext: false, - isOutdatedOnScopeSchool: false, - }; -}); From bce9afe0576e9b41e1e3f05dae5d6eacfddc193a Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Mon, 4 Dec 2023 08:51:51 +0100 Subject: [PATCH 17/19] N21-1494 imports --- .../controller/api-test/tool-reference.api.spec.ts | 2 +- .../controller/dto/tool-reference.response.ts | 2 +- .../controller/api-test/tool-school.api.spec.ts | 2 +- .../mapper/school-external-tool-response.mapper.spec.ts | 9 ++++++--- .../service/school-external-tool.service.spec.ts | 8 +++++--- 5 files changed, 14 insertions(+), 9 deletions(-) diff --git a/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts b/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts index cda96bd03e0..11952df60bc 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/api-test/tool-reference.api.spec.ts @@ -14,9 +14,9 @@ import { externalToolEntityFactory, schoolExternalToolEntityFactory, schoolFactory, + contextExternalToolConfigurationStatusResponseFactory, } from '@shared/testing'; -import { contextExternalToolConfigurationStatusResponseFactory } from '@shared/testing/factory/context-external-tool-configuration-status-response.factory'; import { Response } from 'supertest'; import { CustomParameterLocation, CustomParameterScope, ToolContextType } from '../../../common/enum'; import { ExternalToolEntity } from '../../../external-tool/entity'; diff --git a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts b/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts index 91c945cbf91..a22eba809d1 100644 --- a/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts +++ b/apps/server/src/modules/tool/context-external-tool/controller/dto/tool-reference.response.ts @@ -1,5 +1,5 @@ import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; -import { ContextExternalToolConfigurationStatusResponse } from '../../../common/controller/dto/context-external-tool-configuration-status.response'; +import { ContextExternalToolConfigurationStatusResponse } from '../../../common/controller/dto'; export class ToolReferenceResponse { @ApiProperty({ nullable: false, required: true, description: 'The id of the tool in the context' }) diff --git a/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts b/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts index 945c60d6399..8f7f13c1d13 100644 --- a/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts +++ b/apps/server/src/modules/tool/school-external-tool/controller/api-test/tool-school.api.spec.ts @@ -16,7 +16,7 @@ import { schoolFactory, userFactory, } from '@shared/testing'; -import { schoolToolConfigurationStatusFactory } from '@shared/testing/factory/domainobject/tool/school-external-tool-configuration-status.factory'; +import { schoolToolConfigurationStatusFactory } from '@shared/testing/factory'; import { ContextExternalToolEntity, ContextExternalToolType } from '../../../context-external-tool/entity'; import { CustomParameterScope, CustomParameterType, ExternalToolEntity } from '../../../external-tool/entity'; import { SchoolExternalToolEntity } from '../../entity'; diff --git a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts index b9d5480b030..eb2e0da2fe5 100644 --- a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts +++ b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-response.mapper.spec.ts @@ -1,6 +1,9 @@ -import { schoolExternalToolFactory } from '@shared/testing/factory'; -import { schoolToolConfigurationStatusFactory } from '@shared/testing/factory/domainobject/tool/school-external-tool-configuration-status.factory'; -import { schoolToolConfigurationStatusResponseFactory } from '@shared/testing/factory/school-tool-configuration-status-response.factory'; +import { + schoolExternalToolFactory, + schoolToolConfigurationStatusFactory, + schoolToolConfigurationStatusResponseFactory, +} from '@shared/testing/factory'; + import { SchoolExternalToolResponse, SchoolExternalToolSearchListResponse } from '../controller/dto'; import { SchoolExternalTool } from '../domain'; import { SchoolExternalToolResponseMapper } from './school-external-tool-response.mapper'; diff --git a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts index 1f8e1527e05..43875b3d55c 100644 --- a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts +++ b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool.service.spec.ts @@ -2,9 +2,11 @@ import { createMock, DeepMocked } from '@golevelup/ts-jest'; import { Test, TestingModule } from '@nestjs/testing'; import { ApiValidationError } from '@shared/common'; import { SchoolExternalToolRepo } from '@shared/repo'; -import { externalToolFactory } from '@shared/testing/factory/domainobject/tool/external-tool.factory'; -import { schoolToolConfigurationStatusFactory } from '@shared/testing/factory/domainobject/tool/school-external-tool-configuration-status.factory'; -import { schoolExternalToolFactory } from '@shared/testing/factory/domainobject/tool/school-external-tool.factory'; +import { + schoolExternalToolFactory, + schoolToolConfigurationStatusFactory, + externalToolFactory, +} from '@shared/testing/factory'; import { ExternalTool } from '../../external-tool/domain'; import { ExternalToolService } from '../../external-tool/service'; import { IToolFeatures, ToolFeatures } from '../../tool-config'; From df4ccb5ebf514347dc3c89737f57344fd2d74629 Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Mon, 4 Dec 2023 11:57:12 +0100 Subject: [PATCH 18/19] N21-1494 cy seed data --- backup/setup/context-external-tools.json | 6 +++--- backup/setup/school-external-tools.json | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backup/setup/context-external-tools.json b/backup/setup/context-external-tools.json index d3328e572cb..239539c14e9 100644 --- a/backup/setup/context-external-tools.json +++ b/backup/setup/context-external-tools.json @@ -48,7 +48,7 @@ "schoolTool": { "$oid": "647de374cf6a427b9d39e5bc" }, - "contextId": "0000dcfbfb5c7a3f00bf21ab", + "contextId": "5fa3a2f3a9c31a26f4d1d309", "contextType": "course", "displayName": "Cypress Test Tool School Scope", "parameters": [], @@ -67,7 +67,7 @@ "schoolTool": { "$oid": "647de374cf6a427b9d39e5bd" }, - "contextId": "0000dcfbfb5c7a3f00bf21ab", + "contextId": "5fa3a2f3a9c31a26f4d1d309", "contextType": "course", "displayName": "Cypress Test Tool Context Scope", "parameters": [{ @@ -89,7 +89,7 @@ "schoolTool": { "$oid": "647de374cf6a427b9d39e5be" }, - "contextId": "0000dcfbfb5c7a3f00bf21ab", + "contextId": "5fa3a2f3a9c31a26f4d1d309", "contextType": "course", "displayName": "Cypress Test Tool School and Context Scope", "parameters": [{ diff --git a/backup/setup/school-external-tools.json b/backup/setup/school-external-tools.json index 28e2d25eedb..6c39fd86c0a 100644 --- a/backup/setup/school-external-tools.json +++ b/backup/setup/school-external-tools.json @@ -106,7 +106,7 @@ "$oid": "647de247cf6a427b9d39e5b1" }, "school": { - "$oid": "5f2987e020834114b8efd6f8" + "$oid": "5fa2c5ccb229544f2c69666c" }, "schoolParameters": [{ "name": "search", @@ -128,7 +128,7 @@ "$oid": "647de247cf6a427b9d39e5c2" }, "school": { - "$oid": "5f2987e020834114b8efd6f8" + "$oid": "5fa2c5ccb229544f2c69666c" }, "schoolParameters": [], "toolVersion": 1 @@ -147,7 +147,7 @@ "$oid": "647de247cf6a427b9d39e5c3" }, "school": { - "$oid": "5f2987e020834114b8efd6f8" + "$oid": "5fa2c5ccb229544f2c69666c" }, "schoolParameters": [{ "name": "schoolParan", From 29da5c2525f0feb201117ac369664fe6f268dca9 Mon Sep 17 00:00:00 2001 From: Mrika Llabani Date: Mon, 4 Dec 2023 14:07:53 +0100 Subject: [PATCH 19/19] N21-1494 fix deprecated code --- .../common/service/common-tool.service.spec.ts | 6 +++--- .../tool/common/service/common-tool.service.ts | 14 ++++++-------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts b/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts index c8bc6c8bc70..cabd791a766 100644 --- a/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts +++ b/apps/server/src/modules/tool/common/service/common-tool.service.spec.ts @@ -84,7 +84,7 @@ describe('CommonToolService', () => { expect(result).toEqual( toolConfigurationStatusFactory.build({ - isOutdatedOnScopeContext: false, + isOutdatedOnScopeContext: true, isOutdatedOnScopeSchool: true, }) ); @@ -116,7 +116,7 @@ describe('CommonToolService', () => { expect(result).toEqual( toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: true, - isOutdatedOnScopeSchool: false, + isOutdatedOnScopeSchool: true, }) ); }); @@ -147,7 +147,7 @@ describe('CommonToolService', () => { expect(result).toEqual( toolConfigurationStatusFactory.build({ isOutdatedOnScopeContext: true, - isOutdatedOnScopeSchool: false, + isOutdatedOnScopeSchool: true, }) ); }); diff --git a/apps/server/src/modules/tool/common/service/common-tool.service.ts b/apps/server/src/modules/tool/common/service/common-tool.service.ts index e002d82d973..b1c8d0e8da2 100644 --- a/apps/server/src/modules/tool/common/service/common-tool.service.ts +++ b/apps/server/src/modules/tool/common/service/common-tool.service.ts @@ -22,18 +22,16 @@ export class CommonToolService { isOutdatedOnScopeSchool: true, }); - if (!this.isLatest(schoolExternalTool, externalTool)) { + if ( + this.isLatest(schoolExternalTool, externalTool) && + this.isLatest(contextExternalTool, schoolExternalTool) && + this.isLatest(contextExternalTool, externalTool) + ) { configurationStatus.isOutdatedOnScopeContext = false; - configurationStatus.isOutdatedOnScopeSchool = true; - } else if (!this.isLatest(contextExternalTool, schoolExternalTool)) { - configurationStatus.isOutdatedOnScopeContext = true; configurationStatus.isOutdatedOnScopeSchool = false; - } else if (!this.isLatest(contextExternalTool, externalTool)) { + } else { configurationStatus.isOutdatedOnScopeContext = true; configurationStatus.isOutdatedOnScopeSchool = true; - } else { - configurationStatus.isOutdatedOnScopeContext = false; - configurationStatus.isOutdatedOnScopeSchool = false; } return configurationStatus;