Skip to content

Commit

Permalink
Merge pull request #95 from LocalMingle/dev
Browse files Browse the repository at this point in the history
Eric -> dev -> main
  • Loading branch information
erickimme authored Oct 25, 2023
2 parents 1c453e1 + d3c6a51 commit 72655fd
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 75 deletions.
1 change: 1 addition & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ model UserDetail {
nickname String @unique
intro String?
profileImg String?
userLocation String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand Down
19 changes: 17 additions & 2 deletions src/aws/aws.s3.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// src/aws/aws.s3.ts
import * as AWS from 'aws-sdk';
import { BadRequestException, Injectable } from '@nestjs/common';
import {
BadRequestException,
Injectable,
NotFoundException,
} from '@nestjs/common';

@Injectable()
export class AwsS3Service {
Expand All @@ -15,8 +19,19 @@ export class AwsS3Service {

// S3 프로필 이미지 업로드 로직
async uploadFile(file) {
// 이미지 파일 Validation 체크
const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB
const SUPPORTED_FILE_TYPES = ['image/jpeg', 'image/png', 'image/gif'];
if (!file) {
throw new BadRequestException('No file uploaded');
throw new NotFoundException('이미지 파일을 선택해주세요.');
}
if (file.size > MAX_FILE_SIZE) {
throw new BadRequestException('파일 크기는 5MB를 초과할 수 없습니다.');
}
if (!SUPPORTED_FILE_TYPES.includes(file.mimetype)) {
throw new BadRequestException(
'지원되는 파일 형식은 JPEG, PNG, GIF 뿐입니다.'
);
}

const params = {
Expand Down
8 changes: 8 additions & 0 deletions src/users/dto/create-user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ export class CreateUserDto {
})
profileImg?: string;

@IsString()
@IsOptional()
@ApiProperty({
description: 'userLocation',
example: '서울시 강남구 ',
})
userLocation?: string;

@IsString()
@IsOptional()
@ApiProperty({
Expand Down
22 changes: 21 additions & 1 deletion src/users/dto/update-user.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,43 @@ import {
Matches,
MaxLength,
MinLength,
IsOptional,
} from 'class-validator';

export class UpdateUserDto {
@IsString()
@IsNotEmpty()
@MinLength(2)
@MaxLength(8)
//영어 또는 한글이 포함
@Matches(/^(?=.*[A-Za-z가-힣]).*[A-Za-z가-힣0-9]*$/)
@IsOptional()
@ApiProperty({
description: 'nickname',
example: '닉네임',
})
nickname: string;

@IsString()
@IsOptional()
@ApiProperty({
description: 'intro',
example: '안녕하세요',
})
intro: string;

@IsString()
@IsOptional()
@ApiProperty({
description: 'email',
example: '[email protected]',
})
email: string;

@IsString()
@IsNotEmpty()
@MinLength(8)
@MaxLength(15)
@IsOptional()
//알파벳 포함 , 숫자 포함 , 특수문자 포함
@Matches(/^(?=.*[A-Za-z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]+$/)
@ApiProperty({
Expand All @@ -42,6 +53,7 @@ export class UpdateUserDto {

@IsString()
@IsNotEmpty()
@IsOptional()
@ApiProperty({
description: 'password confirm',
example: 'abc123456789!',
Expand All @@ -53,4 +65,12 @@ export class UpdateUserDto {
example: false,
})
nameChanged: boolean;

@IsString()
@IsOptional()
@ApiProperty({
description: 'userLocation',
example: '서울시 강남구',
})
userLocation?: string;
}
10 changes: 10 additions & 0 deletions src/users/dto/update-userPassword.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// src/users/dto/update-user.dto.ts
import { ApiProperty } from '@nestjs/swagger';

export class UpdateUserPasswordDto {
@ApiProperty({
example: '1234', // 예시 값을 설정
description: 'The password of the user for password update',
})
password: string;
}
47 changes: 32 additions & 15 deletions src/users/users.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,56 @@
import { Test, TestingModule } from '@nestjs/testing';
import { UsersController } from './users.controller';
import { UsersService } from './users.service';
// import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { UsersModule } from './users.module';
import { PrismaService } from '../prisma/prisma.service';
import { AwsS3Service } from '../aws/aws.s3';

describe('UsersController unit test', () => {
// let app: INestApplication;
let controller: UsersController;
let service: UsersService;

// const userServiceTest = { findAll: () => ['test1', 'test2'] };
// console.log('userServiceTest:', userServiceTest);

let requestMock = {};
let responseMock = {};
const mockPrismaService = {
// 여기에 필요한 메서드를 mock 구현
};

const mockUsersService = {
findOne: jest.fn((id: number) => {
return { userId: id, email: '[email protected]' };
}),
};

beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [UsersController],
imports: [UsersModule],
providers: [UsersService],
})
// .overrideProvider(UsersService)
// .useValue(userServiceTest)
.compile();
providers: [
{ provide: UsersService, useValue: mockUsersService },
{ provide: PrismaService, useValue: mockPrismaService },
AwsS3Service,
],
}).compile();

controller = module.get<UsersController>(UsersController);
// app = module.createNestApplication();
// await app.init();
service = module.get<UsersService>(UsersService);
});

// jest test
it('should be defined', () => {
expect(controller).toBeDefined();
// it('should be defined', () => {
// expect(controller).toBeDefined();
// });

describe('Unit Tests', () => {
// TC01: findOne(id: number) 테스트
it('TC01: findOne should return a user object', async () => {
const id = '1';
expect(await controller.findOne(id)).toEqual({
userId: 1,
email: '[email protected]',
});
expect(service.findOne).toHaveBeenCalledWith(id);
});
});

describe('Unit Tests', () => {
Expand Down
Loading

0 comments on commit 72655fd

Please sign in to comment.