-
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.
- Loading branch information
1 parent
fbcd329
commit f746e86
Showing
8 changed files
with
112 additions
and
38 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
47 changes: 47 additions & 0 deletions
47
.../modules/tool/context-external-tool/service/restricted-context-mismatch-loggabble.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,47 @@ | ||
import { ToolContextType } from '../../common/enum'; | ||
import { RestrictedContextMismatchLoggable } from './restricted-context-mismatch-loggabble'; | ||
|
||
describe('RestrictedContextMismatchLoggable', () => { | ||
describe('constructor', () => { | ||
const setup = () => { | ||
const externalToolName = 'name'; | ||
const context: ToolContextType = ToolContextType.COURSE; | ||
|
||
return { externalToolName, context }; | ||
}; | ||
|
||
it('should create an instance of RestrictedContextMismatchLoggable', () => { | ||
const { externalToolName, context } = setup(); | ||
|
||
const loggable = new RestrictedContextMismatchLoggable(externalToolName, context); | ||
|
||
expect(loggable).toBeInstanceOf(RestrictedContextMismatchLoggable); | ||
}); | ||
}); | ||
|
||
describe('getLogMessage', () => { | ||
const setup = () => { | ||
const externalToolName = 'name'; | ||
const context: ToolContextType = ToolContextType.COURSE; | ||
const loggable = new RestrictedContextMismatchLoggable(externalToolName, context); | ||
|
||
return { loggable, externalToolName, context }; | ||
}; | ||
|
||
it('should return a loggable message', () => { | ||
const { loggable, externalToolName, context } = setup(); | ||
|
||
const message = loggable.getLogMessage(); | ||
|
||
expect(message).toEqual({ | ||
type: 'UNPROCESSABLE_ENTITY_EXCEPTION', | ||
message: `Could not create an instance of ${externalToolName} in context: ${context} because of the context restrictions of the tool.`, | ||
stack: loggable.stack, | ||
data: { | ||
externalToolName, | ||
context, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
24 changes: 24 additions & 0 deletions
24
...r/src/modules/tool/context-external-tool/service/restricted-context-mismatch-loggabble.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,24 @@ | ||
import { UnprocessableEntityException } from '@nestjs/common'; | ||
import { Loggable } from '@src/core/logger/interfaces'; | ||
import { ErrorLogMessage, LogMessage, ValidationErrorLogMessage } from '@src/core/logger'; | ||
import { ToolContextType } from '../../common/enum'; | ||
|
||
export class RestrictedContextMismatchLoggable extends UnprocessableEntityException implements Loggable { | ||
constructor(private readonly externalToolName: string, private readonly context: ToolContextType) { | ||
super(); | ||
} | ||
|
||
getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage { | ||
const message: LogMessage | ErrorLogMessage | ValidationErrorLogMessage = { | ||
type: 'UNPROCESSABLE_ENTITY_EXCEPTION', | ||
message: `Could not create an instance of ${this.externalToolName} in context: ${this.context} because of the context restrictions of the tool.`, | ||
stack: this.stack, | ||
data: { | ||
externalToolName: this.externalToolName, | ||
context: this.context, | ||
}, | ||
}; | ||
|
||
return message; | ||
} | ||
} |
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
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