Skip to content

Commit

Permalink
N21-1494 Contextual info outdated CTL (#4572)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrikallab authored Dec 4, 2023
1 parent 3164f26 commit ece3f0d
Show file tree
Hide file tree
Showing 47 changed files with 760 additions and 142 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { ApiProperty } from '@nestjs/swagger';

export class ContextExternalToolConfigurationStatusResponse {
@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({
type: Boolean,
description:
'Is the tool outdated on context scope, because of non matching versions or required parameter changes on SchoolExternalTool?',
})
isOutdatedOnScopeContext: boolean;

constructor(props: ContextExternalToolConfigurationStatusResponse) {
this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool;
this.isOutdatedOnScopeContext = props.isOutdatedOnScopeContext;
}
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { ContextExternalToolCountPerContextResponse } from './context-external-tool-count-per-context.response';
export { ContextExternalToolConfigurationStatusResponse } from './context-external-tool-configuration-status.response';
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export class ContextExternalToolConfigurationStatus {
isOutdatedOnScopeSchool: boolean;

isOutdatedOnScopeContext: boolean;

constructor(props: ContextExternalToolConfigurationStatus) {
this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool;
this.isOutdatedOnScopeContext = props.isOutdatedOnScopeContext;
}
}
2 changes: 1 addition & 1 deletion apps/server/src/modules/tool/common/domain/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './custom-parameter.do';
export * from './custom-parameter-entry.do';
export * from '../enum/tool-configuration-status';
export * from './context-external-tool-configuration-status';
1 change: 0 additions & 1 deletion apps/server/src/modules/tool/common/enum/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 './tool-configuration-status';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { ToolConfigurationStatusResponse } from '../../context-external-tool/controller/dto';
import { ToolConfigurationStatus } from '../enum';

export const statusMapping: Record<ToolConfigurationStatus, ToolConfigurationStatusResponse> = {
[ToolConfigurationStatus.LATEST]: ToolConfigurationStatusResponse.LATEST,
[ToolConfigurationStatus.OUTDATED]: ToolConfigurationStatusResponse.OUTDATED,
[ToolConfigurationStatus.UNKNOWN]: ToolConfigurationStatusResponse.UNKNOWN,
};
import { ContextExternalToolConfigurationStatusResponse } from '../controller/dto';
import { ContextExternalToolConfigurationStatus } from '../domain';

export class ToolStatusResponseMapper {
static mapToResponse(status: ToolConfigurationStatus): ToolConfigurationStatusResponse {
return statusMapping[status];
static mapToResponse(status: ContextExternalToolConfigurationStatus): ContextExternalToolConfigurationStatusResponse {
const configurationStatus: ContextExternalToolConfigurationStatusResponse =
new ContextExternalToolConfigurationStatusResponse({
isOutdatedOnScopeSchool: status.isOutdatedOnScopeSchool,
isOutdatedOnScopeContext: status.isOutdatedOnScopeContext,
});

return configurationStatus;
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { Test, TestingModule } from '@nestjs/testing';
import { contextExternalToolFactory, externalToolFactory, schoolExternalToolFactory } from '@shared/testing';
import {
contextExternalToolFactory,
externalToolFactory,
schoolExternalToolFactory,
toolConfigurationStatusFactory,
} from '@shared/testing';
import { CommonToolService } from './common-tool.service';
import { ExternalTool } from '../../external-tool/domain';
import { SchoolExternalTool } from '../../school-external-tool/domain';
import { ToolConfigurationStatus, ToolContextType } from '../enum';
import { ToolContextType } from '../enum';
import { ContextExternalToolConfigurationStatus } from '../domain';
import { ContextExternalTool } from '../../context-external-tool/domain';

describe('CommonToolService', () => {
Expand Down Expand Up @@ -36,16 +42,21 @@ describe('CommonToolService', () => {
};
};

it('should return ToolConfigurationStatus.LATEST', () => {
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
);

expect(result).toBe(ToolConfigurationStatus.LATEST);
expect(result).toEqual(
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: false,
isOutdatedOnScopeSchool: false,
})
);
});
});

Expand All @@ -62,16 +73,21 @@ describe('CommonToolService', () => {
};
};

it('should return ToolConfigurationStatus.OUTDATED', () => {
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
);

expect(result).toBe(ToolConfigurationStatus.OUTDATED);
expect(result).toEqual(
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: true,
isOutdatedOnScopeSchool: true,
})
);
});
});

Expand All @@ -88,16 +104,21 @@ describe('CommonToolService', () => {
};
};

it('should return ToolConfigurationStatus.OUTDATED', () => {
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
);

expect(result).toBe(ToolConfigurationStatus.OUTDATED);
expect(result).toEqual(
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: true,
isOutdatedOnScopeSchool: true,
})
);
});
});

Expand All @@ -114,16 +135,21 @@ describe('CommonToolService', () => {
};
};

it('should return ToolConfigurationStatus.OUTDATED', () => {
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
);

expect(result).toBe(ToolConfigurationStatus.OUTDATED);
expect(result).toEqual(
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: true,
isOutdatedOnScopeSchool: true,
})
);
});
});

Expand All @@ -140,16 +166,21 @@ describe('CommonToolService', () => {
};
};

it('should return ToolConfigurationStatus.LATEST', () => {
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
);

expect(result).toBe(ToolConfigurationStatus.LATEST);
expect(result).toEqual(
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: false,
isOutdatedOnScopeSchool: false,
})
);
});
});

Expand All @@ -166,16 +197,21 @@ describe('CommonToolService', () => {
};
};

it('should return ToolConfigurationStatus.LATEST', () => {
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
);

expect(result).toBe(ToolConfigurationStatus.LATEST);
expect(result).toEqual(
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: false,
isOutdatedOnScopeSchool: false,
})
);
});
});

Expand All @@ -192,16 +228,21 @@ describe('CommonToolService', () => {
};
};

it('should return ToolConfigurationStatus.LATEST', () => {
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
);

expect(result).toBe(ToolConfigurationStatus.LATEST);
expect(result).toEqual(
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: false,
isOutdatedOnScopeSchool: false,
})
);
});
});
});
Expand Down
18 changes: 14 additions & 4 deletions apps/server/src/modules/tool/common/service/common-tool.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ 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, ToolContextType } from '../enum';
import { ToolContextType } from '../enum';
import { ContextExternalToolConfigurationStatus } from '../domain';
import { ToolVersion } from '../interface';

// TODO N21-1337 remove class when tool versioning is removed
Expand All @@ -15,16 +16,25 @@ export class CommonToolService {
externalTool: ExternalTool,
schoolExternalTool: SchoolExternalTool,
contextExternalTool: ContextExternalTool
): ToolConfigurationStatus {
): ContextExternalToolConfigurationStatus {
const configurationStatus: ContextExternalToolConfigurationStatus = new ContextExternalToolConfigurationStatus({
isOutdatedOnScopeContext: true,
isOutdatedOnScopeSchool: true,
});

if (
this.isLatest(schoolExternalTool, externalTool) &&
this.isLatest(contextExternalTool, schoolExternalTool) &&
this.isLatest(contextExternalTool, externalTool)
) {
return ToolConfigurationStatus.LATEST;
configurationStatus.isOutdatedOnScopeContext = false;
configurationStatus.isOutdatedOnScopeSchool = false;
} else {
configurationStatus.isOutdatedOnScopeContext = true;
configurationStatus.isOutdatedOnScopeSchool = true;
}

return ToolConfigurationStatus.OUTDATED;
return configurationStatus;
}

private isLatest(tool1: ToolVersion, tool2: ToolVersion): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ import {
externalToolEntityFactory,
schoolExternalToolEntityFactory,
schoolFactory,
contextExternalToolConfigurationStatusResponseFactory,
} from '@shared/testing';

import { Response } from 'supertest';
import { CustomParameterLocation, CustomParameterScope, 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;
Expand Down Expand Up @@ -174,7 +175,10 @@ describe('ToolReferenceController (API)', () => {
{
contextToolId: contextExternalToolEntity.id,
displayName: contextExternalToolEntity.displayName as string,
status: ToolConfigurationStatusResponse.LATEST,
status: contextExternalToolConfigurationStatusResponseFactory.build({
isOutdatedOnScopeSchool: false,
isOutdatedOnScopeContext: false,
}),
logoUrl: `http://localhost:3030/api/v3/tools/external-tools/${externalToolEntity.id}/logo`,
openInNewTab: externalToolEntity.openNewTab,
},
Expand Down Expand Up @@ -303,7 +307,10 @@ describe('ToolReferenceController (API)', () => {
expect(response.body).toEqual<ToolReferenceResponse>({
contextToolId: contextExternalToolEntity.id,
displayName: contextExternalToolEntity.displayName as string,
status: ToolConfigurationStatusResponse.LATEST,
status: contextExternalToolConfigurationStatusResponseFactory.build({
isOutdatedOnScopeSchool: false,
isOutdatedOnScopeContext: false,
}),
logoUrl: `http://localhost:3030/api/v3/tools/external-tools/${externalToolEntity.id}/logo`,
openInNewTab: externalToolEntity.openNewTab,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { ToolConfigurationStatusResponse } from './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' })
Expand All @@ -19,13 +19,12 @@ export class ToolReferenceResponse {
openInNewTab: boolean;

@ApiProperty({
enum: ToolConfigurationStatusResponse,
enumName: 'ToolConfigurationStatusResponse',
type: ContextExternalToolConfigurationStatusResponse,
nullable: false,
required: true,
description: 'The status of the tool',
})
status: ToolConfigurationStatusResponse;
status: ContextExternalToolConfigurationStatusResponse;

constructor(toolReferenceResponse: ToolReferenceResponse) {
this.contextToolId = toolReferenceResponse.contextToolId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit ece3f0d

Please sign in to comment.