-
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
(cherry picked from commit 9737e90)
- Loading branch information
1 parent
5c27bf7
commit cf0a9f2
Showing
5 changed files
with
142 additions
and
10 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
38 changes: 38 additions & 0 deletions
38
apps/server/src/modules/user-import/loggable/user-migration-failed.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,38 @@ | ||
import { NotFoundException } from '@nestjs/common'; | ||
import { importUserFactory, setupEntities } from '@shared/testing'; | ||
import { UserMigrationFailedLoggable } from './user-migration-failed.loggable'; | ||
|
||
describe(UserMigrationFailedLoggable.name, () => { | ||
describe('getLogMessage', () => { | ||
const setup = async () => { | ||
await setupEntities(); | ||
const importUser = importUserFactory.build(); | ||
const error = new NotFoundException('user not found'); | ||
const loggable = new UserMigrationFailedLoggable(importUser, error); | ||
|
||
return { | ||
loggable, | ||
importUser, | ||
error, | ||
}; | ||
}; | ||
|
||
it('should return the correct log message', async () => { | ||
const { loggable, importUser, error } = await setup(); | ||
|
||
const message = loggable.getLogMessage(); | ||
|
||
expect(message).toEqual({ | ||
type: 'USER_MIGRATION_FAILED', | ||
message: 'An error occurred while migrating a user with the migration wizard.', | ||
stack: error.stack, | ||
data: { | ||
externalUserId: importUser.externalId, | ||
userId: importUser.user?.id, | ||
errorName: error.name, | ||
errorMsg: error.message, | ||
}, | ||
}); | ||
}); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
apps/server/src/modules/user-import/loggable/user-migration-failed.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,20 @@ | ||
import { ErrorLogMessage, Loggable, LogMessage, ValidationErrorLogMessage } from '@src/core/logger'; | ||
import { ImportUser } from '../entity'; | ||
|
||
export class UserMigrationFailedLoggable implements Loggable { | ||
constructor(private readonly importUser: ImportUser, private readonly error: Error) {} | ||
|
||
public getLogMessage(): LogMessage | ErrorLogMessage | ValidationErrorLogMessage { | ||
return { | ||
type: 'USER_MIGRATION_FAILED', | ||
message: 'An error occurred while migrating a user with the migration wizard.', | ||
stack: this.error.stack, | ||
data: { | ||
externalUserId: this.importUser.externalId, | ||
userId: this.importUser.user?.id, | ||
errorName: this.error.name, | ||
errorMsg: this.error.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