Skip to content

Commit

Permalink
test: 애플 로그인 API 테스트 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
hong-sile committed Jan 25, 2024
1 parent 741f3d9 commit b0fa510
Showing 1 changed file with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
class LoginApiTest extends MockMvcTestHelper {

@Test
@DisplayName("code가 유효할 경우 200과 함께 TokenResponse를 반환해 준다.")
void availableLoginTest() throws Exception {
@DisplayName("code가 유효할 경우 200과 함께 github TokenResponse를 반환해 준다.")
void availableLoginByGithubTest() throws Exception {
// given
final String code = "code";
final TokenResponse tokenResponse = new TokenResponse(1L, false, "access_token");
Expand All @@ -59,6 +59,35 @@ void availableLoginTest() throws Exception {
.andDo(document("login-snippet", requestFields, responseFields));
}

@Test
@DisplayName("code가 유효할 경우 200과 함께 apple TokenResponse를 반환해 준다.")
void availableAppleLoginTest() throws Exception {
// given
final String code = "code";
final TokenResponse tokenResponse = new TokenResponse(1L, false, "access_token");

BDDMockito.given(loginService.createTokenByGithub(code)).willReturn(tokenResponse);

final RequestParametersSnippet requestFields = requestParameters(
parameterWithName("code").description("apple 로그인 코드")
);

final ResponseFieldsSnippet responseFields = responseFields(
fieldWithPath("memberId").type(JsonFieldType.NUMBER).description("멤버 id"),
fieldWithPath("onboarded").type(JsonFieldType.BOOLEAN).description("온보딩 수행 여부"),
fieldWithPath("accessToken").type(JsonFieldType.STRING).description("Access Token 값")
);

// when
final ResultActions result = mockMvc.perform(
post("/login/apple/callback").param("code", code)
);

// then
result.andExpect(status().isOk())
.andDo(document("login-snippet", requestFields, responseFields));
}

@Test
@DisplayName("code가 존재하지 않을 경우 400 BadRequest를 반환한다.")
void illegalLoginTest() throws Exception {
Expand Down

0 comments on commit b0fa510

Please sign in to comment.