refactor(server): user profile picture (#4728)

This commit is contained in:
Jason Rasmussen
2023-10-30 19:38:34 -04:00
committed by GitHub
parent 431536cdbb
commit 3212a47720
5 changed files with 49 additions and 30 deletions
+14 -1
View File
@@ -16,6 +16,7 @@ import {
userStub,
} from '@test';
import { when } from 'jest-when';
import { Readable } from 'stream';
import { AuthUserDto } from '../auth';
import { JobName } from '../job';
import {
@@ -461,7 +462,7 @@ describe(UserService.name, () => {
it('should throw an error if the user does not exist', async () => {
userMock.get.mockResolvedValue(null);
await expect(sut.getProfileImage(adminUserAuth.id)).rejects.toBeInstanceOf(NotFoundException);
await expect(sut.getProfileImage(adminUserAuth.id)).rejects.toBeInstanceOf(BadRequestException);
expect(userMock.get).toHaveBeenCalledWith(adminUserAuth.id);
});
@@ -473,6 +474,18 @@ describe(UserService.name, () => {
expect(userMock.get).toHaveBeenCalledWith(adminUserAuth.id);
});
it('should return the profile picture', async () => {
const stream = new Readable();
userMock.get.mockResolvedValue(userStub.profilePath);
storageMock.createReadStream.mockResolvedValue({ stream });
await expect(sut.getProfileImage(userStub.profilePath.id)).resolves.toEqual({ stream });
expect(userMock.get).toHaveBeenCalledWith(userStub.profilePath.id);
expect(storageMock.createReadStream).toHaveBeenCalledWith('/path/to/profile.jpg', 'image/jpeg');
});
});
describe('resetAdminPassword', () => {