Skip to content

Conversation

@crtEvent
Copy link
Contributor

@crtEvent crtEvent commented Apr 10, 2024

✨ Key changes

👋 To reviewers

Redis Test Container 추가

  • 로그인 테스트를 위해 Redis Test Container를 추가했습니다.

테스트용 로그인 Step 메서드 구현

  • Test에서만 사용할 로그인 Controller와 로그인 메서드를 만들었습니다.
  • 단순히 session만 생성해 주는 기능입니다.
  • @jinny-l 가 테스트용 로그인 API 구현하시면 변경될 수 도 있을 것 같아요

테스트 규칙 제안

API 마다 테스트 class 만들기

  • e.g. 스터디 가입 요청 API -> CreateJoinRequestTest
  • 변경이 일어난다면 API 단위가 될 것 같습니다. API 하나에 성공, 실패 시나리오가 다 있는 편이 요구사항 변경 시 수정해야할 파일 범위를 줄일 수 있다고 생각합니다. 또한 한 API만 수정했는데 다른 파일에서 에러가 나면 해당 변경사항이 다른 API까지 영향을 끼치고 있다는 것을 파일 이름으로 쉽게 파악할 수 있을 것 같습니다.

Fixture는 해당 도메인에서만 사용하기

  • 테스트 시나리오 마다 필요한 데이터와 상태가 다 다릅니다. 픽스처도 도메인의 시나리오 별로 관리하는게 코드는 많아져도 테스트를 이해하고 수정하는 것에는 덜 복잡해질 것 같아요.

테스트 케이스

스터디 가입 요청 케이스

  • 유저는 스터디에 가입 요청을 할 수 있다
  • 존재하지 않는 스터디에 가입 요청을 보낼 수 없다
  • 이미 가입 요청된 상태의 스터디에 가입 요청을 보낼 수 없다
  • 이미 가입된 스터디에 가입 요청을 보낼 수 없다

스터디 가입 요청 수락 케이스

  • 스터디 리더는 스터디 가입 요청을 수락 할 수 있다
  • 스터디 리더가 아닌 멤버는 스터디 가입 요청을 수락 할 수 없다
  • 이미 수락된 스터디 가입 요청은 수락 할 수 없다
  • 이미 거절된 스터디 가입 요청은 수락 할 수 없다
  • 가입 요청시 URL의 JOIN REQUEST가 STUDY에 포함되지 않으면 가입 요청은 수락 할 수 없다

스터디 가입 요청 거절 케이스

  • 스터디 리더는 스터디 가입 요청을 거절 할 수 있다
  • 스터디 리더가 아닌 멤버는 스터디 가입 요청을 거절 할 수 없다
  • 이미 수락된 스터디 가입 요청은 거절 할 수 없다
  • 이미 거절된 스터디 가입 요청은 거절 할 수 없다
  • 가입 요청시 URL의 JOIN REQUEST가 STUDY에 포함되지 않으면 가입 요청은 거절 할 수 없다

@crtEvent crtEvent added the ✅test 테스트 label Apr 10, 2024
@crtEvent crtEvent requested review from jaea-kim and jinny-l April 10, 2024 23:57
@crtEvent crtEvent self-assigned this Apr 10, 2024
Comment on lines +48 to +56
public SessionCookie 테스트_로그인(Long memberId) {
String sessionCookieValue = givenJsonRequest()
.body(memberId)
.when().post("/api/v1/test/sign-in")
.then().extract()
.cookie(sessionCookieName);

return new SessionCookie(sessionCookieName, sessionCookieValue);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

테스트용 로그인 메서드입니다. 로그인 하면 쿠키 객체를 반환합니다.

쿠키 객체는 Step 메서드에서 다음과 같이 사용합니다.

public static ExtractableResponse<Response> 스터디_가입_요청(Long studyId, SessionCookie sessionCookie) {
        return givenJsonRequest()
                .cookie(sessionCookie.name(), sessionCookie.value())
                .when().post("/api/v1/studies/{studyId}/join-requests", studyId)
                .then().log().all().extract();
    }

Copy link
Member

Choose a reason for hiding this comment

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

테스트 로그인할 때 어드민 로그인으로 안하고 별도의 테스트 로그인을 만드신건가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

네, 테스트 시나리오 상 어드민이 아니라 다른 Member가 로그인 할 수도 있을 것 같아서 만들었어요

@crtEvent crtEvent linked an issue Apr 11, 2024 that may be closed by this pull request
17 tasks
Copy link
Member

@jinny-l jinny-l left a comment

Choose a reason for hiding this comment

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

에이프 고생 많으셨어요!

Comment on lines 25 to 29

@BeforeEach
@BeforeAll
void setUp() {
RestAssured.port = port;
}
Copy link
Member

Choose a reason for hiding this comment

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

@BeforeAll 이 더 좋을 것 같네요!

Comment on lines +12 to +13
public class JoinRequestFixture {

Copy link
Member

Choose a reason for hiding this comment

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

흐음.. 에이프랑 저랑 사용하는 픽스쳐 형태가 달라서 fixture 를 어떻게 관리하면 좋을지 논의해보면 좋긴 할 것 같네요

Comment on lines +46 to +48
var leader = memberRepository.save(리더());
var member = memberRepository.save(멤버_01());
var study = studyRepository.save(알고리즘_스터디());
Copy link
Member

Choose a reason for hiding this comment

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

저는 API 요청을 날렸는데 에이프는 레포지토리에 직접 저장하셨군요

Comment on lines +114 to +117
private void 스터디_가입_요청이_생성되었는지_검증(ExtractableResponse<Response> response, Study study, Member member) {
var createdId = response.body().jsonPath().getLong("id");
var created = joinRequestRepository.findById(createdId).get();

Copy link
Member

Choose a reason for hiding this comment

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

저는 actual expected 이런식으로 네이밍했어요!

Comment on lines +48 to +56
public SessionCookie 테스트_로그인(Long memberId) {
String sessionCookieValue = givenJsonRequest()
.body(memberId)
.when().post("/api/v1/test/sign-in")
.then().extract()
.cookie(sessionCookieName);

return new SessionCookie(sessionCookieName, sessionCookieValue);
}
Copy link
Member

Choose a reason for hiding this comment

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

테스트 로그인할 때 어드민 로그인으로 안하고 별도의 테스트 로그인을 만드신건가요?

@crtEvent
Copy link
Contributor Author

Fixture 분리해서 올렸습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✅test 테스트

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feat] 스터디 가입 요청 및 수락/거절 기능 추가

3 participants