-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
33cba70
commit 0f5455f
Showing
12 changed files
with
168 additions
and
36 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
25 changes: 25 additions & 0 deletions
25
apps/server/src/modules/authentication/loggable/account-not-found.loggable-exception.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,25 @@ | ||
import { AccountNotFoundLoggableException } from './account-not-found.loggable-exception'; | ||
|
||
describe(AccountNotFoundLoggableException.name, () => { | ||
describe('getLogMessage', () => { | ||
const setup = () => { | ||
const exception = new AccountNotFoundLoggableException(); | ||
|
||
return { | ||
exception, | ||
}; | ||
}; | ||
|
||
it('should return the correct log message', () => { | ||
const { exception } = setup(); | ||
|
||
const message = exception.getLogMessage(); | ||
|
||
expect(message).toEqual({ | ||
type: 'UNAUTHORIZED_EXCEPTION', | ||
stack: expect.any(String), | ||
data: {}, | ||
}); | ||
}); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
apps/server/src/modules/authentication/loggable/account-not-found.loggable-exception.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,27 @@ | ||
import { HttpStatus } from '@nestjs/common'; | ||
import { BusinessError } from '@shared/common'; | ||
import { Loggable } from '@src/core/logger/interfaces'; | ||
import { ErrorLogMessage } from '@src/core/logger/types'; | ||
|
||
export class AccountNotFoundLoggableException extends BusinessError implements Loggable { | ||
constructor() { | ||
super( | ||
{ | ||
type: 'UNAUTHORIZED_EXCEPTION', | ||
title: 'Login has failed because account not found', | ||
defaultMessage: 'Login has failed because account not found', | ||
}, | ||
HttpStatus.UNAUTHORIZED | ||
); | ||
} | ||
|
||
getLogMessage(): ErrorLogMessage { | ||
const message: ErrorLogMessage = { | ||
type: this.type, | ||
stack: this.stack, | ||
data: {}, | ||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
export * from './school-in-migration.loggable-exception'; | ||
export * from './account-not-found.loggable-exception'; | ||
export * from './user-could-not-be-authenticated.loggable.exception'; | ||
export * from './user-authenticated.loggable'; |
24 changes: 24 additions & 0 deletions
24
apps/server/src/modules/authentication/loggable/user-authenticated.loggable.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,24 @@ | ||
import { UserAuthenticatedLoggable } from './user-authenticated.loggable'; | ||
|
||
describe(UserAuthenticatedLoggable.name, () => { | ||
describe('getLogMessage', () => { | ||
const setup = () => { | ||
const loggable = new UserAuthenticatedLoggable(); | ||
|
||
return { | ||
loggable, | ||
}; | ||
}; | ||
|
||
it('should return the correct log message', () => { | ||
const { loggable } = setup(); | ||
|
||
const message = loggable.getLogMessage(); | ||
|
||
expect(message).toEqual({ | ||
message: 'SUCCESSFULLY_AUTHENTICATED', | ||
data: {}, | ||
}); | ||
}); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
apps/server/src/modules/authentication/loggable/user-authenticated.loggable.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,13 @@ | ||
import { Loggable } from '@src/core/logger/interfaces'; | ||
import { LogMessage } from '@src/core/logger/types'; | ||
|
||
export class UserAuthenticatedLoggable implements Loggable { | ||
getLogMessage(): LogMessage { | ||
const message: LogMessage = { | ||
message: 'SUCCESSFULLY_AUTHENTICATED', | ||
data: {}, | ||
}; | ||
|
||
return message; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...odules/authentication/loggable/user-could-not-be-authenticated.loggable.exception.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,27 @@ | ||
import { LdapUserCouldNotBeAuthenticatedLoggableException } from './user-could-not-be-authenticated.loggable.exception'; | ||
|
||
describe(LdapUserCouldNotBeAuthenticatedLoggableException.name, () => { | ||
describe('getLogMessage', () => { | ||
const setup = () => { | ||
const err = new Error('test'); | ||
const exception = new LdapUserCouldNotBeAuthenticatedLoggableException(err); | ||
|
||
return { | ||
exception, | ||
err, | ||
}; | ||
}; | ||
|
||
it('should return the correct log message', () => { | ||
const { err, exception } = setup(); | ||
|
||
const message = exception.getLogMessage(); | ||
|
||
expect(message).toEqual({ | ||
type: 'UNAUTHORIZED_EXCEPTION', | ||
stack: expect.any(String), | ||
data: { error: JSON.stringify(err) }, | ||
}); | ||
}); | ||
}); | ||
}); |
29 changes: 29 additions & 0 deletions
29
...src/modules/authentication/loggable/user-could-not-be-authenticated.loggable.exception.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,29 @@ | ||
import { HttpStatus } from '@nestjs/common'; | ||
import { BusinessError } from '@shared/common'; | ||
import { Loggable } from '@src/core/logger/interfaces'; | ||
import { ErrorLogMessage } from '@src/core/logger/types'; | ||
|
||
export class LdapUserCouldNotBeAuthenticatedLoggableException extends BusinessError implements Loggable { | ||
constructor(private readonly error: Error) { | ||
super( | ||
{ | ||
type: 'UNAUTHORIZED_EXCEPTION', | ||
title: 'User could not be authenticated', | ||
defaultMessage: 'LdapService connection failed because User could not be authenticated', | ||
}, | ||
HttpStatus.UNAUTHORIZED | ||
); | ||
} | ||
|
||
getLogMessage(): ErrorLogMessage { | ||
const message: ErrorLogMessage = { | ||
type: this.type, | ||
stack: this.stack, | ||
data: { | ||
error: JSON.stringify(this.error), | ||
}, | ||
}; | ||
|
||
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