|
| 1 | +package com.sponus.sponusbe.domain.organization; |
| 2 | + |
| 3 | +import java.util.List; |
| 4 | + |
| 5 | +import org.assertj.core.api.Assertions; |
| 6 | +import org.junit.jupiter.api.Test; |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; |
| 8 | +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; |
| 9 | +import org.springframework.boot.test.context.SpringBootTest; |
| 10 | +import org.springframework.http.HttpStatus; |
| 11 | +import org.springframework.http.MediaType; |
| 12 | +import org.springframework.test.web.servlet.MockMvc; |
| 13 | +import org.springframework.test.web.servlet.MvcResult; |
| 14 | +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; |
| 15 | +import org.springframework.transaction.annotation.Transactional; |
| 16 | + |
| 17 | +import com.sponus.coredomain.domain.organization.Organization; |
| 18 | +import com.sponus.coredomain.domain.organization.enums.OrganizationType; |
| 19 | +import com.sponus.coredomain.domain.organization.repository.OrganizationRepository; |
| 20 | +import com.sponus.sponusbe.domain.organization.dto.OrganizationCreateRequest; |
| 21 | +import com.sponus.sponusbe.domain.organization.service.OrganizationService; |
| 22 | + |
| 23 | +@SpringBootTest |
| 24 | +@Transactional |
| 25 | +@AutoConfigureMockMvc |
| 26 | +class SecurityAuthTest { |
| 27 | + |
| 28 | + @Autowired |
| 29 | + MockMvc mockMvc; |
| 30 | + |
| 31 | + @Autowired |
| 32 | + OrganizationRepository organizationRepository; |
| 33 | + @Autowired |
| 34 | + OrganizationService organizationService; |
| 35 | + |
| 36 | + @Test |
| 37 | + void joinTest() { |
| 38 | + |
| 39 | + // given |
| 40 | + OrganizationCreateRequest request = new OrganizationCreateRequest( "[email protected]", |
| 41 | + "sponus_company1234#", |
| 42 | + "sponus_company", OrganizationType.COMPANY); |
| 43 | + |
| 44 | + // when |
| 45 | + Long organizationId = organizationService.createOrganization(request); |
| 46 | + |
| 47 | + // then |
| 48 | + List<Organization> organizationList = organizationRepository.findAll(); |
| 49 | + Assertions.assertThat(organizationList.size()).isEqualTo(1); |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + void loginTest() throws Exception { |
| 54 | + |
| 55 | + // given |
| 56 | + OrganizationCreateRequest request = new OrganizationCreateRequest( "[email protected]", |
| 57 | + "sponus_club1234#", |
| 58 | + "sponus_club", OrganizationType.COMPANY); |
| 59 | + |
| 60 | + organizationService.createOrganization(request); |
| 61 | + |
| 62 | + // when |
| 63 | + String jsonRequest = "{" |
| 64 | + + "\"email\": \"[email protected]\", " |
| 65 | + + "\"password\": \"sponus_club1234#\", " |
| 66 | + + "\"fcmToken\": \"fcmTokenFcmTokenFcmTokenFcmTokenFcmTokenFcmTokenFcmTokenFcmTokenFcmTokenFcmTokenFcmTokenFcmToken\"" |
| 67 | + + "}"; |
| 68 | + |
| 69 | + MvcResult response = mockMvc.perform( |
| 70 | + MockMvcRequestBuilders.post("/api/v2/auth/login") |
| 71 | + .contentType(MediaType.APPLICATION_JSON) |
| 72 | + .content(jsonRequest)) // JSON 형식의 데이터를 본문에 추가 |
| 73 | + .andReturn(); |
| 74 | + |
| 75 | + // then |
| 76 | + Assertions.assertThat(response.getResponse().getStatus()).isEqualTo(HttpStatus.CREATED.value()); |
| 77 | + } |
| 78 | +} |
0 commit comments