Skip to content

Commit

Permalink
refactor: findProfileByUserUuid 비즈니스 로직 서비스로 이동
Browse files Browse the repository at this point in the history
  • Loading branch information
Conut-1 committed Nov 5, 2024
1 parent a895356 commit c3fcadf
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
2 changes: 1 addition & 1 deletion nestjs-BE/server/src/profiles/profiles.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('ProfilesController', () => {
it('not found profile', async () => {
jest
.spyOn(profilesService, 'findProfileByUserUuid')
.mockResolvedValue(null);
.mockRejectedValue(new NotFoundException());

const response = controller.findProfileByUserUuid(requestMock);

Expand Down
2 changes: 0 additions & 2 deletions nestjs-BE/server/src/profiles/profiles.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
UploadedFile,
Request as Req,
ValidationPipe,
NotFoundException,
HttpStatus,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
Expand Down Expand Up @@ -35,7 +34,6 @@ export class ProfilesController {
const profile = await this.profilesService.findProfileByUserUuid(
req.user.uuid,
);
if (!profile) throw new NotFoundException();
return { statusCode: HttpStatus.OK, message: 'Success', data: profile };
}

Expand Down
26 changes: 26 additions & 0 deletions nestjs-BE/server/src/profiles/profiles.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('ProfilesService', () => {
provide: PrismaService,
useValue: {
profile: {
findUnique: jest.fn(),
update: jest.fn(),
},
},
Expand All @@ -37,6 +38,31 @@ describe('ProfilesService', () => {
uploadService = module.get<UploadService>(UploadService);
});

describe('findProfileByUserUuid', () => {
const userUuid = 'user uuid';
const profile = { uuid: 'profile uuid', userUuid };

beforeEach(() => {
(prisma.profile.findUnique as jest.Mock).mockResolvedValue(profile);
});

it('found', async () => {
const res = profilesService.findProfileByUserUuid(userUuid);

await expect(res).resolves.toEqual(profile);
});

it('not found', async () => {
(prisma.profile.findUnique as jest.Mock).mockRejectedValue(
new NotFoundException(),
);

const res = profilesService.findProfileByUserUuid(userUuid);

await expect(res).rejects.toThrow(NotFoundException);
});
});

describe('updateProfile', () => {
const userUuid = 'user uuid';
const profileUuid = 'profile uuid';
Expand Down
6 changes: 5 additions & 1 deletion nestjs-BE/server/src/profiles/profiles.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export class ProfilesService {
) {}

async findProfileByUserUuid(userUuid: string): Promise<Profile | null> {
return this.prisma.profile.findUnique({ where: { userUuid } });
const profile = await this.prisma.profile.findUnique({
where: { userUuid },
});
if (!profile) throw new NotFoundException();
return profile;
}

async findProfileByProfileUuid(uuid: string): Promise<Profile | null> {
Expand Down

0 comments on commit c3fcadf

Please sign in to comment.