Skip to content

Commit

Permalink
요구사항 명세에 근거한 인수테스트 작성
Browse files Browse the repository at this point in the history
요구사항 명세에 근거한 인수테스트 작성
  • Loading branch information
xGreenNarae authored Oct 13, 2023
2 parents f1468f7 + 39f8c98 commit d051a06
Show file tree
Hide file tree
Showing 11 changed files with 432 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public record ShelterAddressSignUpDto(
@NotNull(message = "광역시/도를 입력해주세요.") Province province,
@NotNull(message = "시/군/구를 입력해주세요.") String city,
@NotNull(message = "도로명을 입력해주세요.") String roadName,
@NotNull(message = "상세 주소를 입력해주세요.") String detail) {
String detail) {
public ShelterAddress getShelterAddress() {
return ShelterAddress.builder()
.province(province)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,6 @@ public class Pet extends BaseEntity {
@JoinColumn(name = "shelter_id")
private Shelter shelter;

@OneToOne(mappedBy = "pet")
@JoinColumn(name = "pet_polygon_profile_id")
private PetPolygonProfile petPolygonProfile;


public void updateImage(final String imageUrl) {
this.profileImageUrl = imageUrl;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
public class PetPolygonProfile {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;

@MapsId
Expand All @@ -24,7 +23,6 @@ public class PetPolygonProfile {

private int intelligence;


private int affinity;

private int athletic;
Expand Down
120 changes: 120 additions & 0 deletions animory/src/test/java/com/daggle/animory/acceptance/AccountTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package com.daggle.animory.acceptance;

import com.daggle.animory.domain.account.dto.request.AccountLoginDto;
import com.daggle.animory.domain.account.dto.request.EmailValidateDto;
import com.daggle.animory.domain.account.dto.request.ShelterAddressSignUpDto;
import com.daggle.animory.domain.account.dto.request.ShelterSignUpDto;
import com.daggle.animory.domain.shelter.entity.Province;
import com.daggle.animory.testutil.AcceptanceTest;
import com.daggle.animory.testutil.fixture.AccountFixture;
import org.junit.jupiter.api.Test;
import org.springframework.http.MediaType;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;


class AccountTest extends AcceptanceTest {

private final String EMAIL = AccountFixture.EMAIL;
private final String PASSWORD = AccountFixture.PASSWORD;

@Test
void 이메일_중복_검사() throws Exception {
final EmailValidateDto emailValidateDto = new EmailValidateDto(EMAIL + "1");

result = mvc.perform(post("/account/email")
.contentType(MediaType.APPLICATION_JSON)
.content(om.writeValueAsString(emailValidateDto)));

assertSuccess();
}

@Test
void 보호소_회원가입() throws Exception {
final ShelterSignUpDto shelterSignUpDto = ShelterSignUpDto.builder()
.email(EMAIL + "1")
.password(PASSWORD)
.name("테스트 보호소")
.address(
ShelterAddressSignUpDto.builder()
.province(Province.광주)
.city("무슨무슨구")
.roadName("무슨무슨로")
.detail("상세주소 1234-56")
.build()
)
.contact("010-1234-5678")
.build();


result = mvc.perform(post("/account/shelter")
.contentType(MediaType.APPLICATION_JSON)
.content(om.writeValueAsString(shelterSignUpDto)));

assertSuccess();
}

@Test
void 중복된_이메일로_회원가입_불가() throws Exception {
final ShelterSignUpDto shelterSignUpDto = ShelterSignUpDto.builder()
.email(EMAIL)
.password(PASSWORD)
.name("테스트 보호소")
.address(
ShelterAddressSignUpDto.builder()
.province(Province.광주)
.city("무슨무슨구")
.roadName("무슨무슨로")
.detail("상세주소 1234-56")
.build()
)
.contact("010-1234-5678")
.build();


result = mvc.perform(post("/account/shelter")
.contentType(MediaType.APPLICATION_JSON)
.content(om.writeValueAsString(shelterSignUpDto)))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.success").value(false));
}

@Test
void 보호소_로그인() throws Exception {
final AccountLoginDto accountLoginDto = AccountLoginDto.builder()
.email(EMAIL)
.password(PASSWORD)
.build();

result = mvc.perform(post("/account/login")
.contentType(MediaType.APPLICATION_JSON)
.content(om.writeValueAsString(accountLoginDto)));

assertSuccess();

// header authorization field exists
assertThat( result.andReturn()
.getResponse()
.getHeader("Authorization") ).isNotNull();
}

@Test
void 존재하지_않는_계정으로_로그인_실패와_안내문구() throws Exception {
final AccountLoginDto accountLoginDto = AccountLoginDto.builder()
.email(EMAIL + "1")
.password(PASSWORD)
.build();

result = mvc.perform(post("/account/login")
.contentType(MediaType.APPLICATION_JSON)
.content(om.writeValueAsString(accountLoginDto)))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.success").value(false))
.andExpect(jsonPath("$.error.message").value("이메일 또는 비밀번호를 확인해주세요."));

}

}

This file was deleted.

Loading

0 comments on commit d051a06

Please sign in to comment.