-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #226 from PLADI-ALM/test/PDS-196-getResourceBookin…
…gDetail [PDS-196/test] 장비 예약 개별 조회 API 성공&실패 테스트 구현
- Loading branch information
Showing
7 changed files
with
229 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
src/test/java/com/example/pladialmserver/booking/service/ResourceBookingServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package com.example.pladialmserver.booking.service; | ||
|
||
import com.example.pladialmserver.booking.dto.response.ProductBookingDetailRes; | ||
import com.example.pladialmserver.booking.entity.ResourceBooking; | ||
import com.example.pladialmserver.booking.repository.resourceBooking.ResourceBookingRepository; | ||
import com.example.pladialmserver.global.exception.BaseException; | ||
import com.example.pladialmserver.global.exception.BaseResponseCode; | ||
import com.example.pladialmserver.global.utils.DateTimeUtil; | ||
import com.example.pladialmserver.user.entity.Role; | ||
import com.example.pladialmserver.user.entity.User; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.Spy; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
|
||
import java.util.Optional; | ||
|
||
import static com.example.pladialmserver.booking.service.model.TestResourceBookingInfo.setUpResourceBooking; | ||
import static com.example.pladialmserver.user.service.model.TestUserInfo.*; | ||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.doReturn; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class ResourceBookingServiceTest { | ||
|
||
@InjectMocks | ||
private ResourceBookingService resourceBookingService; | ||
|
||
@Mock | ||
private ResourceBookingRepository resourceBookingRepository; | ||
|
||
@Spy | ||
BCryptPasswordEncoder passwordEncoder; | ||
|
||
@Test | ||
void getProductBookings() { | ||
} | ||
|
||
@Test | ||
@DisplayName("[성공] 장비 예약 개별 조회") | ||
void getProductBookingDetail_SUCCESS() { | ||
// given | ||
User basicUser = setUpBasicUser(setUpDepartment(), setUpAffiliation(), passwordEncoder.encode(PASSWORD)); | ||
User adminUser = setUpUser(setUpDepartment(), setUpAffiliation(), passwordEncoder.encode(PASSWORD)); | ||
ResourceBooking resourceBooking = setUpResourceBooking(basicUser, adminUser); | ||
// when | ||
doReturn(Optional.of(resourceBooking)).when(resourceBookingRepository).findById(resourceBooking.getResourceBookingId()); | ||
ProductBookingDetailRes res = resourceBookingService.getProductBookingDetail(basicUser, resourceBooking.getResourceBookingId()); | ||
// then | ||
assertThat(res.getId()).isEqualTo(resourceBooking.getResource().getResourceId()); | ||
assertThat(res.getStatus()).isEqualTo(resourceBooking.getStatus().getValue()); | ||
assertThat(res.getReservatorName()).isEqualTo(resourceBooking.getUser().getName()); | ||
assertThat(res.getReservatorPhone()).isEqualTo(resourceBooking.getUser().getPhone()); | ||
assertThat(res.getStartDate()).isEqualTo(DateTimeUtil.dateTimeToString(resourceBooking.getStartDate())); | ||
assertThat(res.getEndDate()).isEqualTo(DateTimeUtil.dateTimeToString(resourceBooking.getEndDate())); | ||
assertThat(res.getReturnDateTime()).isEqualTo(DateTimeUtil.dateTimeToStringNullable(resourceBooking.getReturnDate())); | ||
assertThat(res.getMemo()).isEqualTo(resourceBooking.getMemo()); | ||
} | ||
|
||
@Test | ||
@DisplayName("[실패] 장비 예약 개별 조회 - 본인 장비 예약이 아닌 경우") | ||
void getProductBookingDetail_NO_AUTHENTICATION() { | ||
// given | ||
User basicUser = setUpUser(1L, Role.BASIC, setUpDepartment(), setUpAffiliation(), passwordEncoder.encode(PASSWORD)); | ||
User adminUser = setUpUser(2L, Role.ADMIN, setUpDepartment(), setUpAffiliation(), passwordEncoder.encode(PASSWORD)); | ||
User fakeUser = setUpUser(3L, Role.BASIC, setUpDepartment(), setUpAffiliation(), passwordEncoder.encode(PASSWORD)); | ||
ResourceBooking resourceBooking = setUpResourceBooking(basicUser, adminUser); | ||
// when | ||
doReturn(Optional.of(resourceBooking)).when(resourceBookingRepository).findById(resourceBooking.getResourceBookingId()); | ||
BaseException exception = assertThrows(BaseException.class, () -> { | ||
resourceBookingService.getProductBookingDetail(fakeUser, resourceBooking.getResourceBookingId()); | ||
}); | ||
// then | ||
assertThat(exception.getBaseResponseCode()).isEqualTo(BaseResponseCode.NO_AUTHENTICATION); | ||
} | ||
|
||
@Test | ||
@DisplayName("[실패] 장비 예약 개별 조회 - 존재하지 않는 예약인 경우") | ||
void getProductBookingDetail_BOOKING_NOT_FOUND() { | ||
// given | ||
User basicUser = setUpUser(1L, Role.BASIC, setUpDepartment(), setUpAffiliation(), passwordEncoder.encode(PASSWORD)); | ||
User adminUser = setUpUser(2L, Role.ADMIN, setUpDepartment(), setUpAffiliation(), passwordEncoder.encode(PASSWORD)); | ||
User fakeUser = setUpUser(3L, Role.BASIC, setUpDepartment(), setUpAffiliation(), passwordEncoder.encode(PASSWORD)); | ||
ResourceBooking resourceBooking = setUpResourceBooking(basicUser, adminUser); | ||
// when | ||
BaseException exception = assertThrows(BaseException.class, () -> { | ||
resourceBookingService.getProductBookingDetail(fakeUser, resourceBooking.getResourceBookingId()+1); | ||
}); | ||
// then | ||
assertThat(exception.getBaseResponseCode()).isEqualTo(BaseResponseCode.BOOKING_NOT_FOUND); | ||
} | ||
|
||
@Test | ||
void cancelBookingProduct() { | ||
} | ||
|
||
@Test | ||
void checkProductBookingTime() { | ||
} | ||
|
||
@Test | ||
void getProductBookingDetailByAdmin() { | ||
} | ||
|
||
@Test | ||
void rejectProductBooking() { | ||
} | ||
|
||
@Test | ||
void allowProductBooking() { | ||
} | ||
|
||
@Test | ||
void returnBookingProductByAdmin() { | ||
} | ||
|
||
@Test | ||
void getBookingProducts() { | ||
} | ||
|
||
@Test | ||
void returnBookingProduct() { | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/test/java/com/example/pladialmserver/booking/service/model/TestResourceBookingInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.example.pladialmserver.booking.service.model; | ||
|
||
import com.example.pladialmserver.booking.entity.ResourceBooking; | ||
import com.example.pladialmserver.product.resource.entity.Resource; | ||
import com.example.pladialmserver.user.entity.User; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
import static com.example.pladialmserver.resource.service.model.TestResourceInfo.setUpResource; | ||
|
||
public class TestResourceBookingInfo { | ||
public static ResourceBooking setUpResourceBooking(User basicUser, User adminUser){ | ||
Resource resource = setUpResource(adminUser); | ||
return new ResourceBooking( | ||
1L, | ||
basicUser, | ||
resource, | ||
LocalDateTime.of(2024,1,1,0,0), | ||
LocalDateTime.of(2024,1,2,0,0), | ||
"예약합니다."); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/test/java/com/example/pladialmserver/resource/service/model/TestResourceInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.example.pladialmserver.resource.service.model; | ||
|
||
import com.example.pladialmserver.product.resource.entity.Resource; | ||
import com.example.pladialmserver.user.entity.User; | ||
|
||
public class TestResourceInfo { | ||
|
||
public static Resource setUpResource(User adminUser) { | ||
return new Resource( | ||
1L, | ||
"ENG 카메라", | ||
"소니", | ||
"401호", | ||
"파손 주의", | ||
"sample.jpg", | ||
adminUser); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,35 @@ public static User setUpUser(Department department, Affiliation affiliation, Str | |
.build(); | ||
} | ||
|
||
public static User setUpUser(Long userId, Role role, Department department, Affiliation affiliation, String password){ | ||
return new User( | ||
userId, | ||
"홍길동", | ||
"[email protected]", | ||
password, | ||
department, | ||
"010-0000-0000", | ||
role, | ||
"1234545", | ||
"A12345", | ||
affiliation); | ||
} | ||
|
||
public static User setUpBasicUser(Department department, Affiliation affiliation, String password){ | ||
return User.builder() | ||
.userId(1L) | ||
.name("홍길동") | ||
.email("[email protected]") | ||
.password(password) | ||
.fcmToken("1234545") | ||
.phone("010-0000-0000") | ||
.department(department) | ||
.role(Role.BASIC) | ||
.assets("A12345") | ||
.affiliation(affiliation) | ||
.build(); | ||
} | ||
|
||
public static Department setUpDepartment(){ | ||
return Department.builder() | ||
.name("마케팅") | ||
|