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-1677 ctl config states #4970

Merged
merged 15 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ export class ContextExternalToolConfigurationStatusResponse {

@ApiProperty({
type: Boolean,
description: 'True, if a configured parameter on the context external tool is missing a value',
description: 'True, if a mandatory parameter on the context external tool is missing a value',
mrikallab marked this conversation as resolved.
Show resolved Hide resolved
})
isIncompleteOnScopeContext: boolean;

@ApiProperty({
type: Boolean,
description: 'True, if a optional parameter on the context external tool is missing a value',
})
isIncompleteOperationalOnScopeContext: boolean;
mrikallab marked this conversation as resolved.
Show resolved Hide resolved

@ApiProperty({
type: Boolean,
description: 'Is the tool deactivated, because of superhero or school administrator',
Expand All @@ -31,6 +37,7 @@ export class ContextExternalToolConfigurationStatusResponse {
this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool;
this.isOutdatedOnScopeContext = props.isOutdatedOnScopeContext;
this.isIncompleteOnScopeContext = props.isIncompleteOnScopeContext;
this.isIncompleteOperationalOnScopeContext = props.isIncompleteOperationalOnScopeContext;
this.isDeactivated = props.isDeactivated;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ export class ContextExternalToolConfigurationStatus {

isDeactivated: boolean;

isIncompleteOperationalOnScopeContext: boolean;

constructor(props: ContextExternalToolConfigurationStatus) {
this.isOutdatedOnScopeSchool = props.isOutdatedOnScopeSchool;
this.isOutdatedOnScopeContext = props.isOutdatedOnScopeContext;
this.isIncompleteOnScopeContext = props.isIncompleteOnScopeContext;
this.isIncompleteOperationalOnScopeContext = props.isIncompleteOperationalOnScopeContext;
this.isDeactivated = props.isDeactivated;
}
}
3 changes: 2 additions & 1 deletion apps/server/src/modules/tool/common/domain/error/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export { ToolParameterRequiredLoggableException } from './tool-parameter-require
export { ToolParameterUnknownLoggableException } from './tool-parameter-unknown.loggable-exception';
export { ToolParameterValueRegexLoggableException } from './tool-parameter-value-regex.loggable-exception';
export { ToolParameterTypeMismatchLoggableException } from './tool-parameter-type-mismatch.loggable-exception';
export { ToolParameterValueMissingLoggableException } from './tool-parameter-value-missing.loggable-exception';
export { ToolParameterMandatoryValueMissingLoggableException } from './tool-parameter-mandatory-value-missing-loggable.exception';
export { ContextExternalToolNameAlreadyExistsLoggableException } from './context-external-tool-name-already-exists.loggable-exception';
export { ToolParameterOptionalValueMissingLoggableException } from './tool-parameter-optional-value-missing-loggable-exception';
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { EntityId } from '@shared/domain/types';
import { HttpStatus } from '@nestjs/common';
import { CustomParameter } from '../custom-parameter.do';

export class ToolParameterValueMissingLoggableException extends BusinessError implements Loggable {
export class ToolParameterMandatoryValueMissingLoggableException extends BusinessError implements Loggable {
constructor(private readonly validatableToolId: EntityId | undefined, private readonly parameter: CustomParameter) {
super(
{
type: 'TOOL_PARAMETER_VALUE_MISSING',
title: 'Missing tool parameter value',
defaultMessage: 'The parameter has no value.',
type: 'TOOL_PARAMETER_MANDATORY_VALUE_MISSING',
title: 'Missing mandatory tool parameter value',
defaultMessage: 'The mandatory parameter has no value.',
},
HttpStatus.BAD_REQUEST,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import { customParameterFactory } from '@shared/testing';
import { CustomParameter } from '../custom-parameter.do';
import { ToolParameterValueMissingLoggableException } from './tool-parameter-value-missing.loggable-exception';
import { ToolParameterMandatoryValueMissingLoggableException } from './tool-parameter-mandatory-value-missing-loggable.exception';

describe(ToolParameterValueMissingLoggableException.name, () => {
describe(ToolParameterMandatoryValueMissingLoggableException.name, () => {
describe('getLogMessage', () => {
const setup = () => {
const parameter: CustomParameter = customParameterFactory.build();

const exception: ToolParameterValueMissingLoggableException = new ToolParameterValueMissingLoggableException(
'toolId',
parameter
);
const exception: ToolParameterMandatoryValueMissingLoggableException =
new ToolParameterMandatoryValueMissingLoggableException('toolId', parameter);

return {
parameter,
Expand All @@ -24,8 +22,8 @@ describe(ToolParameterValueMissingLoggableException.name, () => {
const result = exception.getLogMessage();

expect(result).toEqual({
type: 'TOOL_PARAMETER_VALUE_MISSING',
message: 'The parameter has no value.',
type: 'TOOL_PARAMETER_MANDATORY_VALUE_MISSING',
mrikallab marked this conversation as resolved.
Show resolved Hide resolved
message: 'The mandatory parameter has no value.',
stack: exception.stack,
data: {
parameterName: parameter.name,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { customParameterFactory } from '@shared/testing';
import { CustomParameter } from '../custom-parameter.do';
import { ToolParameterOptionalValueMissingLoggableException } from './tool-parameter-optional-value-missing-loggable-exception';

describe(ToolParameterOptionalValueMissingLoggableException.name, () => {
describe('getLogMessage', () => {
const setup = () => {
const parameter: CustomParameter = customParameterFactory.build();

const exception: ToolParameterOptionalValueMissingLoggableException =
new ToolParameterOptionalValueMissingLoggableException('toolId', parameter);

return {
parameter,
exception,
};
};

it('should return log message', () => {
const { exception, parameter } = setup();

const result = exception.getLogMessage();

expect(result).toStrictEqual({
type: 'VALUE_MISSING_ON_OPTIONAL_TOOL_PARAMETER',
message: 'The optional parameter has no value.',
stack: exception.stack,
data: {
parameterName: parameter.name,
validatableToolId: 'toolId',
},
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { HttpStatus } from '@nestjs/common';
import { BusinessError } from '@shared/common';
import { ErrorLogMessage, Loggable, LogMessage, ValidationErrorLogMessage } from '@src/core/logger';
import { EntityId } from '@shared/domain/types';
import { CustomParameter } from '../custom-parameter.do';

export class ToolParameterOptionalValueMissingLoggableException extends BusinessError implements Loggable {
constructor(private readonly validatableToolId: EntityId | undefined, private readonly parameter: CustomParameter) {
super(
{
type: 'VALUE_MISSING_ON_OPTIONAL_TOOL_PARAMETER',
title: 'Missing value on optional tool parameter',
defaultMessage: 'The optional parameter has no value.',
},
HttpStatus.BAD_REQUEST,
{
parameter,
validatableToolId,
}
);
}

getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage {
return {
type: this.type,
message: this.message,
stack: this.stack,
data: {
parameterName: this.parameter.name,
validatableToolId: this.validatableToolId,
},
};
}
}
3 changes: 2 additions & 1 deletion apps/server/src/modules/tool/common/domain/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ export {
ToolParameterUnknownLoggableException,
ToolParameterValueRegexLoggableException,
ToolParameterTypeMismatchLoggableException,
ToolParameterValueMissingLoggableException,
ToolParameterMandatoryValueMissingLoggableException,
ToolParameterOptionalValueMissingLoggableException,
ContextExternalToolNameAlreadyExistsLoggableException,
} from './error';
export * from './custom-parameter.do';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class ToolStatusResponseMapper {
isOutdatedOnScopeSchool: status.isOutdatedOnScopeSchool,
isOutdatedOnScopeContext: status.isOutdatedOnScopeContext,
isIncompleteOnScopeContext: status.isIncompleteOnScopeContext,
isIncompleteOperationalOnScopeContext: status.isIncompleteOperationalOnScopeContext,
isDeactivated: status.isDeactivated,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
CustomParameter,
CustomParameterEntry,
ToolParameterRequiredLoggableException,
ToolParameterValueMissingLoggableException,
ToolParameterMandatoryValueMissingLoggableException,
} from '../../../domain';
import { ParameterArrayEntryValidator } from './parameter-array-entry-validator';

Expand Down Expand Up @@ -83,7 +83,7 @@ describe(ParameterArrayEntryValidator.name, () => {

const result: ValidationError[] = new ParameterArrayEntryValidator().validate(entries, declarations, undefined);

expect(result[0]).toBeInstanceOf(ToolParameterValueMissingLoggableException);
expect(result[0]).toBeInstanceOf(ToolParameterMandatoryValueMissingLoggableException);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ValidationError } from '@shared/common';
import { customParameterFactory } from '@shared/testing';
import { CustomParameter, CustomParameterEntry, ToolParameterValueMissingLoggableException } from '../../../domain';
import {
CustomParameter,
CustomParameterEntry,
ToolParameterMandatoryValueMissingLoggableException,
ToolParameterOptionalValueMissingLoggableException,
} from '../../../domain';
import { ParameterEntryValueValidator } from './parameter-entry-value-validator';

describe(ParameterEntryValueValidator.name, () => {
Expand Down Expand Up @@ -30,52 +35,107 @@ describe(ParameterEntryValueValidator.name, () => {
});
});

describe('when the parameter value is an empty string', () => {
const setup = () => {
const declaration: CustomParameter = customParameterFactory.build({
name: 'param1',
});
const entry: CustomParameterEntry = new CustomParameterEntry({
name: 'param1',
value: '',
describe('when parameter is mandatory', () => {
describe('when the parameter value is an empty string', () => {
const setup = () => {
const declaration: CustomParameter = customParameterFactory.build({
name: 'param1',
});
const entry: CustomParameterEntry = new CustomParameterEntry({
name: 'param1',
value: '',
});

return {
entry,
declaration,
};
};

it('should return a validation error', () => {
const { entry, declaration } = setup();

const result: ValidationError[] = new ParameterEntryValueValidator().validate(entry, declaration, undefined);

expect(result[0]).toBeInstanceOf(ToolParameterMandatoryValueMissingLoggableException);
});
});

return {
entry,
declaration,
describe('when the parameter value is undefined', () => {
const setup = () => {
const declaration: CustomParameter = customParameterFactory.build({
name: 'param1',
});
const entry: CustomParameterEntry = new CustomParameterEntry({
name: 'param1',
});

return {
entry,
declaration,
};
};
};

it('should return a validation error', () => {
const { entry, declaration } = setup();
it('should return a validation error', () => {
const { entry, declaration } = setup();

const result: ValidationError[] = new ParameterEntryValueValidator().validate(entry, declaration, undefined);
const result: ValidationError[] = new ParameterEntryValueValidator().validate(entry, declaration, undefined);

expect(result[0]).toBeInstanceOf(ToolParameterValueMissingLoggableException);
expect(result[0]).toBeInstanceOf(ToolParameterMandatoryValueMissingLoggableException);
});
});
});

describe('when the parameter value is undefined', () => {
const setup = () => {
const declaration: CustomParameter = customParameterFactory.build({
name: 'param1',
});
const entry: CustomParameterEntry = new CustomParameterEntry({
name: 'param1',
describe('when parameter is optional', () => {
describe('when the parameter value is an empty string', () => {
const setup = () => {
const declaration: CustomParameter = customParameterFactory.build({
name: 'param1',
isOptional: true,
});
const entry: CustomParameterEntry = new CustomParameterEntry({
name: 'param1',
value: '',
});

return {
entry,
declaration,
};
};

it('should return a validation error', () => {
const { entry, declaration } = setup();

const result: ValidationError[] = new ParameterEntryValueValidator().validate(entry, declaration, undefined);

expect(result[0]).toBeInstanceOf(ToolParameterOptionalValueMissingLoggableException);
});
});

return {
entry,
declaration,
describe('when the parameter value is undefined', () => {
const setup = () => {
const declaration: CustomParameter = customParameterFactory.build({
name: 'param1',
isOptional: true,
});
const entry: CustomParameterEntry = new CustomParameterEntry({
name: 'param1',
});

return {
entry,
declaration,
};
};
};

it('should return a validation error', () => {
const { entry, declaration } = setup();
it('should return a validation error', () => {
const { entry, declaration } = setup();

const result: ValidationError[] = new ParameterEntryValueValidator().validate(entry, declaration, undefined);
const result: ValidationError[] = new ParameterEntryValueValidator().validate(entry, declaration, undefined);

expect(result[0]).toBeInstanceOf(ToolParameterValueMissingLoggableException);
expect(result[0]).toBeInstanceOf(ToolParameterOptionalValueMissingLoggableException);
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ValidationError } from '@shared/common';
import { EntityId } from '@shared/domain/types';
import { CustomParameter, CustomParameterEntry, ToolParameterValueMissingLoggableException } from '../../../domain';
import {
CustomParameter,
CustomParameterEntry,
ToolParameterMandatoryValueMissingLoggableException,
ToolParameterOptionalValueMissingLoggableException,
} from '../../../domain';
import { ParameterEntryValidator } from './parameter-entry-validator';

export class ParameterEntryValueValidator implements ParameterEntryValidator {
Expand All @@ -10,7 +15,10 @@ export class ParameterEntryValueValidator implements ParameterEntryValidator {
toolId: EntityId | undefined
): ValidationError[] {
if (entry.value === undefined || entry.value === '') {
return [new ToolParameterValueMissingLoggableException(toolId, declaration)];
if (declaration.isOptional) {
return [new ToolParameterOptionalValueMissingLoggableException(toolId, declaration)];
}
return [new ToolParameterMandatoryValueMissingLoggableException(toolId, declaration)];
}

return [];
Expand Down
Loading
Loading