forked from yy0ung/nibobnebob
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #176 from boostcampwm2023/feature/be-object-storage
유저 프로필 사진을 object storage에 저장 및 응답
- Loading branch information
Showing
13 changed files
with
480 additions
and
138 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
#config | ||
typeorm.config.ts | ||
objectStorage.config.ts | ||
|
||
# Logs | ||
logs | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,109 @@ | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
import { AuthService } from "./auth.service"; | ||
import { DataSource } from "typeorm"; | ||
import { User } from "src/user/entities/user.entity"; | ||
import { TypeOrmModule } from "@nestjs/typeorm"; | ||
import { FollowEntity } from "src/user/entities/user.followList.entity"; | ||
import { RestaurantInfoEntity } from "src/restaurant/entities/restaurant.entity"; | ||
import { UserRestaurantListEntity } from "src/user/entities/user.restaurantlist.entity"; | ||
import { ReviewInfoEntity } from "src/review/entities/review.entity"; | ||
import { JwtService } from "@nestjs/jwt"; | ||
import { UserModule } from "src/user/user.module"; | ||
import { RestaurantModule } from "src/restaurant/restaurant.module"; | ||
import { ReviewModule } from "src/review/review.module"; | ||
import { HttpException } from '@nestjs/common'; | ||
import { UserInfoDto } from "src/user/dto/userInfo.dto"; | ||
import { UserService } from "src/user/user.service"; | ||
import { AuthModule } from "./auth.module"; | ||
|
||
describe("AuthService", () => { | ||
let service: AuthService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [AuthService], | ||
let authService: AuthService; | ||
let dataSource: DataSource; | ||
let jwtService: JwtService; | ||
let userService: UserService; | ||
|
||
beforeAll(async () => { | ||
const testModule = await Test.createTestingModule({ | ||
imports: [ | ||
AuthModule, | ||
UserModule, | ||
RestaurantModule, | ||
ReviewModule, | ||
TypeOrmModule.forRoot({ | ||
type: 'postgres', | ||
host: 'localhost', | ||
port: 5433, | ||
username: 'user', | ||
password: 'password', | ||
database: 'testdb', | ||
entities: [User, FollowEntity, RestaurantInfoEntity, UserRestaurantListEntity, ReviewInfoEntity], | ||
synchronize: true, | ||
}), | ||
], | ||
}).compile(); | ||
|
||
service = module.get<AuthService>(AuthService); | ||
authService = testModule.get<AuthService>(AuthService); | ||
jwtService = testModule.get<JwtService>(JwtService); | ||
dataSource = testModule.get<DataSource>(DataSource); | ||
userService = testModule.get<UserService>(UserService); | ||
}); | ||
|
||
it("should be defined", () => { | ||
expect(service).toBeDefined(); | ||
|
||
|
||
beforeEach(async () => { | ||
const repository = dataSource.getRepository(User); | ||
await repository.query('DELETE FROM public.user'); | ||
}); | ||
}); | ||
|
||
it("회원가입 된 유저가 로그인 요청을 한 경우", async () => { | ||
|
||
const userInfoDto: UserInfoDto = { | ||
email: "[email protected]", | ||
password: "", | ||
provider: "naver", | ||
nickName: "test", | ||
region: "인천", | ||
birthdate: "1999/10/13", | ||
isMale: true, | ||
}; | ||
|
||
await userService.signup(userInfoDto); | ||
|
||
const loginRequestUser = { | ||
email: "[email protected]" | ||
} | ||
|
||
const result = await authService.signin(loginRequestUser); | ||
expect(result).toBeDefined(); | ||
expect(jwtService.verify(result.accessToken)).toBeTruthy(); | ||
expect(jwtService.verify(result.refreshToken)).toBeTruthy(); | ||
}) | ||
|
||
it("회원가입이 안된 유저가 로그인 요청을 한 경우",async () => { | ||
const loginRequestUser = { | ||
email: "[email protected]" | ||
} | ||
|
||
await expect(authService.signin(loginRequestUser)) | ||
.rejects | ||
.toThrow(HttpException); | ||
}) | ||
|
||
it("정상적인 리프레쉬 토큰을 받은 경우", async () => { | ||
const refreshToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0IiwiaWQiOi0xLCJpYXQiOjIwMTYyMzkwMjJ9.zOd1UtNxKjPqNUYGapfDgqY78M5iBEj2Ike386HTDOA" | ||
|
||
const result = await authService.checkRefreshToken(refreshToken); | ||
|
||
expect(result).toBeDefined(); | ||
expect(jwtService.verify(result.accessToken)).toBeTruthy(); | ||
}) | ||
|
||
it("비정상적인 리프레쉬 토큰을 받은 경우", async () => { | ||
const refreshToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0IiwiaWQiOjEsImlhdCI6MjAxNjIzOTAyMn0.3nRp6Qdxf5xj2C0M7-0lOURWx-dAKEjl9eS9dRoQTsA" | ||
|
||
await expect(authService.checkRefreshToken(refreshToken)) | ||
.rejects | ||
.toThrow(HttpException); | ||
}) | ||
}); |
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,9 @@ | ||
import { Global, Module } from '@nestjs/common'; | ||
import { AwsService } from './aws.service'; | ||
|
||
@Global() | ||
@Module({ | ||
providers: [AwsService], | ||
exports: [AwsService], | ||
}) | ||
export class AwsModule {} |
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,18 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { AwsService } from './aws.service'; | ||
|
||
describe('AwsService', () => { | ||
let service: AwsService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [AwsService], | ||
}).compile(); | ||
|
||
service = module.get<AwsService>(AwsService); | ||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
}); |
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 { Injectable } from "@nestjs/common"; | ||
import * as AWS from "aws-sdk"; | ||
import { awsConfig } from "objectStorage.config"; | ||
import { v4 } from "uuid"; | ||
|
||
@Injectable() | ||
export class AwsService { | ||
private s3: AWS.S3; | ||
|
||
constructor() { | ||
this.s3 = new AWS.S3({ | ||
endpoint: awsConfig.endpoint, | ||
region: awsConfig.region, | ||
credentials: { | ||
accessKeyId: awsConfig.accessKey, | ||
secretAccessKey: awsConfig.secretKey, | ||
}, | ||
}); | ||
} | ||
|
||
async uploadToS3(path: string, data: Buffer){ | ||
await this.s3.putObject({ | ||
Bucket: awsConfig.bucket, | ||
Key: path, | ||
Body: data, | ||
}).promise(); | ||
} | ||
|
||
getImageURL(path: string) { | ||
const signedUrl = this.s3.getSignedUrl("getObject", { | ||
Bucket: awsConfig.bucket, | ||
Key: path, | ||
Expires: 60, | ||
}); | ||
|
||
return signedUrl; | ||
} | ||
} |
Oops, something went wrong.