-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into BC-5522-impl-of-deletion-api
- Loading branch information
Showing
24 changed files
with
496 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
apps/server/src/modules/tool/context-external-tool/service/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export * from './context-external-tool.service'; | ||
export * from './context-external-tool-validation.service'; | ||
export * from './context-external-tool-authorizable.service'; | ||
export * from './tool-reference.service'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
196 changes: 196 additions & 0 deletions
196
apps/server/src/modules/tool/context-external-tool/service/tool-version-service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
import { createMock, DeepMocked } from '@golevelup/ts-jest'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { contextExternalToolFactory, externalToolFactory, schoolExternalToolFactory } from '@shared/testing'; | ||
import { ApiValidationError } from '@shared/common'; | ||
import { SchoolExternalToolValidationService } from '../../school-external-tool/service'; | ||
import { ToolVersionService } from './tool-version-service'; | ||
import { ContextExternalToolValidationService } from './context-external-tool-validation.service'; | ||
import { CommonToolService } from '../../common/service'; | ||
import { IToolFeatures, ToolFeatures } from '../../tool-config'; | ||
import { ToolConfigurationStatus } from '../../common/enum'; | ||
|
||
describe('ToolVersionService', () => { | ||
let module: TestingModule; | ||
let service: ToolVersionService; | ||
|
||
let contextExternalToolValidationService: DeepMocked<ContextExternalToolValidationService>; | ||
let schoolExternalToolValidationService: DeepMocked<SchoolExternalToolValidationService>; | ||
let commonToolService: DeepMocked<CommonToolService>; | ||
let toolFeatures: DeepMocked<IToolFeatures>; | ||
|
||
beforeAll(async () => { | ||
module = await Test.createTestingModule({ | ||
providers: [ | ||
ToolVersionService, | ||
{ | ||
provide: ContextExternalToolValidationService, | ||
useValue: createMock<ContextExternalToolValidationService>(), | ||
}, | ||
{ | ||
provide: SchoolExternalToolValidationService, | ||
useValue: createMock<SchoolExternalToolValidationService>(), | ||
}, | ||
{ | ||
provide: CommonToolService, | ||
useValue: createMock<CommonToolService>(), | ||
}, | ||
{ | ||
provide: ToolFeatures, | ||
useValue: { | ||
toolStatusWithoutVersions: false, | ||
}, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
service = module.get(ToolVersionService); | ||
contextExternalToolValidationService = module.get(ContextExternalToolValidationService); | ||
schoolExternalToolValidationService = module.get(SchoolExternalToolValidationService); | ||
commonToolService = module.get(CommonToolService); | ||
toolFeatures = module.get(ToolFeatures); | ||
}); | ||
|
||
afterAll(async () => { | ||
await module.close(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('determineToolConfigurationStatus', () => { | ||
describe('when FEATURE_COMPUTE_TOOL_STATUS_WITHOUT_VERSIONS_ENABLED is false', () => { | ||
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 = false; | ||
|
||
return { | ||
externalTool, | ||
schoolExternalTool, | ||
contextExternalTool, | ||
}; | ||
}; | ||
|
||
it('should call CommonToolService', async () => { | ||
const { externalTool, schoolExternalTool, contextExternalTool } = setup(); | ||
|
||
await service.determineToolConfigurationStatus(externalTool, schoolExternalTool, contextExternalTool); | ||
|
||
expect(commonToolService.determineToolConfigurationStatus).toHaveBeenCalledWith( | ||
externalTool, | ||
schoolExternalTool, | ||
contextExternalTool | ||
); | ||
}); | ||
}); | ||
|
||
describe('when FEATURE_COMPUTE_TOOL_STATUS_WITHOUT_VERSIONS_ENABLED is true and validation runs through', () => { | ||
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.mockResolvedValue(); | ||
contextExternalToolValidationService.validate.mockResolvedValueOnce(); | ||
|
||
return { | ||
externalTool, | ||
schoolExternalTool, | ||
contextExternalTool, | ||
}; | ||
}; | ||
|
||
it('should return latest tool status', async () => { | ||
const { externalTool, schoolExternalTool, contextExternalTool } = setup(); | ||
|
||
const status: ToolConfigurationStatus = await service.determineToolConfigurationStatus( | ||
externalTool, | ||
schoolExternalTool, | ||
contextExternalTool | ||
); | ||
|
||
expect(status).toEqual(ToolConfigurationStatus.LATEST); | ||
}); | ||
|
||
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(schoolExternalToolValidationService.validate).toHaveBeenCalledWith(schoolExternalTool); | ||
}); | ||
}); | ||
|
||
describe('when FEATURE_COMPUTE_TOOL_STATUS_WITHOUT_VERSIONS_ENABLED is true and validation 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.mockResolvedValue(); | ||
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(ToolConfigurationStatus.OUTDATED); | ||
}); | ||
|
||
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); | ||
}); | ||
}); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
apps/server/src/modules/tool/context-external-tool/service/tool-version-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { Injectable } from '@nestjs/common/decorators/core/injectable.decorator'; | ||
import { Inject } from '@nestjs/common'; | ||
import { ContextExternalToolValidationService } from './context-external-tool-validation.service'; | ||
import { SchoolExternalToolValidationService } from '../../school-external-tool/service'; | ||
import { IToolFeatures, ToolFeatures } from '../../tool-config'; | ||
import { ExternalTool } from '../../external-tool/domain'; | ||
import { SchoolExternalTool } from '../../school-external-tool/domain'; | ||
import { ContextExternalTool } from '../domain'; | ||
import { ToolConfigurationStatus } from '../../common/enum'; | ||
import { CommonToolService } from '../../common/service'; | ||
|
||
@Injectable() | ||
export class ToolVersionService { | ||
constructor( | ||
private readonly contextExternalToolValidationService: ContextExternalToolValidationService, | ||
private readonly schoolExternalToolValidationService: SchoolExternalToolValidationService, | ||
private readonly commonToolService: CommonToolService, | ||
@Inject(ToolFeatures) private readonly toolFeatures: IToolFeatures | ||
) {} | ||
|
||
async determineToolConfigurationStatus( | ||
externalTool: ExternalTool, | ||
schoolExternalTool: SchoolExternalTool, | ||
contextExternalTool: ContextExternalTool | ||
): Promise<ToolConfigurationStatus> { | ||
// TODO N21-1337 remove if statement, when feature flag is removed | ||
if (this.toolFeatures.toolStatusWithoutVersions) { | ||
try { | ||
await this.schoolExternalToolValidationService.validate(schoolExternalTool); | ||
await this.contextExternalToolValidationService.validate(contextExternalTool); | ||
return ToolConfigurationStatus.LATEST; | ||
} catch (err) { | ||
return ToolConfigurationStatus.OUTDATED; | ||
} | ||
} | ||
const status: ToolConfigurationStatus = this.commonToolService.determineToolConfigurationStatus( | ||
externalTool, | ||
schoolExternalTool, | ||
contextExternalTool | ||
); | ||
|
||
return status; | ||
} | ||
} |
Oops, something went wrong.