-
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 #217 from boostcampwm2023/test/216-naver-and-purch…
…ase-test [Test] 네이버 로그인, 유료 디자인 구매 관련 테스트 코드 작성
- Loading branch information
Showing
9 changed files
with
150 additions
and
12 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
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ import { AuthCredentialsDto } from "src/auth/dto/auth-credential.dto"; | |
import { Request } from "express"; | ||
import { AccessTokenDto } from "src/auth/dto/auth-access-token.dto"; | ||
import { NotFoundException } from "@nestjs/common"; | ||
import { providerEnum } from "src/utils/enum"; | ||
|
||
describe("AuthService 통합 테스트", () => { | ||
let authService: AuthService; | ||
|
@@ -132,4 +133,21 @@ describe("AuthService 통합 테스트", () => { | |
expect(result).toBeInstanceOf(AccessTokenDto); | ||
}); | ||
}); | ||
|
||
describe("naverSignIn 메서드", () => { | ||
it("메서드 정상 요청", async () => { | ||
const user = new User(); | ||
user.email = "[email protected]"; | ||
user.userId = "test*naver"; | ||
user.nickname = "test"; | ||
user.password = "test"; | ||
user.provider = providerEnum.NAVER; | ||
|
||
const request = { ip: "111.111.111.111" } as Request; | ||
|
||
const result = await authService.naverSignIn(user, request); | ||
|
||
expect(result).toBeInstanceOf(AccessTokenDto); | ||
}); | ||
}); | ||
}); |
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,31 +1,68 @@ | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
import { TypeOrmModule } from "@nestjs/typeorm"; | ||
import { User } from "src/auth/users.entity"; | ||
import { UsersRepository } from "src/auth/users.repository"; | ||
import { typeORMTestConfig } from "src/configs/typeorm.test.config"; | ||
import { PurchaseDesignDto } from "src/purchase/dto/purchase.design.dto"; | ||
import { Purchase } from "src/purchase/purchase.entity"; | ||
import { PurchaseRepository } from "src/purchase/purchase.repository"; | ||
import { PurchaseService } from "src/purchase/purchase.service"; | ||
import { clearUserDb } from "src/utils/clearDb"; | ||
import { DataSource } from "typeorm"; | ||
|
||
describe("PurchaseService 통합 테스트", () => { | ||
let purchaseService: PurchaseService; | ||
let user: User; | ||
let usersRepository: UsersRepository; | ||
let dataSource: DataSource; | ||
|
||
beforeAll(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
const moduleFixture: TestingModule = await Test.createTestingModule({ | ||
imports: [TypeOrmModule.forRoot(typeORMTestConfig)], | ||
providers: [PurchaseService, PurchaseRepository], | ||
providers: [PurchaseService, PurchaseRepository, UsersRepository], | ||
}).compile(); | ||
|
||
purchaseService = module.get<PurchaseService>(PurchaseService); | ||
dataSource = moduleFixture.get<DataSource>(DataSource); | ||
purchaseService = moduleFixture.get<PurchaseService>(PurchaseService); | ||
|
||
usersRepository = await moduleFixture.get<UsersRepository>(UsersRepository); | ||
await clearUserDb(moduleFixture, usersRepository); | ||
|
||
user = new User(); | ||
user.userId = "purchaseTest"; | ||
user.password = "purchaseTest"; | ||
user.nickname = "purchaseTest"; | ||
user.email = "[email protected]"; | ||
await user.save(); | ||
}); | ||
|
||
describe("getDesignPurchaseList 메서드", () => { | ||
afterAll(async () => { | ||
await dataSource.destroy(); | ||
}); | ||
|
||
describe("purchaseDesign 메서드", () => { | ||
it("메서드 정상 요청", async () => { | ||
const user = await User.findOne({ where: { userId: "commonUser" } }); | ||
const purchaseDesignDto = new PurchaseDesignDto(); | ||
purchaseDesignDto.domain = "GROUND"; | ||
purchaseDesignDto.design = "GROUND_GREEN"; | ||
user.credit = 500; | ||
await user.save(); | ||
|
||
await purchaseService.purchaseDesign(user, purchaseDesignDto); | ||
}); | ||
|
||
// 별가루가 부족한 경우 테스트 | ||
// 이미 존재하는 디자인에 대한 경우 테스트 | ||
// 위 두 테스트는 테스트 DB 데이터 삭제 오류의 문제로 테스트 DB 독립화 이후 구현 예정 | ||
}); | ||
|
||
describe("getDesignPurchaseList 메서드", () => { | ||
it("메서드 정상 요청", async () => { | ||
// 테스트 DB 독립 시 수정 필요 | ||
const result = await purchaseService.getDesignPurchaseList(user); | ||
|
||
expect(result).toStrictEqual({ | ||
ground: ["#254117", "#493D26"], | ||
ground: ["#254117"], | ||
sky: [], | ||
}); | ||
}); | ||
|
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,12 @@ | ||
{ | ||
"moduleFileExtensions": ["js", "json", "ts"], | ||
"rootDir": ".", | ||
"testEnvironment": "node", | ||
"testRegex": ".unit-spec.ts$", | ||
"transform": { | ||
"^.+\\.(t|j)s$": "ts-jest" | ||
}, | ||
"moduleNameMapper": { | ||
"^src/(.*)$": "<rootDir>/../src/$1" | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
BE/src/auth/dto/auth-credential.dto.spec.ts → ...est/unit/auth-credential.dto.unit-spec.ts
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
8 changes: 6 additions & 2 deletions
8
BE/src/diaries/dto/diaries.dto.spec.ts → BE/test/unit/diaries.dto.unit-spec.ts
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { validate } from "class-validator"; | ||
import { PurchaseDesignDto } from "../../src/purchase/dto/purchase.design.dto"; | ||
|
||
describe("PurchaaseDesignDto 단위 테스트", () => { | ||
let purchaseDesignDto; | ||
|
||
beforeEach(() => { | ||
purchaseDesignDto = new PurchaseDesignDto(); | ||
}); | ||
|
||
it("모든 값이 유효한 요청 시 성공", async () => { | ||
purchaseDesignDto.domain = "GROUND"; | ||
purchaseDesignDto.design = "GROUND_GREEN"; | ||
|
||
const errors = await validate(purchaseDesignDto); | ||
|
||
expect(errors).toHaveLength(0); | ||
}); | ||
|
||
it("빈 구매 항목 종류로 요청 시 실패", async () => { | ||
purchaseDesignDto.domain = ""; | ||
purchaseDesignDto.design = "GROUND_GREEN"; | ||
|
||
const errors = await validate(purchaseDesignDto); | ||
expect(errors[0].constraints.isNotEmpty).toBe( | ||
"구매 항목 종류는 비어있지 않아야 합니다.", | ||
); | ||
}); | ||
|
||
it("domainEnum 값이 아닌 구매 항목 종류로 요청 시 실패", async () => { | ||
purchaseDesignDto.domain = "실패"; | ||
purchaseDesignDto.design = "GROUND_GREEN"; | ||
|
||
const errors = await validate(purchaseDesignDto); | ||
expect(errors[0].constraints.isIn).toBe( | ||
"적절하지 않은 구매 항목 종류 양식입니다.", | ||
); | ||
}); | ||
|
||
it("빈 디자인으로 요청 시 실패", async () => { | ||
purchaseDesignDto.domain = "GROUND"; | ||
purchaseDesignDto.design = ""; | ||
|
||
const errors = await validate(purchaseDesignDto); | ||
|
||
expect(errors[0].constraints.isNotEmpty).toBe( | ||
"디자인은 비어있지 않아야 합니다.", | ||
); | ||
}); | ||
|
||
it("designEnum 값이 아닌 디자인으로 요청 시 실패", async () => { | ||
purchaseDesignDto.domain = "GROUND"; | ||
purchaseDesignDto.design = "실패"; | ||
|
||
const errors = await validate(purchaseDesignDto); | ||
|
||
expect(errors[0].constraints.isIn).toBe("적절하지 않은 디자인 양식입니다."); | ||
}); | ||
}); |
2 changes: 1 addition & 1 deletion
2
BE/src/auth/dto/users.dto.spec.ts → BE/test/unit/users.dto.unit-spec.ts
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