Fake Toss Payments Server
1. Outline
fake-toss-payments-server
๋ ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ์ API ๋ฅผ ํ๋ด๋ด์ด ๋ง๋ , ๊ฐ์ง ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ์ด๋ค. ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ์์ ๋ณด๋ค ์ํํ ์ฐ๋ ํ
์คํธ๋ฅผ ์ํ์ฌ ๋ง๋ค์๋ค. ํนํ ํ๋ก ํธ ์ดํ๋ฆฌ์ผ์ด์
์ ํตํ ์๊ธฐ ํ
์คํธ๊ฐ ์๋, ๋ฐฑ์๋ ์๋ฒ ์์ฒด์ ํ
์คํธ ์๋ํ ํ๋ก๊ทธ๋จ์ ํตํ ์์ ๊ฒ์ฆ์ ์ ํฉํ๋ค.
๋ํ, toss-payments-server-api ๋ ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ์ ์ฐ๋ํ ์ ์๋ SDK ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ก์จ, fake-toss-payments-server
์ ์์ค์ฝ๋๋ฅผ ํ ๋๋ก Nestia ๋ฅผ ์ด์ฉํ์ฌ ๋น๋ํ์๋ค. ๊ทธ๋ฆฌ๊ณ ์ด๋ฅผ ํตํ์ฌ ๊ฐ์ง ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ ๋ฟ ์๋๋ผ, ์ง์ง ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ, ์์ชฝ ๋ชจ๋์ ์ฐ๋ํ ์ ์๋ค.
์ฐธ๊ณ ๋ก Nestia ๋ SDK ๋ฟ ์๋๋ผ Swagger ๋ํ ๋น๋ํ ์ ์๋๋ฐ, ์ด ๋ํ fake-toss-payments-server
์ ์์ค์ฝ๋ ๋ฐ DTO ๋ฅผ ์ปดํ์ผ๋ฌ ์์ค์์ ๋ถ์ํ์ฌ ๋ง๋ค์ด์ง๋ ๊ฒ์ธ์ง๋ผ, ๊ทธ ํ๋ฆฌํฐ๊ฐ ์๋นํ๋ค. ์ด์ฉ๋ฉด ํ ์ค ํ์ด๋จผ์ธ ๊ฐ ๊ณต์ ์ ๊ณตํ๋ ๊ฐ๋ฐ์ ๊ฐ์ด๋ ๋ฌธ์๋ณด๋ค, fake-toss-payments-server
๋ก ์์ฑํ Swagger ๊ฐ ๋ ๊ฐ๋ฐ์ ์นํ์ ์ด๊ณ ์ผ๋ชฉ์์ฐํ ์ง๋?
- ์๋ฒ ์ฃผ์: http://localhost:30771
- ๋งค๋ด์ผ
- Swagger Editor: dist/swagger.json
- ์๋ฃ ๊ตฌ์กฐ: src/api/structures/ITossBilling.ts
- API ํจ์: src/api/functional/payments/index.ts
- ์์ ์ฝ๋
- ๊ฐํธ ๊ฒฐ์ : test_fake_billing_payment.ts
- ์นด๋ ๊ฒฐ์ : test_fake_card_payment.ts
- ๊ฐ์ ๊ณ์ข ๊ฒฐ์ : test_fake_virtual_account_payment.ts
- ํ๊ธ ์์์ฆ ๋ฐํ: test_fake_cash_receipt.ts
- ์ฐ๊ด ์ ์ฅ์
- samchon/typia - Superfast runtime validator
- samchon/netia - SDK generator for the NestJS
- samchon/fake-iamport-server: ๊ฐ์ง ์์ํฌํธ ์๋ฒ
import btoa from "btoa";
import toss from "toss-payments-server-api";
import { ITossPayment } from "toss-payments-server-api/lib/structures/ITossPayment";
import { assert } from "typia";
export async function test_fake_card_payment_approval(): Promise<void>
{
const connection: toss.IConnection = {
host: "http://127.0.0.1:30771", // FAKE-SERVER
// host: "https://api.tosspayments.com", // REAL-SERVER
headers: {
Authorization: `Basic ${btoa("test_ak_ZORzdMaqN3wQd5k6ygr5AkYXQGwy:")}`
}
};
const payment: ITossPayment = await toss.functional.v1.payments.key_in
(
connection,
{
// CARD INFORMATION
method: "card",
cardNumber: "1111222233334444",
cardExpirationYear: "24",
cardExpirationMonth: "03",
// ORDER INFORMATION
orderId: "some-order-id",
amount: 25_000,
// FAKE PROPERTY
__approved: false
}
);
assert<ITossPayment>(payment);
const approved: ITossPayment = await toss.functional.v1.payments.approve
(
connection,
payment.paymentKey,
{
orderId: payment.orderId,
amount: payment.totalAmount,
}
);
assert<ITossPayment>(approved);
}
2. Installation
2.1. NodeJS
๋ฐฑ์๋ ์๋ฒ ํ๋ก๊ทธ๋จ์ TypeScript ๋ก ๋ง๋ค์ด์ก์ผ๋ฉฐ, NodeJS ์์ ๊ตฌ๋๋๋ค.
๊ณ ๋ก ์ ์ผ ๋จผ์ ํ ์ผ์, NodeJS ๋ฅผ ์ค์นํ๋ ๊ฒ์ด๋ค. ์๋ ๋งํฌ๋ฅผ ์ด์ด, NodeJS ํ๋ก๊ทธ๋จ์ ๋ค์ด๋ก๋ ๋ฐ์ ํ ์ฆ๊ฐ ์ค์นํ๊ธฐ ๋ฐ๋๋ค. ์ฐธ๊ณ ๋ก NodeJS ๋ฒ์ ์ ์ด์ง๊ฐํ ๋ฎ์ ์ ์๋์ ๋ฒ์ ๋ง ์๋๋ฉด ๋๋, ๊ตฌํ์ฌ Latest ๋ฒ์ ์ ์ค์นํ ํ์๋ ์์ผ๋ฉฐ, Stable ๋ฒ์ ๋ง์ผ๋ก๋ ์ถฉ๋ถํ๋ค.
2.2. Server
NodeJS ์ ์ค์น๊ฐ ๋๋ฌ๋ค๋ฉด, ๋ฐ๋ก (๊ฐ์ง) ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ ๊ตฌ๋์ ์์ํ ์ ์๋ค.
์ ์ผ ๋จผ์ git clone
์ ํตํ์ฌ, ๋ฐฑ์๋ ํ๋ก์ ํธ๋ฅผ ๋ก์ปฌ ์ ์ฅ์์ ๋ณต์ฌํ๋๋ก ํ๋ค. ๊ทธ๋ฆฌ๊ณ ํด๋น ํด๋๋ก ์ด๋ํ์ฌ npm install
๋ช
๋ น์ด๋ฅผ ์คํํจ์ผ๋ก์จ, ๋ฐฑ์๋ ์๋ฒ๋ฅผ ๊ตฌ๋ํ๋ ๋ฐ ํ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ค์ ๋ค์ด๋ก๋ ํ๋ค. ๊ทธ๋ฆฌ๊ณ npm run build
๋ช
๋ น์ด๋ฅผ ์
๋ ฅํ์ฌ, ๋ฐฑ์๋ ์๋ฒ์ ์์ค ์ฝ๋๋ฅผ ์ปดํ์ผํ๋ค.
๋ง์ง๋ง์ผ๋ก npm run start
๋ช
๋ น์ด๋ฅผ ์คํํด์ฃผ๋ฉด, (๊ฐ์ง) ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ๊ฐ ๊ตฌ๋๋๋ค. ์ด ๊ฐ์ง ์๋ฒ๋ฅผ ํตํ์ฌ, ๊ทํ๊ฐ ๊ฐ๋ฐํ๋ ๋ฐฑ์๋ ์๋ฒ๊ฐ ๊ฒฐ์ ์ฐ๋์ ๊ด๋ จํ์ฌ ์ ๋๋ก ๊ตฌํ๋์๋ ์ง ์ถฉ๋ถํ ๊ฒ์ฆํ ํ, ์ค ์๋ฒ๋ฅผ ๋ฐฐํฌํ ๋ ์ฐ๋ ๋์ ์๋ฒ๋ฅผ ํ์ฌ์ ๊ฐ์ง ์๋ฒ์์ ์ง์ง ์๋ฒ๋ก ๋ฐ๊พธ์ด์ฃผ๋๋ก ํ์. ๊ตฌ๋ ์ค์ธ ๊ฐ์ง ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ๋ฅผ ์ค๋จํ๊ณ ์ถ๋ค๋ฉด, npm run stop
๋ช
๋ น์ด๋ฅผ ์คํํด์ฃผ๋ฉด ๋๋ค.
์ฐธ๊ณ ๋ก ๊ฐ์ง ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ๊ฐ ์ฌ์ฉํ๋ ํฌํธ ๋ฒํธ๋, ๊ฐ์ง ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ๊ฐ ์ด๋ฒคํธ๋ฅผ ์ ๋ฌํด์ฃผ๋ Webhook URL ๋ฑ์ ๋ชจ๋ src/FakeTossConfiguration.ts ์ ์ ์๋์ด์์ผ๋, ์ด๋ฅผ ์๋ง๊ฒ ์์ ํ ํ ์ปดํ์ผ ๋ฐ ๊ฐ์ง ์๋ฒ ์ฌ ๊ฐ๋์ ํด ์ฃผ๋ฉด ๋๋ค.
# CLONE REPOSITORY
git clone https://github.com/samchon/fake-toss-payments-server
cd fake-toss-payments-server
# INSTALLATION & COMPILATION
npm install
npm run build
# START SERVER & STOP SERVER
npm run start
npm run stop
๋ํ์ฌ fake-toss-payments-server
๋ npm ๋ชจ๋๋ก ์ค์นํ์ฌ ๊ตฌ๋ํ ์๋ ์๋ค.
๊ทํ์ ๋ฐฑ์๋ ์๋ฒ ํ
์คํธ ์๋ํ ํ๋ก๊ทธ๋จ์ด, fake-toss-payments-server
์ ์ค์ ๊ณผ ๊ฐ์ค ๋ฐ ํ์๋ฅผ ๋ชจ๋ ํต์ ํ๊ณ ์ ํ ๋๋, github ์ ์ฅ์๋ฅผ clone ํ๋ ๊ฒ๋ณด๋ค, ์ด์ฒ๋ผ npm ๋ชจ๋์ ์ค์นํ์ฌ import ํ๋ ๊ฒ์ด ํจ์ฌ ๋ ์๋ง๋ค.
๋ฐ๋ผ์ ๊ทํ์ ๋ฐฑ์๋ ์๋ฒ๊ฐ TypeScript ๋ด์ง JavaScript ๋ฅผ ์ฌ์ฉํ๋ค๋ฉด, github ์ ์ฅ์๋ฅผ clone ํ์ฌ fake-toss-payments-server
๋ฅผ ๋ณ๋ ๊ตฌ๋ํ๊ธฐ๋ณด๋ค, ๊ทํ์ ๋ฐฑ์๋ ์๋ฒ์์ fake-toss-payments-server
์ ๊ฐ์ค๊ณผ ํ์๋ฅผ ์ง์ ํต์ ํ๊ธฐ๋ฅผ ๊ถ์ฅํ๋ค.
// npm install --save-dev fake-toss-payments-server
import FakeToss from "fake-toss-payments-server";
async function main(): Promise<void>
{
FakeToss.FakeTossConfiguration.WEBHOOK_URL = "your-backend-webhook-api-url";
FakeToss.FakeTossConfiguration.authorize = token =>
{
return token === "test_ak_ZORzdMaqN3wQd5k6ygr5AkYXQGwy";
};
const fake: FakeToss.FakeTossBackend = new FakeToss.FakeTossBackend();
await fake.open();
await fake.close();
}
2.3. SDK
๋ณธ ๋ฐฑ์๋ ํ๋ก์ ํธ fake-toss-payments-server
๋ ๋น๋ก ํ ์ค ํ์ด๋จผ์ธ ์ API ๋ฅผ ํ๋ด๋ด์ด ๋ง๋ ๊ฐ์ง์ด์ง๋ง, ์ด๊ฒ์ ํตํ์ฌ ๋ง๋ค์ด์ง๋ SDK (Software Development Kit) ๋งํผ์ ์ง์ง์ด๋ค. ์ด SDK ๋ฅผ ์ด์ฉํ๋ฉด, fake-toss-payments-server
๋ฟ ์๋๋ผ ์ง์ง ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ์๋ ์ํํ ์ฐ๋ํ ์ ์๊ธฐ ๋๋ฌธ์ด๋ค.
๊ณ ๋ก ํ ์ค ํ์ด๋จผ์ธ ์ ์ฐ๋ํ๋ TypeScript ๊ธฐ๋ฐ ๋ฐฑ์๋ ์๋ฒ๋ฅผ ๊ฐ๋ฐํจ์ ์์ด, ๊ฐ์ง ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ fake-toss-payments-server
๋ ์ง์ ์ด์ฉ์น ์๋๋ผ๋, ์ค์ ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ์์ ์ฐ๋์ ์ํ์ฌ, SDK ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋งํผ์ ๋ฐ๋์ ์ค์นํ๊ธฐ๋ฅผ ๊ถ์ฅํ๋ ๋ฐ์ด๋ค.
npm install --save toss-payments-server-api
๋จผ์ ์ ๋ช
๋ น์ด๋ฅผ ํตํ์ฌ, ๊ทํ์ TypeScript ๊ธฐ๋ฐ ๋ฐฑ์๋ ์๋ฒ์, ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ์์ ์ฐ๋์ ์ํ SDK ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ค์นํ๋ค. ๊ทธ๋ฆฌ๊ณ ๊ฐ์ง ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ fake-toss-payments-server
๋ฅผ ๊ตฌ๋ํ์ฌ, ์ด ๊ฒ๊ณผ์ ๊ฒฐ์ ์ฐ๋์ด ์ ๋๋ก ์ด๋ฃจ์ด์ง๋ ์ง ์ถฉ๋ถํ ๋งํผ์ ๊ฒ์ฆ์ ํ๋ค. ํ
์คํธ ์๋ํ ํ๋ก๊ทธ๋จ์ ์ ์, ์ด ์์ ์ฑ์ด ์์ ๊ฒ์ฆ๋ ์ ์๋ค๋ฉด ๋๋์ฑ ์ข๋ค.
๋ง์ง๋ง์ผ๋ก ์ค ์๋ฒ๋ฅผ ๋ฐฐํฌํ๋ฉฐ, ์ฐ๋ ๋์ ์๋ฒ๋ฅผ ๊ฐ์ง์์ ์ง์ง๋ก ๊ต์ฒดํด์ฃผ๋ฉด ๋๋ค.
์ฐธ๊ณ ๋ก Nestia ๋ SDK ๋ฟ ์๋๋ผ Swagger ๋ํ ๋น๋ํ ์ ์๋๋ฐ, ์ด ๋ํ fake-toss-payments-server
์ ์์ค์ฝ๋ ๋ฐ DTO ๋ฅผ ์ปดํ์ผ๋ฌ ์์ค์์ ๋ถ์ํ์ฌ ๋ง๋ค์ด์ง๋ ๊ฒ์ธ์ง๋ผ, ๊ทธ ํ๋ฆฌํฐ๊ฐ ์๋นํ๋ค. ์ด์ฉ๋ฉด ํ ์ค ํ์ด๋จผ์ธ ๊ฐ ๊ณต์ ์ ๊ณตํ๋ ๊ฐ๋ฐ์ ๊ฐ์ด๋ ๋ฌธ์๋ณด๋ค, fake-toss-payments-server
๋ก ์์ฑํ Swagger ๊ฐ ๋ ๊ฐ๋ฐ์ ์นํ์ ์ด๊ณ ์ผ๋ชฉ์์ฐํ ์ง๋?
- ์๋ฒ ์ฃผ์: http://localhost:30771
- ๋งค๋ด์ผ
- Swagger Editor: dist/swagger.json
- ์๋ฃ ๊ตฌ์กฐ: src/api/structures/ITossBilling.ts
- API ํจ์: src/api/functional/payments/index.ts
- ์์ ์ฝ๋
- ๊ฐํธ ๊ฒฐ์ : test_fake_billing_payment.ts
- ์นด๋ ๊ฒฐ์ : test_fake_card_payment.ts
- ๊ฐ์ ๊ณ์ข ๊ฒฐ์ : test_fake_virtual_account_payment.ts
- ํ๊ธ ์์์ฆ ๋ฐํ: test_fake_cash_receipt.ts
- ์ฐ๊ด ์ ์ฅ์
- samchon/netia - Automatic SDK generator for the NestJS
- samchon/fake-iamport-server: ๊ฐ์ง ์์ํฌํธ ์๋ฒ
import btoa from "btoa";
import toss from "toss-payments-server-api";
import { ITossBilling } from "toss-payments-server-api/lib/structures/ITossBilling";
import { ITossPayment } from "toss-payments-server-api/lib/structures/ITossPayment";
import { assert } from "typia";
export async function test_fake_payment_billing_payment(): Promise<void>
{
const connection: toss.IConnection = {
host: "http://127.0.0.1:30771", // FAKE-SERVER
// host: "https://api.tosspayments.com", // REAL-SERVER
headers: {
Authorization: `Basic ${btoa("test_ak_ZORzdMaqN3wQd5k6ygr5AkYXQGwy:")}`
}
};
const billing: ITossBilling = await toss.functional.v1.billing.authorizations.card.store
(
connection,
{
customerKey: "some-consumer-key",
cardNumber: "1111222233334444",
cardExpirationYear: "28",
cardExpirationMonth: "03",
cardPassword: "99",
customerBirthday: "880311",
consumerName: "๋จ์ ํธ"
}
);
assert<ITossBilling>(billing);
const payment: ITossPayment = await toss.functional.v1.billing.pay
(
connection,
billing.billingKey,
{
method: "billing",
billingKey: billing.billingKey,
customerKey: "some-consumer-key",
orderId: "some-order-id",
amount: 10_000
}
);
assert<ITossPayment>(payment);
}
3. Development
3.1. API Interface Definition
๋ฐฑ์๋ ์๋ฒ์ ์ API ๋ฅผ ์ถ๊ฐํ๊ณ ๊ธฐ๋ฅ์ ๋ณ๊ฒฝํ๋ ์ผ ๋ฐ์๋ ๋ฌผ๋ก , API ์ปจํธ๋กค๋ฌ, ์ฆ src/controllers ์ ์ฝ๋๋ฅผ ์์ ํจ์ผ๋ก์จ ์ด๋ฃจ์ด์ง๋ค. ํ์ง๋ง fake-toss-payments-server
๋ ์ ๊ท API ๊ฐ ํ์ํ๊ฑฐ๋ ํน์ ๊ธฐ์กด API ์ ๋ณ๊ฒฝ ํ์ํ ๋, ๋๋ธ Main Program ์ ์ฝ๋๋ถํฐ ์์ฑํ๊ณ ๋ณด๋ ๊ฒ์ ๋งค์ฐ ์ง์ํ๋ค. ๊ทธ ๋์ fake-toss-payments-server
๋ API ์ ์ธํฐํ์ด์ค๋ง์ ๋จผ์ ์ ์ํ๊ณ , Main Program ์ ๊ตฌํ์ ๋์ค์ผ๋ก ๋ฏธ๋ฃจ๋ ๊ฒ์ ์งํฅํ๋ค.
๋ฐ๋ผ์ fake-toss-payments-server
์ ์ API ๋ฅผ ์ถ๊ฐํ๋ ค๊ฑฐ๋ , src/controllers ์ ์ API ์ ์ธํฐํ์ด์ค๋ง์ ๋จผ์ ์ ์ํด์ค๋ค. ๊ณง์ด์ด npm run sdk
๋ npm run api
๋ช
๋ น์ด๋ฅผ ํตํ์ฌ, API Library ๋ฅผ ๋น๋ํ๋ค. ๊ฒฝ์ฐ์ ๋ฐ๋ผ์๋ ํ๋ก ํธ ํ๋ก์ ํธ์์ ๋์ ๊ฐ๋ฐ์ ์ํ์ฌ, ์๋ก์ด ๋น๋๋ SDK ๋ฅผ ๊ทธ๋๋ก npm publish
ํด ๋ฒ๋ ค๋ ์ข๋ค.
์ดํ ๋ก์ปฌ์์ ์๋ก์ด ์์ฑ๋ SDK ์ ํด๋น API ๋ฅผ ์ด์ฉ, ์ ์ฆ์ผ์ด์ค ์๋๋ฆฌ์ค๋ฅผ ํ ์คํธ ์๋ํ ํ๋ก๊ทธ๋จ์ผ๋ก ์์ฑํ๋ค. ๊ทธ๋ฆฌ๊ณ Main Program ์ ์ ์ํ๋ฉฐ, ์์ ์์ฑํด ๋ ํ ์คํธ ์๋ํ ํ๋ก๊ทธ๋จ์ผ๋ก ์์ ๊ฒ์ฆํ๋ค. ๋ง์ง๋ง์ผ๋ก Main Program ๊น์ง ์์ฑ๋๋ฉด ์ด๋ฅผ ๋ฐฐํฌํ๋ฉด ๋๋ค.
์ดํ fake-toss-payments-server
์ ๊ฐ๋ต์ ์ธ ๊ฐ๋ฐ ์์๋ฅผ ์์ฝํ๋ฉด ์๋์ ๊ฐ๋ค.
- API Interface Definition
- API Library (SDK) ๋น๋
- Test Automation Program ์ ์
- Main Program ์ ์ ๋ฐ ํ ์คํธ ์๋ํ ํ๋ก๊ทธ๋จ์ ์ด์ฉํ ์์ ๊ฒ์ฆ
- DEV ๋ฐ REAL ์๋ฒ์ ๋ฐฐํฌ
3.2. Test Automation Program
npm run test
์๋ก์ด ๊ฐ๋ฐํ API ์ธํฐํ์ด์ค ์ ์๋ฅผ ๋ง์ณค๋ค๋ฉด, ๊ทธ ๋ค์์ ํ ์ผ์ ๋ฐ๋ก ํด๋น API ์ ๋ํ ์ ์ฆ์ผ์ด์ค ์๋๋ฆฌ์ค๋ฅผ ์ธ์ฐ๊ณ ์ด๋ฅผ ํ ์คํธ ์๋ํ ํ๋ก๊ทธ๋จ์ ๋ง๋ค์ด, ํฅํ Main Program ์ ์์ ์ด๋ฅผ ์์ ๊ฒ์ฆํ ์ ์๋ ์๋จ์ ๊ตฌ๋นํด๋๋ ๊ฒ์ด๋ค - TDD (Test Driven Development).
๊ทธ๋ฆฌ๊ณ ๋ณธ ํ๋ก์ ํธ๋ npm run test
๋ผ๋ ๋ช
๋ น์ด๋ฅผ ํตํ์ฌ, ์๋ฒ ํ๋ก๊ทธ๋จ์ ์ผ์ฒด ๊ธฐ๋ฅ ๋ฐ ์ ์ฑ
๋ฑ์ ๋ํ์ฌ ๊ฒ์ฆํ ์ ์๋, ํ
์คํธ ์๋ํ ํ๋ก๊ทธ๋จ์ ๊ตฌ๋ํด ๋ณผ ์ ์๋ค. ๋ง์ฝ ์๋ก์ด ํ
์คํธ ๋ก์ง์ ์ถ๊ฐํ๊ณ ์ถ๋ค๋ฉด, test/features ํด๋์ ์ ๋นํ ์์น์ ์ ts
ํ์ผ์ ํ๋ ๋ง๋ค๊ณ , test_
๋ก ์์ํ๋ ํจ์๋ฅผ ํ๋ ๋ง๋ค์ด ๊ทธ ์์ ํ
์คํธ ๋ก์ง์ ์์ฑํ ํ, ์ด๋ฅผ export
์ฌ๋ฒ์ ์ด์ฉํ์ฌ ๋ฐฐ์ถํด์ฃผ๋ฉด ๋๋ค. ์ด์ ๋ํ ์์ธํ ๋ด์ฉ์ test/features ํด๋์ ๋ค์ด์๋ ๋ชจ๋ ts
ํ์ผ ํ๋ ํ๋๊ฐ ๋ค ์ข์ ์์ ๊ฒฉ์ด๋, ์ด๋ฅผ ์ฐธ๊ณ ํ๋๋ก ํ๋ค.
์ฐธ๊ณ ๋ก npm run test
๋ช
๋ น์ด๋ฅผ ์คํํ ๋๋ง๋ค, test/features ํด๋ ๋ด์ ๋ฑ๋ก๋ ๋ชจ๋ ํ๋ก๊ทธ๋จ์ ์คํํ๊ฒ ๋๋ค. ํ์ง๋ง ์ด๋ฐ ์์ entire level test ๊ฐ ๋งค๋ฒ ํ์ํ ๊ฒ์ ์๋ ๊ฒ์ด๋ค. ์๋ก ๊ฐ๋ฐํ ๊ธฐ๋ฅ์ด ๊ทนํ ์ผ๋ถ ์์์ ๊ตญํ๋์ด ๋ถ๋ถ ํ
์คํธ๊ฐ ํ์ํ๋ค๋ฉด, ์๋ ์ต์
๊ฐ์ ์ฐธ์กฐ, --include
๋ --exclude
ํ๊ทธ๋ฅผ ์ฌ์ฉํ์ฌ ์๊ฐ์ ์ ์ฝํ๋๋ก ํ์.
- options
include
: ํน์ ๋จ์ด๊ฐ ํฌํจ๋ ํ ์คํธ ํจ์๋ง ์คํexclude
: ํน์ ๋จ์ด๊ฐ ํฌํจ๋ ํ ์คํธ ํจ์ ์ ์ธ
3.3. Main Program
API ์ธํฐํ์ด์ค๋ฅผ ์ ์ํ๊ณ ๊ทธ์ ๊ด๋ จ๋ ํ ์คํธ ์๋ํ ํ๋ก๊ทธ๋จ์ ์ ์ํ์๋ค๋ฉด, ๋ง์ง๋ง์ผ๋ก ๋จ์ ์ผ์ ๋ฐ๋ก ์๋ฒ์ ๋ฉ์ธ ํ๋ก๊ทธ๋จ์ ์์ฑ, ํด๋น API ๋ฅผ ์์ฑํ๋ ๊ฒ์ด๋ค. ์์ ์ ์ํ API ์ธํฐํ์ด์ค ๋ฉ์๋ ๋ด์, ์์ธ ๊ตฌํ ์ฝ๋๋ฅผ ์์ฑํ๊ณ , ์ด๋ฅผ ํ ์คํธ ์๋ํ ํ๋ก๊ทธ๋จ์ ํตํ์ฌ ์์ ๊ฒ์ฆํ๋๋ก ํ์.
๋จ, ๋ชจ๋ ์์ค ์ฝ๋๋ฅผ ์ ๋ถ API ์ปจํธ๋กค๋ฌ์ ๋ฉ์๋์ ์์ฑํ๋ ์ฐ๋ ๋ฒํ์ง ์๊ธฐ๋ฅผ ๋ฐ๋๋ค. API ์ปจํธ๋กค๋ฌ๋ ๋จ์ง ๋งค๊ฐ์ฒด + a ์ ์ญํ ๋ง์ ํด์ผ ํ ๋ฟ์ด๋ฉฐ, ์ฃผ ์์ค ์ฝ๋๋ src ํด๋ ๋ด ๊ฐ ํด๋์ ๋ถ๋ฅ์ ๋ฐ๋ผ ์๋ง๊ฒ ๋๋์ด ์์ฑ๋์ด์ผ ํ๋ค.
4. Appendix
4.1. Expiration
fake-toss-payments-server
๋ ๊ฒฐ์ ๋ฐ์ดํฐ๋ฅผ ๋ฉ๋ชจ๋ฆฌ์ ์์ ๊ธฐ๋กํ๋ค.
์๋ํ๋ฉด fake-toss-payments-server
๋ ํ ์ค ํ์ด๋จผ์ธ ์๋ฒ์ API ๋ฅผ ํ๋ด๋ด์ด ๋ง๋ ๊ฐ์ง ์๋ฒ๋ก์จ, ๊ฐ๋ฐ ๋จ๊ณ์์ ์ฐ์ด๋ ์์ ์์คํ
์ ๋ถ๊ณผํ๊ธฐ ๋๋ฌธ์ด๋ค. ๋ฐ๋ผ์ fake-toss-payments-server
์ ์์ฑ๋ ๊ฒฐ์ ๋ด์ง ์นด๋ ์ ๋ณด๋ค์ ๋ชจ๋ ํ
์คํธ ์ฉ๋๋ก ์์ฑ๋ ์์ ๋ ์ฝ๋๊ฐ ๋ถ๊ณผํ๊ธฐ์, ๊ตฌํ์ฌ ์ด๋ฅผ DB ๋ ๋ก์ปฌ ๋์คํฌ์ ์ ์ฅํ์ฌ ์๊ตฌ ๋ณด์กดํ ์ด์ ๊ฐ ์๋ค.
์ด์ fake-toss-payments-server
๋ ๊ฒฐ์ ๋ฐ์ดํฐ๋ฅผ ๋ฉ๋ชจ๋ฆฌ์ ์์๋ก ๊ธฐ๋กํ๋ฉฐ, ํ ํธ์ผ๋ก ๊ทธ ์๋ ๋ฐ ๋ณด์กด ๊ธฐํ์ ํ๋๋ฅผ ๋์ด, ์ฌ์ด ๋ฉ๋ชจ๋ฆฌ ๋ถ์กฑ ํ์์ด ์ผ์ด๋์ง ์๋๋ก ํ๊ณ ์๋ค. ์ด๋ฌํ ์์ ๋ฐ์ดํฐ ๋ง๋ฃ ์ ๋ณด๋ src/FakeTossConfiguration.ts ํ์ผ์ EXPIRATION
๋ณ์์ ์ ์๋์ด์์ผ๋ฉฐ, ๊ฒฐ์ ๋ฐ ๊ฐํธ ์นด๋ ๊ฒฐ์ ๋ฑ๋ก ๋ฐ์ดํฐ๋ ๋ชจ๋ src/providers/FakeTossStorage.ts ์์ ๊ด๋ฆฌ๋๋ค.
- ์์ ๋ฐ์ดํฐ ๋ง๋ฃ ์ ๋ณด: src/FakeTossConfiguration.ts
- ์์ ๋ฐ์ดํฐ ์ ์ฅ์: src/providers/FakeTossStorage.ts
- ์์ ๋ฐ์ดํฐ ์ปจํ ์ด๋: src/utils/VolatileMap.ts
ํน์ฌ
fake-toss-payments-server
๋ฅผ ์ฌ์ฉํ๋ ๋ฐฑ์๋ ์์คํ ์ด ์ ๋ฒ ํฌ๊ณ ๊ทธ ๋คํธ์ํฌ ํ๊ฒฝ ๊ตฌ์ฑ์ด ๋งค์ฐ ๋ณต์กํ์ฌ,fake-toss-payments-server
๋ฅผ ๋ ๋ฆฝ ์๋ฒ๋ก ๋ฐฐํฌํ๊ณ , ๊ฐ์์ ๊ฒฐ์ ๋ ์ฝ๋ ๋ํ DB ์ ์ ์ฅํด์ผ ํ๋ฉฐ, ๋ฌด์ค๋จ ๋ฐฐํฌ ์์คํ ๋ํ ํ์ํ์ง ์์๊น?์ค๋ง ์์ ๊ฐ์ ๊ฒฝ์ฐ๊ฐ ์์ด๋ด์ผ ์ผ๋ง๋ ์๊ฒ ๋ ์ถ์ด ๊ณต๊ฐ ์ ์ฅ์์ ์ฌ๋ ค๋์ง๋ ์์์ผ๋,
fake-toss-payments-server
๊ฐ ๊ฒฐ์ ๋ฐ์ดํฐ๋ฅผ VolatileMap ์ด ์๋ DB ์ ์ ์ฅํ๊ณ , ํ์๋ง์์์กฐ์ฐจ ๋์ํ ์ ์๋ ๋ฌด์ค๋จ ์ ๋ฐ์ดํธ ๋ฐ ๋ฐฐํฌ ์์คํ ์ ๋ฐ๋ก ๊ตฌ๋นํด ๋ ๊ฒ์ด ์๋ค.๋ฐ๋ผ์ ์์ ๊ฐ์ ํํ์
fake-toss-payments-server
๊ฐ ํ์ํ๋ค๋ฉด, ์ผ๋ง๋ ์ง ์ฐ๋ฝํ๊ธฐ ๋ฐ๋๋ค. ์ฆ์ ์ ์์๋ฅผ ์ถฉ๋นํ๋ ์๋ฃจ์ ์ ๊ณต๊ธํด ์ค ์ ์์ผ๋ฉฐ, ๋ง์ผ ์ด๋ฌํ ์์ฒญ์ด ์ ๋ฒ ๋ง์ ๊ฒฝ์ฐ, ๋ณ๋์ ๋ธ๋์น๋ฅผ ๋ง๋ค์ด ๋ฐฐํฌํด ๋ณผ ์๋๋ ์๋ค.# WHEN STARTING THE MASTE SERVER npm run start:updator:master npm run start # WHEN STARTING A SLAVE SERVER npm run start:updator:slave npm run start # WHEN RUN UPDATE COMMAND IN THE CLIENT SIDE npm run update
4.2. Typia
// RUNTIME VALIDATORS
export function is<T>(input: unknown): input is T; // returns boolean
export function assert<T>(input: unknown): T; // throws TypeGuardError
export function validate<T>(input: unknown): IValidation<T>; // detailed
export const customValidators: CustomValidatorMap; // can add custom validators
// JSON
export function application<T>(): IJsonApplication; // JSON schema
export function assertParse<T>(input: string): T; // type safe parser
export function assertStringify<T>(input: T): string; // safe and faster
// +) isParse, validateParse
// +) stringify, isStringify, validateStringify
// MISC
export function random<T>(g?: Partial<IRandomGenerator>): Primitive<T>;
Typia is a transformer library supporting below features:
- Super-fast Runtime Validators
- Safe JSON parse and fast stringify functions
- JSON schema generator
- Random data generator
Note
- Only one line required, with pure TypeScript type
- Runtime validator is 20,000x faster than
class-validator
- JSON serialization is 200x faster than
class-transformer
4.3. Nestia
Nestia is a set of helper libraries for NestJS, supporting below features:
@nestia/core
: super-fast decorators@nestia/sdk
:- SDK generator for clients
- Swagger generator evolved than ever
- Automatic E2E test functions generator
nestia
: just CLI (command line interface) tool
Note
- Only one line required, with pure TypeScript type
- Runtime validator is 20,000x faster than
class-validator
- JSON serialization is 200x faster than
class-transformer
- SDK is similar with tRPC, but much advanced