-
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 #215 from boostcampwm2023/feat/211-purchase-design…
…-list-api [Feat] 유료 디자인 구매 목록 API 구현
- Loading branch information
Showing
7 changed files
with
209 additions
and
4 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
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,98 @@ | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
import { INestApplication } from "@nestjs/common"; | ||
import * as request from "supertest"; | ||
import { ValidationPipe } from "@nestjs/common"; | ||
import { typeORMTestConfig } from "src/configs/typeorm.test.config"; | ||
import { TypeOrmModule } from "@nestjs/typeorm"; | ||
import { RedisModule } from "@liaoliaots/nestjs-redis"; | ||
import { clearUserDb } from "src/utils/clearDb"; | ||
import { UsersRepository } from "src/auth/users.repository"; | ||
import { AuthModule } from "src/auth/auth.module"; | ||
import { PurchaseModule } from "src/purchase/purchase.module"; | ||
import { User } from "src/auth/users.entity"; | ||
|
||
describe("[디자인 구매 내역 조회] /purchase/design GET e2e 테스트", () => { | ||
let app: INestApplication; | ||
let accessToken: string; | ||
|
||
beforeAll(async () => { | ||
const moduleFixture: TestingModule = await Test.createTestingModule({ | ||
imports: [ | ||
TypeOrmModule.forRoot(typeORMTestConfig), | ||
RedisModule.forRoot({ | ||
readyLog: true, | ||
config: { | ||
host: "223.130.129.145", | ||
port: 6379, | ||
}, | ||
}), | ||
PurchaseModule, | ||
AuthModule, | ||
], | ||
providers: [UsersRepository], | ||
}).compile(); | ||
|
||
let usersRepository = moduleFixture.get<UsersRepository>(UsersRepository); | ||
|
||
await clearUserDb(moduleFixture, usersRepository); | ||
|
||
app = moduleFixture.createNestApplication(); | ||
app.enableCors(); | ||
app.useGlobalPipes(new ValidationPipe()); | ||
|
||
await app.init(); | ||
|
||
const signInPost = await request(app.getHttpServer()) | ||
.post("/auth/signin") | ||
.send({ | ||
userId: "commonUser", | ||
password: process.env.COMMON_USER_PASS, | ||
}); | ||
|
||
accessToken = signInPost.body.accessToken; | ||
|
||
// 1000 별가루 충전 | ||
const user = await User.findOne({ where: { userId: "commonUser" } }); | ||
user.credit = 1000; | ||
await user.save(); | ||
|
||
// 디자인 구매 | ||
await request(app.getHttpServer()) | ||
.post("/purchase/design") | ||
.set("Authorization", `Bearer ${accessToken}`) | ||
.send({ | ||
domain: "GROUND", | ||
design: "GROUND_GREEN", | ||
}); | ||
|
||
await request(app.getHttpServer()) | ||
.post("/purchase/design") | ||
.set("Authorization", `Bearer ${accessToken}`) | ||
.send({ | ||
domain: "GROUND", | ||
design: "GROUND_MOCHA", | ||
}); | ||
}); | ||
|
||
afterAll(async () => { | ||
await app.close(); | ||
}); | ||
|
||
it("정상 요청 시 200 OK 응답", async () => { | ||
const getResponse = await request(app.getHttpServer()) | ||
.get("/purchase/design") | ||
.set("Authorization", `Bearer ${accessToken}`) | ||
.expect(200); | ||
|
||
expect(getResponse.body).toStrictEqual({ | ||
ground: ["#254117", "#493D26"], | ||
sky: [], | ||
}); | ||
}); | ||
|
||
it("유효하지 않은 토큰 요청 시 401 Unauthorized 응답", async () => { | ||
const getResponse = await request(app.getHttpServer()) | ||
.get("/purchase/design") | ||
.expect(401); | ||
}); | ||
}); |
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,32 @@ | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
import { TypeOrmModule } from "@nestjs/typeorm"; | ||
import { User } from "src/auth/users.entity"; | ||
import { typeORMTestConfig } from "src/configs/typeorm.test.config"; | ||
import { Purchase } from "src/purchase/purchase.entity"; | ||
import { PurchaseRepository } from "src/purchase/purchase.repository"; | ||
|
||
describe("PurchaseRepository 통합 테스트", () => { | ||
let purchaseRepository: PurchaseRepository; | ||
|
||
beforeAll(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
imports: [TypeOrmModule.forRoot(typeORMTestConfig)], | ||
providers: [PurchaseRepository], | ||
}).compile(); | ||
|
||
purchaseRepository = module.get<PurchaseRepository>(PurchaseRepository); | ||
}); | ||
|
||
describe("getDesignPurchaseList 메서드", () => { | ||
it("메서드 정상 요청", async () => { | ||
const user = await User.findOne({ where: { userId: "commonUser" } }); | ||
|
||
const purchaseList = await Purchase.find({ | ||
where: { user: { userId: user.userId } }, | ||
}); | ||
const result = await purchaseRepository.getDesignPurchaseList(user); | ||
|
||
expect(result).toStrictEqual(purchaseList); | ||
}); | ||
}); | ||
}); |
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,33 @@ | ||
import { Test, TestingModule } from "@nestjs/testing"; | ||
import { TypeOrmModule } from "@nestjs/typeorm"; | ||
import { User } from "src/auth/users.entity"; | ||
import { typeORMTestConfig } from "src/configs/typeorm.test.config"; | ||
import { PurchaseRepository } from "src/purchase/purchase.repository"; | ||
import { PurchaseService } from "src/purchase/purchase.service"; | ||
|
||
describe("PurchaseService 통합 테스트", () => { | ||
let purchaseService: PurchaseService; | ||
|
||
beforeAll(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
imports: [TypeOrmModule.forRoot(typeORMTestConfig)], | ||
providers: [PurchaseService, PurchaseRepository], | ||
}).compile(); | ||
|
||
purchaseService = module.get<PurchaseService>(PurchaseService); | ||
}); | ||
|
||
describe("getDesignPurchaseList 메서드", () => { | ||
it("메서드 정상 요청", async () => { | ||
const user = await User.findOne({ where: { userId: "commonUser" } }); | ||
|
||
// 테스트 DB 독립 시 수정 필요 | ||
const result = await purchaseService.getDesignPurchaseList(user); | ||
|
||
expect(result).toStrictEqual({ | ||
ground: ["#254117", "#493D26"], | ||
sky: [], | ||
}); | ||
}); | ||
}); | ||
}); |