Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 30 additions & 19 deletions infra/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ networks:
atdd-net:
external: true

x-db-env: &db_env
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ν”Όλ“œλ°± 반영 πŸ‘

SPRING_DATASOURCE_URL: "jdbc:mysql://atdd-db:3306/atdd?useSSL=false&characterEncoding=utf8&allowPublicKeyRetrieval=true&serverTimezone=Asia/Seoul"
SPRING_DATASOURCE_USERNAME: "root"
SPRING_DATASOURCE_PASSWORD: "secret"

x-wait-db: &wait_db_cmd >
sh -c "until nc -z atdd-db 3306; do echo 'waiting db...'; sleep 2; done;
java $JAVA_OPTS -jar /app/app.jar"

services:
kiosk:
build:
Expand All @@ -20,13 +29,10 @@ services:
KIOSK_ADMIN_AUTH_PASSWORD: "admin123"
KIOSK_ADMIN_AUTH_COOKIE_NAME: "AUTH_TOKEN"
RESERVATION_BASE_URL: "http://reservation:8080"
SPRING_DATASOURCE_URL: "jdbc:mysql://atdd-db:3306/atdd?useSSL=false&characterEncoding=utf8&allowPublicKeyRetrieval=true&serverTimezone=Asia/Seoul"
SPRING_DATASOURCE_USERNAME: "root"
SPRING_DATASOURCE_PASSWORD: "secret"

command: >
sh -c "until nc -z atdd-db 3306; do echo 'waiting db...'; sleep 2; done;
java $JAVA_OPTS -jar /app/app.jar"
KIOSK_PAYMENT_BASE_URL: "http://payments-mock:8080"
KIOSK_PAYMENT_SECRET_KEY: "test_sk_dummy"
<<: *db_env
command: *wait_db_cmd

admin:
build:
Expand All @@ -41,12 +47,8 @@ services:
JAVA_OPTS: "-Xms256m -Xmx512m"
RESERVATION_BASE_URL: "http://reservation:8080"
KIOSK_BASE_URL: "http://kiosk:8080"
SPRING_DATASOURCE_URL: "jdbc:mysql://atdd-db:3306/atdd?useSSL=false&characterEncoding=utf8&allowPublicKeyRetrieval=true&serverTimezone=Asia/Seoul"
SPRING_DATASOURCE_USERNAME: "root"
SPRING_DATASOURCE_PASSWORD: "secret"
command: >
sh -c "until nc -z atdd-db 3306; do echo 'waiting db...'; sleep 2; done;
java $JAVA_OPTS -jar /app/app.jar"
<<: *db_env
command: *wait_db_cmd

reservation:
build:
Expand All @@ -61,9 +63,18 @@ services:
JAVA_OPTS: "-Xms256m -Xmx512m"
ADMIN_BASE_URL: "http://admin:8080"
KIOSK_BASE_URL: "http://kiosk:8080"
SPRING_DATASOURCE_URL: "jdbc:mysql://atdd-db:3306/atdd?useSSL=false&characterEncoding=utf8&allowPublicKeyRetrieval=true&serverTimezone=Asia/Seoul"
SPRING_DATASOURCE_USERNAME: "root"
SPRING_DATASOURCE_PASSWORD: "secret"
command: >
sh -c "until nc -z atdd-db 3306; do echo 'waiting db...'; sleep 2; done;
java $JAVA_OPTS -jar /app/app.jar"
<<: *db_env
command: *wait_db_cmd

payments-mock:
image: wiremock/wiremock:3.13.1
container_name: payments-mock
networks: [ atdd-net ]
ports:
- "9090:8080"
volumes:
- ./wiremock:/home/wiremock
command:
- "--global-response-templating"
- "--verbose"

30 changes: 30 additions & 0 deletions infra/wiremock/mappings/payment-20-confirm-success.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"priority": 20,
"request": {
"method": "POST",
"urlPath": "/v1/payments/confirm",
"headers": {
"Authorization": { "equalTo": "Basic dGVzdF9za19kdW1teTo=" },
"Content-Type": { "contains": "application/json" }
},
"bodyPatterns": [
{ "matchesJsonPath": "$.paymentKey" },
{ "matchesJsonPath": "$.orderId" },
{ "matchesJsonPath": "$.amount" }
]
},
"response": {
"status": 200,
"headers": { "Content-Type": "application/json" },
"jsonBody": {
"paymentKey": "{{jsonPath request.body '$.paymentKey'}}",
"orderId": "{{jsonPath request.body '$.orderId'}}",
"method": "CARD",
"approvedAt": "2024-01-01T12:34:56Z",
"totalAmount": "{{jsonPath request.body '$.amount'}}",
"status": "APPROVED",
"receipt": { "url": "https://pay.local/receipts/{{jsonPath request.body '$.paymentKey'}}" }
},
"transformers": ["response-template"]
}
}
14 changes: 14 additions & 0 deletions infra/wiremock/mappings/payment-21-confirm-amount-mismatch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"priority": 19,
"request": {
"method": "POST",
"urlPath": "/v1/payments/confirm",
"headers": { "Authorization": { "equalTo": "Basic dGVzdF9za19kdW1teTo=" } },
"bodyPatterns": [ { "matchesJsonPath": "$[?(@.amount == 99999)]" } ]
},
"response": {
"status": 409,
"headers": { "Content-Type": "application/json" },
"jsonBody": { "code": "AMOUNT_MISMATCH", "message": "amount/orderId mismatch" }
}
}
61 changes: 61 additions & 0 deletions src/test/java/com/camping/tests/steps/KioskPaymentStepDef.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.camping.tests.steps;

import static io.restassured.RestAssured.given;
import static org.assertj.core.api.Assertions.assertThat;

import io.cucumber.java.PendingException;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import io.restassured.response.Response;
import java.util.List;
import java.util.Map;
import org.apache.http.HttpStatus;

public class KioskPaymentStepDef {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 ν…ŒμŠ€νŠΈ μ €μž₯μ†Œμ—λŠ” ν‚€μ˜€μŠ€ν¬ μ™Έ μ‚¬μš©μž μ˜ˆμ•½κ³Ό κ΄€λ¦¬μžλ‘œ ν˜ΈμΆœν•˜λŠ” ν…ŒμŠ€νŠΈλ„ ν¬ν•¨λ˜λŠ” μ €μž₯μ†Œμž…λ‹ˆλ‹€!

ν˜„μž¬ ν‚€μ˜€μŠ€ν¬λ‘œ ν˜ΈμΆœμ„ λ³΄λ‚΄λŠ” μŠ€ν…μ΄ KioskProductStepsκ³Ό KioskPaymentStepDef에 μœ„μΉ˜ν•΄μžˆλŠ”λ°μš”~
ν‚€μ˜€μŠ€ν¬λ‘œ ν˜ΈμΆœν•˜λŠ” λΆ€λΆ„μ˜ λ‘œμ§μ„ μŠ€ν…κ³Ό λΆ„λ¦¬ν•΄μ„œ μž¬μ‚¬μš©ν•  수 μžˆλŠ” 방법은 μ—†μ„κΉŒμš”?
κ·Έλ ‡κ²Œ 될 경우 맀번 ν…ŒμŠ€νŠΈλ₯Ό λ§Œλ“€μ–΄μ€„ λ•Œ λ§ˆλ‹€ μŠ€ν… 클래슀λ₯Ό μƒˆλ‘œ λ§Œλ“€μ–΄μ€„ ν•„μš” 없이 ν•˜λ‚˜μ˜ ν΄λž˜μŠ€μ—μ„œ 관리할 수 μžˆμ„ 것 κ°™μ•„μ„œμš”~

Copy link
Author

@stoneHee99 stoneHee99 Sep 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

κΈ°μ‘΄ 2μ£Όμ°¨ λ―Έμ…˜μ—μ„œ ν–ˆλ˜ 것 처럼 API 호좜 μ±…μž„μ„ κ°€μ§„ 클래슀λ₯Ό λ§Œλ“€μ–΄λ³΄λ©΄ μ’‹κ² λ„€μš”!


private int amount;
private Response response;
Comment on lines +17 to +18
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μŠ€ν… ν΄λž˜μŠ€λ³„λ‘œ κ³΅μœ ν•˜λŠ” 객체가 λ”°λ‘œ κ΄€λ¦¬λ˜κ³  μžˆλŠ”λ°μš”~
μŠ€ν… 클래슀λ₯Ό λ‹€μ–‘ν•˜κ²Œ μ‚¬μš©ν•  경우 κ³΅μœ κ°€ μ–΄λ €μšΈ 것 κ°™μ•„μš”!
λ‹€μ–‘ν•œ ν΄λž˜μŠ€μ—μ„œ μƒνƒœλ₯Ό κ³΅μœ ν•  수 있게 ν•˜λ €λ©΄ μ–΄λ–»κ²Œ ν•˜λ©΄ μ’‹μ„κΉŒμš”?


@Given("결제 κΈˆμ•‘μ΄ {int}원인 μž₯λ°”κ΅¬λ‹ˆκ°€ μžˆλ‹€")
public void κ²°μ œκΈˆμ•‘μ΄μ›μΈμž₯λ°”κ΅¬λ‹ˆκ°€μžˆλ‹€(int amount) {
this.amount = amount;
}

@When("κ²°μ œν‚€ {string} 와 주문번호 {string} 둜 결제 μŠΉμΈμ„ μš”μ²­ν•œλ‹€")
public void κ²°μ œν‚€μ™€μ£Όλ¬Έλ²ˆν˜Έλ‘œκ²°μ œμŠΉμΈμ„μš”μ²­ν•œλ‹€(String paymentKey, String orderId) {
Map<String, Object> body = Map.of(
"paymentKey", paymentKey,
"orderId", orderId,
"amount", amount,
"items", List.of(Map.of(
"productId", 1,
"quantity", 1,
"lineTotal", amount
))
);

response = given()
.contentType("application/json")
.body(body)
.when().post("http://localhost:8080/api/payments/confirm")
.then().extract().response();
}


@Then("κ²°μ œκ°€ μ„±κ³΅ν•˜λ©° 결제 κΈˆμ•‘μ€ {int}원이닀")
public void κ²°μ œκ°€μ„±κ³΅ν•˜λ©°κ²°μ œκΈˆμ•‘μ€μ›μ΄λ‹€(int expectedAmount) {
assertThat(response.statusCode()).isEqualTo(HttpStatus.SC_OK);
boolean success = response.jsonPath().getBoolean("success");
int paid = response.jsonPath().getInt("paidAmount");
assertThat(success).isTrue();
assertThat(paid).isEqualTo(expectedAmount);
}

@Then("κ²°μ œκ°€ μ‹€νŒ¨ν•œλ‹€.")
public void κ²°μ œκ°€μ‹€νŒ¨ν•œλ‹€() {
assertThat(response.statusCode()).isEqualTo(HttpStatus.SC_OK);
boolean success = response.jsonPath().getBoolean("success");
assertThat(success).isFalse();
}
}
11 changes: 11 additions & 0 deletions src/test/resources/features/kiosk-payment.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Feature: ν‚€μ˜€μŠ€ν¬ 결제 승인 E2E ν…ŒμŠ€νŠΈ
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kiosk - paymeny(wiremock) e2e ν…ŒμŠ€νŠΈ πŸ‘


Scenario: 결제 μŠΉμΈμ„ μš”μ²­ν•˜λ©΄ κ²°μ œκ°€ 정상 μŠΉμΈλœλ‹€.
Given 결제 κΈˆμ•‘μ΄ 10000원인 μž₯λ°”κ΅¬λ‹ˆκ°€ μžˆλ‹€
When κ²°μ œν‚€ "pay_123" 와 주문번호 "ord_123" 둜 결제 μŠΉμΈμ„ μš”μ²­ν•œλ‹€
Then κ²°μ œκ°€ μ„±κ³΅ν•˜λ©° 결제 κΈˆμ•‘μ€ 10000원이닀

Scenario: 결제 μŠΉμΈμ„ μš”μ²­ν•˜λ©΄ κ²°μ œκ°€ μ‹€νŒ¨ν•œλ‹€.
Given 결제 κΈˆμ•‘μ΄ 99999원인 μž₯λ°”κ΅¬λ‹ˆκ°€ μžˆλ‹€
When κ²°μ œν‚€ "pay_fail" 와 주문번호 "ord_fail" 둜 결제 μŠΉμΈμ„ μš”μ²­ν•œλ‹€
Then κ²°μ œκ°€ μ‹€νŒ¨ν•œλ‹€.
2 changes: 1 addition & 1 deletion src/test/resources/features/kiosk-product.feature
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Feature: ν‚€μ˜€μŠ€ν¬ μ•± μƒν’ˆ 쑰회
Feature: ν‚€μ˜€μŠ€ν¬ μ•± μƒν’ˆ 쑰회 E2E ν…ŒμŠ€νŠΈ

Scenario: μƒν’ˆ 쑰회λ₯Ό μš”μ²­ν•˜λ©΄ μƒν’ˆ λͺ©λ‘μ΄ 잘 μ‘°νšŒλœλ‹€.
When ν‚€μ˜€μŠ€ν¬ μ•±μœΌλ‘œ μƒν’ˆ 쑰회 μš”μ²­μ„ 보낸닀
Expand Down