Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 나갔던 약속에 재참여가 되지 않는 문제 개선 #880

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
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
4 changes: 2 additions & 2 deletions backend/src/main/java/com/ody/mate/domain/Mate.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@

@Table(uniqueConstraints = {
@UniqueConstraint(
name = "uniqueMeetingAndMember",
columnNames = {"meeting_id", "member_id"}
name = "uniqueMeetingAndMemberAndDeletedAt",
columnNames = {"meeting_id", "member_id", "deleted_at"}
)
})
@Entity
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package com.ody.mate.controller;

import static org.junit.jupiter.api.DynamicTest.dynamicTest;

import com.ody.common.BaseControllerTest;
import com.ody.mate.dto.request.MateSaveRequestV2;
import com.ody.meeting.domain.Meeting;
import com.ody.member.domain.Member;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import java.time.LocalDateTime;
import java.util.stream.Stream;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import org.springframework.http.HttpHeaders;

class MateControllerTest extends BaseControllerTest {

@DisplayName("동일 약속에 퇴장했다가 재참여가 가능하다")
@TestFactory
Stream<DynamicTest> canReattendMeeting() {
LocalDateTime fiveMinutesLater = LocalDateTime.now().plusMinutes(5L);
Meeting meeting = fixtureGenerator.generateMeeting(fiveMinutesLater);
Member member = fixtureGenerator.generateMember();

return Stream.of(
dynamicTest("약속에 최초 참여한다", () -> {
MateSaveRequestV2 mateSaveRequestV2 = dtoGenerator.generateMateSaveRequest(meeting);
RestAssured.given().log().all()
.contentType(ContentType.JSON)
.header(HttpHeaders.AUTHORIZATION, fixtureGenerator.generateAccessTokenValueByMember(member))
.body(mateSaveRequestV2)
.when()
.post("/v2/mates")
.then()
.statusCode(201);
}),
dynamicTest("약속에서 퇴장한다", () -> {
RestAssured.given().log().all()
.contentType(ContentType.JSON)
.header(HttpHeaders.AUTHORIZATION, fixtureGenerator.generateAccessTokenValueByMember(member))
.when()
.delete("/meetings/" + meeting.getId() + "/mate")
.then()
.statusCode(204);
}),
dynamicTest("약속에 재참여한다", () -> {
MateSaveRequestV2 mateSaveRequestV2 = dtoGenerator.generateMateSaveRequest(meeting);
RestAssured.given().log().all()
.contentType(ContentType.JSON)
.header(HttpHeaders.AUTHORIZATION, fixtureGenerator.generateAccessTokenValueByMember(member))
.body(mateSaveRequestV2)
.when()
.post("/v2/mates")
.then()
.statusCode(201);
})
);
}

@DisplayName("약속에 참여한 상태로 재참여가 불가하다")
@TestFactory
Stream<DynamicTest> canNotReattendMeetingWithoutLeave() {
LocalDateTime fiveMinutesLater = LocalDateTime.now().plusMinutes(5L);
Meeting meeting = fixtureGenerator.generateMeeting(fiveMinutesLater);
Member member = fixtureGenerator.generateMember();

return Stream.of(
dynamicTest("약속에 최초 참여한다", () -> {
MateSaveRequestV2 mateSaveRequestV2 = dtoGenerator.generateMateSaveRequest(meeting);
RestAssured.given().log().all()
.contentType(ContentType.JSON)
.header(HttpHeaders.AUTHORIZATION,
fixtureGenerator.generateAccessTokenValueByMember(member))
.body(mateSaveRequestV2)
.when()
.post("/v2/mates")
.then()
.statusCode(201);
}),
dynamicTest("동일 약속에 재참여를 시도한다", () -> {
MateSaveRequestV2 mateSaveRequestV2 = dtoGenerator.generateMateSaveRequest(meeting);
RestAssured.given().log().all()
.contentType(ContentType.JSON)
.header(HttpHeaders.AUTHORIZATION,
fixtureGenerator.generateAccessTokenValueByMember(member))
.body(mateSaveRequestV2)
.when()
.post("/v2/mates")
.then()
.statusCode(400);
})
);
};
}
Loading