Skip to content

Commit

Permalink
Merge pull request #269 from boostcampwm2023/test/230-test-db-refactor
Browse files Browse the repository at this point in the history
[Test] 백엔드 통합 테스트 코드 트랜잭션 반영 및 테스트 DB 더미데이터 활용
  • Loading branch information
mingxoxo authored Dec 14, 2023
2 parents eff45fd + cbf0a32 commit c8cff6b
Show file tree
Hide file tree
Showing 20 changed files with 830 additions and 592 deletions.
16 changes: 16 additions & 0 deletions BE/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions BE/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typeorm-transactional-tests": "^2.0.0",
"typescript": "^5.1.3"
},
"jest": {
Expand Down
2 changes: 1 addition & 1 deletion BE/src/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class AuthController {
@UseGuards(ExpiredOrNotGuard)
@HttpCode(204)
async signOut(@GetUser() user: User): Promise<void> {
await this.authService.signOut(user);
await this.authService.signOut(user.userId);
}

@Post("/reissue")
Expand Down
18 changes: 16 additions & 2 deletions BE/src/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Redis } from "ioredis";
import { InjectRedis } from "@liaoliaots/nestjs-redis";
import { Request } from "express";
import { providerEnum } from "src/utils/enum";
import * as jwt from "jsonwebtoken";

@Injectable()
export class AuthService {
Expand Down Expand Up @@ -45,8 +46,8 @@ export class AuthService {
return new LoginResponseDto(accessToken, nickname);
}

async signOut(user: User): Promise<void> {
await this.redisClient.del(user.userId);
async signOut(userId: string): Promise<void> {
await this.redisClient.del(userId);
}

async reissueAccessToken(request: Request): Promise<LoginResponseDto> {
Expand Down Expand Up @@ -121,4 +122,17 @@ export class AuthService {

return accessToken;
}

extractJwtToken(accessToken: string) {
const jwtPayload = jwt.verify(
accessToken,
process.env.JWT_SECRET,
) as jwt.JwtPayload;

return jwtPayload;
}

async getRefreshTokenFromRedis(key: string): Promise<string> {
return this.redisClient.get(key);
}
}
12 changes: 12 additions & 0 deletions BE/src/diaries/dto/diaries.sentiment.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,16 @@ export class SentimentDto {
neutralRatio: number;
negativeRatio: number;
sentiment: sentimentStatus;

constructor(
positiveRatio: number,
neutralRatio: number,
negativeRatio: number,
sentiment: sentimentStatus,
) {
this.positiveRatio = positiveRatio;
this.neutralRatio = neutralRatio;
this.negativeRatio = negativeRatio;
this.sentiment = sentiment;
}
}
7 changes: 3 additions & 4 deletions BE/src/purchase/purchase.repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Purchase } from "./purchase.entity";
import { PurchaseDesignDto } from "./dto/purchase.design.dto";
import { User } from "src/auth/users.entity";
import { designEnum, domainEnum } from "src/utils/enum";

Expand All @@ -9,7 +8,7 @@ export class PurchaseRepository {
domain: domainEnum,
design: designEnum,
): Promise<void> {
const purchase = await Purchase.create();
const purchase = Purchase.create();

purchase.domain = domain;
purchase.design = design;
Expand All @@ -18,7 +17,7 @@ export class PurchaseRepository {
await purchase.save();
}

async getDesignPurchaseList(user: User) {
return Purchase.find({ where: { user: { userId: user.userId } } });
async getDesignPurchaseList(userId: string): Promise<Purchase[]> {
return Purchase.find({ where: { user: { userId } } });
}
}
5 changes: 3 additions & 2 deletions BE/src/purchase/purchase.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ export class PurchaseService {
}

async getDesignPurchaseList(user: User): Promise<PurchaseListDto> {
const purchaseList =
await this.purchaseRepository.getDesignPurchaseList(user);
const purchaseList = await this.purchaseRepository.getDesignPurchaseList(
user.userId,
);

const groundPurchase = [];
purchaseList.forEach((purchase) => {
Expand Down
11 changes: 3 additions & 8 deletions BE/src/shapes/shapes.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,9 @@ export class ShapesRepository {
return found;
}

async getShapesByUser(user: User): Promise<Shape[]> {
const shapeList: Shape[] = await Shape.find({
where: { user: { userId: user.userId } },
async getShapesByUser(userId: string): Promise<Shape[]> {
return Shape.find({
where: { user: { userId } },
});
if (!shapeList) {
throw new NotFoundException("존재하지 않는 사용자입니다.");
}

return shapeList;
}
}
2 changes: 1 addition & 1 deletion BE/src/shapes/shapes.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class ShapesService {

if (user.userId !== "commonUser") {
shapeList = defaultShapeList.concat(
await this.shapesRepository.getShapesByUser(user),
await this.shapesRepository.getShapesByUser(user.userId),
);
} else {
shapeList = defaultShapeList;
Expand Down
2 changes: 1 addition & 1 deletion BE/src/tags/tags.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NotFoundException } from "@nestjs/common";

export class TagsRepository {
async createTag(name: string): Promise<Tag> {
const tag = await Tag.create({ name });
const tag = Tag.create({ name });
await tag.save();

return tag;
Expand Down
Loading

0 comments on commit c8cff6b

Please sign in to comment.