Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

N21-1494 Contextual info outdated CTL #4572

Merged
merged 28 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1454fda
N21-1494 WIP
mrikallab Nov 23, 2023
b28bdd0
N21-1494 remove import
mrikallab Nov 23, 2023
1021f15
Merge branch 'main' into N21-1494-info-outdated-ctl-tools
mrikallab Nov 23, 2023
6659d21
N21-1494 move toolConfiguration status
mrikallab Nov 23, 2023
988deaf
N21-1494 fix tests
mrikallab Nov 23, 2023
43fbf92
N21-1494 fix tests
mrikallab Nov 23, 2023
df3f704
Merge branch 'main' into N21-1494-info-outdated-ctl-tools
mrikallab Nov 24, 2023
3926f0f
N21-1494 review changes
mrikallab Nov 24, 2023
d6d9125
N21-1494 remove unused imports
mrikallab Nov 24, 2023
562068d
Merge branch 'main' into N21-1494-info-outdated-ctl-tools
mrikallab Nov 24, 2023
0e82ad6
N21-1494 review changes
mrikallab Nov 27, 2023
3d55b0f
Merge branch 'main' into N21-1494-info-outdated-ctl-tools
mrikallab Nov 27, 2023
3f57ec9
N21-1494 fix test
mrikallab Nov 28, 2023
607875f
Merge branch 'main' into N21-1494-info-outdated-ctl-tools
mrikallab Nov 28, 2023
4028fea
N21-1494 cypress test data
mrikallab Nov 30, 2023
96b047a
N21-1494 review changes
mrikallab Dec 1, 2023
6312b9e
N21-1494 refactoring
mrikallab Dec 1, 2023
7135aed
N21-1494 fix import
mrikallab Dec 1, 2023
6fa175f
Merge branch 'main' into N21-1494-info-outdated-ctl-tools
mrikallab Dec 1, 2023
08caca4
N21-1494 fix import
mrikallab Dec 1, 2023
17cd004
N21-1494 fix cy data
mrikallab Dec 1, 2023
22797b8
Merge branch 'main' into N21-1494-info-outdated-ctl-tools
mrikallab Dec 1, 2023
682d1d1
Merge branch 'main' into N21-1494-info-outdated-ctl-tools
mrikallab Dec 1, 2023
169ee50
N21-1494 review changes
mrikallab Dec 4, 2023
bce9afe
N21-1494 imports
mrikallab Dec 4, 2023
381810e
Merge branch 'main' into N21-1494-info-outdated-ctl-tools
mrikallab Dec 4, 2023
df4ccb5
N21-1494 cy seed data
mrikallab Dec 4, 2023
29da5c2
N21-1494 fix deprecated code
mrikallab Dec 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 './tool-configuration-status';
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export class ToolConfigurationStatus {
isDisabled: boolean;

isOutdatedOnScopeSchool: boolean;

isOutdatedOnScopeContext: boolean;

constructor(props: ToolConfigurationStatus) {
this.isDisabled = props.isDisabled;
this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool;
this.isOutdatedOnScopeContext = props.isOutdatedOnScopeContext;
}
}
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 { ToolConfigurationStatus } from '../domain';

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

return configurationStatus;
}
}
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down Expand Up @@ -36,7 +41,7 @@ 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(
Expand All @@ -45,7 +50,12 @@ describe('CommonToolService', () => {
contextExternalTool
);

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

Expand All @@ -62,7 +72,7 @@ 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(
Expand All @@ -71,7 +81,12 @@ describe('CommonToolService', () => {
contextExternalTool
);

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

Expand All @@ -88,7 +103,7 @@ 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(
Expand All @@ -97,7 +112,12 @@ describe('CommonToolService', () => {
contextExternalTool
);

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

Expand All @@ -114,7 +134,7 @@ 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(
Expand All @@ -123,7 +143,12 @@ describe('CommonToolService', () => {
contextExternalTool
);

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

Expand All @@ -140,7 +165,7 @@ 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(
Expand All @@ -149,7 +174,12 @@ describe('CommonToolService', () => {
contextExternalTool
);

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

Expand All @@ -166,7 +196,7 @@ 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(
Expand All @@ -175,7 +205,12 @@ describe('CommonToolService', () => {
contextExternalTool
);

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

Expand All @@ -192,7 +227,7 @@ 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(
Expand All @@ -201,7 +236,12 @@ describe('CommonToolService', () => {
contextExternalTool
);

expect(result).toBe(ToolConfigurationStatus.LATEST);
expect(result).toStrictEqual(
toolConfigurationStatusFactory.build({
isOutdatedOnScopeContext: false,
isOutdatedOnScopeSchool: false,
})
);
});
});
});
Expand Down
28 changes: 20 additions & 8 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,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
Expand All @@ -16,15 +16,27 @@ export class CommonToolService {
schoolExternalTool: SchoolExternalTool,
contextExternalTool: ContextExternalTool
): ToolConfigurationStatus {
if (
this.isLatest(schoolExternalTool, externalTool) &&
this.isLatest(contextExternalTool, schoolExternalTool) &&
this.isLatest(contextExternalTool, externalTool)
) {
return ToolConfigurationStatus.LATEST;
const configurationStatus: ToolConfigurationStatus = new ToolConfigurationStatus({
mrikallab marked this conversation as resolved.
Show resolved Hide resolved
isDisabled: false,
isOutdatedOnScopeContext: true,
isOutdatedOnScopeSchool: 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;
}

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 @@ -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';
mrikallab marked this conversation as resolved.
Show resolved Hide resolved
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;
Expand Down Expand Up @@ -160,7 +160,11 @@ describe('ToolReferenceController (API)', () => {
{
contextToolId: contextExternalToolEntity.id,
displayName: contextExternalToolEntity.displayName as string,
status: ToolConfigurationStatusResponse.LATEST,
status: toolConfigurationStatusResponseFactory.build({
isDisabled: false,
isOutdatedOnScopeSchool: false,
isOutdatedOnScopeContext: false,
}),
logoUrl: `http://localhost:3030/api/v3/tools/external-tools/${externalToolEntity.id}/logo`,
openInNewTab: externalToolEntity.openNewTab,
},
Expand Down Expand Up @@ -277,7 +281,10 @@ describe('ToolReferenceController (API)', () => {
expect(response.body).toEqual<ToolReferenceResponse>({
contextToolId: contextExternalToolEntity.id,
displayName: contextExternalToolEntity.displayName as string,
status: ToolConfigurationStatusResponse.LATEST,
status: toolConfigurationStatusResponseFactory.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
@@ -1,5 +1,26 @@
export enum ToolConfigurationStatusResponse {
LATEST = 'Latest',
OUTDATED = 'Outdated',
UNKNOWN = 'Unknown',
import { ApiProperty } from '@nestjs/swagger';

export class ToolConfigurationStatusResponse {
@ApiProperty({ type: Boolean, description: 'Is the tool disabled for context?' })
mrikallab marked this conversation as resolved.
Show resolved Hide resolved
isDisabled: boolean;

@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: ToolConfigurationStatusResponse) {
this.isDisabled = props.isDisabled;
this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool;
this.isOutdatedOnScopeContext = props.isOutdatedOnScopeContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export class ToolReferenceResponse {
openInNewTab: boolean;

@ApiProperty({
enum: ToolConfigurationStatusResponse,
enumName: 'ToolConfigurationStatusResponse',
type: ToolConfigurationStatusResponse,
nullable: false,
required: true,
description: 'The status of the tool',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain, why this could not be correct? I added also required, because we could need these Informations

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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ToolConfigurationStatus } from '../../common/enum';
import { ToolConfigurationStatus } from '../../common/domain';

export class ToolReference {
contextToolId: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
Loading
Loading