From e0a40e2d630d560ce4ae96f9abdb032d3ff04041 Mon Sep 17 00:00:00 2001 From: boltaevt Date: Sat, 24 Jun 2023 23:10:19 +0500 Subject: [PATCH 1/7] sprint 16 implemented --- .DS_Store | Bin 0 -> 6148 bytes docker-compose.yml | 45 + gateway/.DS_Store | Bin 0 -> 6148 bytes gateway/Dockerfile | 3 + gateway/pom.xml | 71 + .../ru/practicum/shareit/ShareItGateway.java | 12 + .../shareit/booking/BookingClient.java | 66 + .../shareit/booking/BookingController.java | 68 + .../shareit/booking/dto/BookingDto.java | 3 - .../shareit/booking/dto/BookingShortDto.java | 0 .../shareit/booking/dto/BookingState.java | 10 + .../practicum/shareit/client/BaseClient.java | 121 + .../practicum/shareit/error/ErrorHandler.java | 38 + .../shareit/error/ErrorResponse.java | 0 .../ru/practicum/shareit/item/ItemClient.java | 68 + .../shareit/item/ItemController.java | 68 + .../shareit/item/dto/CommentDto.java | 0 .../practicum/shareit/item/dto/ItemDto.java | 4 - .../shareit/request/ItemRequestClient.java | 49 + .../request/ItemRequestController.java | 45 + .../shareit/request/dto/ItemRequestDto.java | 0 .../ru/practicum/shareit/user/UserClient.java | 48 + .../shareit/user/UserController.java | 46 + .../practicum/shareit/user/dto/UserDto.java | 0 .../validation/FieldUpdateConstraint.java | 0 .../FieldUpdateConstraintValidator.java | 0 .../shareit/validation/ValidationGroups.java | 0 .../src/main/resources/application.properties | 7 + pom.xml | 94 +- postman/sprint.json | 11050 ++++++++++++++++ server/Dockerfile | 4 + server/pom.xml | 86 + .../java/ru/practicum/shareit/ShareItApp.java | 8 +- .../shareit/booking/BookingState.java | 0 .../shareit/booking/BookingStatus.java | 0 .../booking/controller/BookingController.java | 21 +- .../shareit/booking/dto/BookingDto.java | 39 + .../shareit/booking/dto/BookingMapper.java | 0 .../shareit/booking/dto/BookingShortDto.java | 25 + .../shareit/booking/model/Booking.java | 0 .../shareit/booking/model/BookingShort.java | 0 .../booking/repository/BookingRepository.java | 0 .../booking/service/BookingService.java | 0 .../service/impl}/BookingServiceImpl.java | 20 +- .../error/BookingNotFoundException.java | 0 .../BookingStatusChangeDeniedException.java | 0 .../practicum/shareit/error/ErrorHandler.java | 4 +- .../shareit/error/ErrorResponse.java | 13 + .../shareit/error/ItemNotFoundException.java | 0 .../error/ItemRequestNotFoundException.java | 0 .../error/ItemUnavailableException.java | 7 + .../error/UserAccessDeniedException.java | 7 + .../shareit/error/UserNotFoundException.java | 0 .../item/controller/ItemController.java | 23 +- .../shareit/item/dto/CommentDto.java | 25 + .../shareit/item/dto/CommentMapper.java | 0 .../practicum/shareit/item/dto/ItemDto.java | 28 + .../shareit/item/dto/ItemMapper.java | 0 .../practicum/shareit/item/model/Comment.java | 12 +- .../ru/practicum/shareit/item/model/Item.java | 8 +- .../item/repository/CommentRepository.java | 0 .../item/repository/ItemRepository.java | 0 .../shareit/item/service/ItemService.java | 0 .../item/service/impl}/ItemServiceImpl.java | 25 +- .../controller/ItemRequestController.java | 9 +- .../shareit/request/dto/ItemRequestDto.java | 23 + .../request/dto/ItemRequestMapper.java | 0 .../shareit/request/model/ItemRequest.java | 0 .../repository/ItemRequestRepository.java | 0 .../request/service/ItemRequestService.java | 0 .../service/impl/ItemRequestServiceImpl.java | 0 .../user/controller/UserController.java | 14 +- .../practicum/shareit/user/dto/UserDto.java | 16 + .../shareit/user/dto/UserMapper.java | 0 .../ru/practicum/shareit/user/model/User.java | 13 +- .../user/repository/UserRepository.java | 0 .../shareit/user/service/UserService.java | 0 .../user/service/impl/UserServiceImpl.java | 0 .../validation/PagingParametersChecker.java | 0 .../src/main/resources/application.properties | 19 + {src => server/src}/main/resources/schema.sql | 0 .../shareit/error/AccessDeniedException.java | 7 - .../error/ItemNotAvailableException.java | 7 - src/main/resources/application.properties | 21 - .../ru/practicum/shareit/ShareItAppTest.java | 13 - .../ru/practicum/shareit/ShareItTests.java | 13 - .../controller/BookingControllerTest.java | 184 - .../shareit/booking/dto/BookingDtoTest.java | 45 - .../booking/dto/BookingMapperTest.java | 42 - .../booking/dto/BookingShortDtoTest.java | 40 - .../repository/BookingRepositoryTest.java | 331 - .../service/BookingServiceImplTest.java | 289 - .../IntegrationBookingServiceImplTest.java | 159 - .../shareit/error/ErrorHandlerTest.java | 25 - .../item/controller/ItemControllerTest.java | 222 - .../shareit/item/dto/CommentDtoTest.java | 38 - .../shareit/item/dto/CommentMapperTest.java | 43 - .../shareit/item/dto/ItemDtoTest.java | 63 - .../repository/CommentRepositoryTest.java | 73 - .../item/repository/ItemRepositoryTest.java | 100 - .../IntegrationItemServiceImplTest.java | 76 - .../item/service/ItemServiceImplTest.java | 277 - .../controller/ItemRequestControllerTest.java | 110 - .../request/dto/ItemRequestDtoTest.java | 90 - .../request/dto/ItemRequestMapperTest.java | 67 - .../repository/ItemRequestRepositoryTest.java | 82 - ...IntegrationItemRequestServiceImplTest.java | 89 - .../service/ItemRequestServiceImplTest.java | 141 - .../user/controller/UserControllerTest.java | 139 - .../shareit/user/dto/UserDtoTest.java | 33 - .../user/repository/UserRepositoryTest.java | 39 - .../user/service/UserServiceImplTest.java | 108 - .../PagingParametersCheckerTest.java | 30 - 113 files changed, 12199 insertions(+), 3162 deletions(-) create mode 100644 .DS_Store create mode 100644 docker-compose.yml create mode 100644 gateway/.DS_Store create mode 100644 gateway/Dockerfile create mode 100644 gateway/pom.xml create mode 100644 gateway/src/main/java/ru/practicum/shareit/ShareItGateway.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/booking/BookingClient.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/booking/BookingController.java rename {src => gateway/src}/main/java/ru/practicum/shareit/booking/dto/BookingDto.java (90%) rename {src => gateway/src}/main/java/ru/practicum/shareit/booking/dto/BookingShortDto.java (100%) create mode 100644 gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingState.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/client/BaseClient.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/error/ErrorHandler.java rename {src => gateway/src}/main/java/ru/practicum/shareit/error/ErrorResponse.java (100%) create mode 100644 gateway/src/main/java/ru/practicum/shareit/item/ItemClient.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/item/ItemController.java rename {src => gateway/src}/main/java/ru/practicum/shareit/item/dto/CommentDto.java (100%) rename {src => gateway/src}/main/java/ru/practicum/shareit/item/dto/ItemDto.java (87%) create mode 100644 gateway/src/main/java/ru/practicum/shareit/request/ItemRequestClient.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/request/ItemRequestController.java rename {src => gateway/src}/main/java/ru/practicum/shareit/request/dto/ItemRequestDto.java (100%) create mode 100644 gateway/src/main/java/ru/practicum/shareit/user/UserClient.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/user/UserController.java rename {src => gateway/src}/main/java/ru/practicum/shareit/user/dto/UserDto.java (100%) rename {src => gateway/src}/main/java/ru/practicum/shareit/validation/FieldUpdateConstraint.java (100%) rename {src => gateway/src}/main/java/ru/practicum/shareit/validation/FieldUpdateConstraintValidator.java (100%) rename {src => gateway/src}/main/java/ru/practicum/shareit/validation/ValidationGroups.java (100%) create mode 100644 gateway/src/main/resources/application.properties create mode 100644 postman/sprint.json create mode 100644 server/Dockerfile create mode 100644 server/pom.xml rename {src => server/src}/main/java/ru/practicum/shareit/ShareItApp.java (65%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/BookingState.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/BookingStatus.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/controller/BookingController.java (61%) create mode 100644 server/src/main/java/ru/practicum/shareit/booking/dto/BookingDto.java rename {src => server/src}/main/java/ru/practicum/shareit/booking/dto/BookingMapper.java (100%) create mode 100644 server/src/main/java/ru/practicum/shareit/booking/dto/BookingShortDto.java rename {src => server/src}/main/java/ru/practicum/shareit/booking/model/Booking.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/model/BookingShort.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/repository/BookingRepository.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/service/BookingService.java (100%) rename {src/main/java/ru/practicum/shareit/booking/service => server/src/main/java/ru/practicum/shareit/booking/service/impl}/BookingServiceImpl.java (88%) rename {src => server/src}/main/java/ru/practicum/shareit/error/BookingNotFoundException.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/error/BookingStatusChangeDeniedException.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/error/ErrorHandler.java (94%) create mode 100644 server/src/main/java/ru/practicum/shareit/error/ErrorResponse.java rename {src => server/src}/main/java/ru/practicum/shareit/error/ItemNotFoundException.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/error/ItemRequestNotFoundException.java (100%) create mode 100644 server/src/main/java/ru/practicum/shareit/error/ItemUnavailableException.java create mode 100644 server/src/main/java/ru/practicum/shareit/error/UserAccessDeniedException.java rename {src => server/src}/main/java/ru/practicum/shareit/error/UserNotFoundException.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/controller/ItemController.java (59%) create mode 100644 server/src/main/java/ru/practicum/shareit/item/dto/CommentDto.java rename {src => server/src}/main/java/ru/practicum/shareit/item/dto/CommentMapper.java (100%) create mode 100644 server/src/main/java/ru/practicum/shareit/item/dto/ItemDto.java rename {src => server/src}/main/java/ru/practicum/shareit/item/dto/ItemMapper.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/model/Comment.java (82%) rename {src => server/src}/main/java/ru/practicum/shareit/item/model/Item.java (88%) rename {src => server/src}/main/java/ru/practicum/shareit/item/repository/CommentRepository.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/repository/ItemRepository.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/service/ItemService.java (100%) rename {src/main/java/ru/practicum/shareit/item/service => server/src/main/java/ru/practicum/shareit/item/service/impl}/ItemServiceImpl.java (89%) rename {src => server/src}/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java (72%) create mode 100644 server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestDto.java rename {src => server/src}/main/java/ru/practicum/shareit/request/dto/ItemRequestMapper.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/request/model/ItemRequest.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/request/repository/ItemRequestRepository.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/request/service/ItemRequestService.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/request/service/impl/ItemRequestServiceImpl.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/user/controller/UserController.java (61%) create mode 100644 server/src/main/java/ru/practicum/shareit/user/dto/UserDto.java rename {src => server/src}/main/java/ru/practicum/shareit/user/dto/UserMapper.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/user/model/User.java (71%) rename {src => server/src}/main/java/ru/practicum/shareit/user/repository/UserRepository.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/user/service/UserService.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/user/service/impl/UserServiceImpl.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/validation/PagingParametersChecker.java (100%) create mode 100644 server/src/main/resources/application.properties rename {src => server/src}/main/resources/schema.sql (100%) delete mode 100644 src/main/java/ru/practicum/shareit/error/AccessDeniedException.java delete mode 100644 src/main/java/ru/practicum/shareit/error/ItemNotAvailableException.java delete mode 100644 src/main/resources/application.properties delete mode 100644 src/test/java/ru/practicum/shareit/ShareItAppTest.java delete mode 100644 src/test/java/ru/practicum/shareit/ShareItTests.java delete mode 100644 src/test/java/ru/practicum/shareit/booking/controller/BookingControllerTest.java delete mode 100644 src/test/java/ru/practicum/shareit/booking/dto/BookingDtoTest.java delete mode 100644 src/test/java/ru/practicum/shareit/booking/dto/BookingMapperTest.java delete mode 100644 src/test/java/ru/practicum/shareit/booking/dto/BookingShortDtoTest.java delete mode 100644 src/test/java/ru/practicum/shareit/booking/repository/BookingRepositoryTest.java delete mode 100644 src/test/java/ru/practicum/shareit/booking/service/BookingServiceImplTest.java delete mode 100644 src/test/java/ru/practicum/shareit/booking/service/IntegrationBookingServiceImplTest.java delete mode 100644 src/test/java/ru/practicum/shareit/error/ErrorHandlerTest.java delete mode 100644 src/test/java/ru/practicum/shareit/item/controller/ItemControllerTest.java delete mode 100644 src/test/java/ru/practicum/shareit/item/dto/CommentDtoTest.java delete mode 100644 src/test/java/ru/practicum/shareit/item/dto/CommentMapperTest.java delete mode 100644 src/test/java/ru/practicum/shareit/item/dto/ItemDtoTest.java delete mode 100644 src/test/java/ru/practicum/shareit/item/repository/CommentRepositoryTest.java delete mode 100644 src/test/java/ru/practicum/shareit/item/repository/ItemRepositoryTest.java delete mode 100644 src/test/java/ru/practicum/shareit/item/service/IntegrationItemServiceImplTest.java delete mode 100644 src/test/java/ru/practicum/shareit/item/service/ItemServiceImplTest.java delete mode 100644 src/test/java/ru/practicum/shareit/request/controller/ItemRequestControllerTest.java delete mode 100644 src/test/java/ru/practicum/shareit/request/dto/ItemRequestDtoTest.java delete mode 100644 src/test/java/ru/practicum/shareit/request/dto/ItemRequestMapperTest.java delete mode 100644 src/test/java/ru/practicum/shareit/request/repository/ItemRequestRepositoryTest.java delete mode 100644 src/test/java/ru/practicum/shareit/request/service/IntegrationItemRequestServiceImplTest.java delete mode 100644 src/test/java/ru/practicum/shareit/request/service/ItemRequestServiceImplTest.java delete mode 100644 src/test/java/ru/practicum/shareit/user/controller/UserControllerTest.java delete mode 100644 src/test/java/ru/practicum/shareit/user/dto/UserDtoTest.java delete mode 100644 src/test/java/ru/practicum/shareit/user/repository/UserRepositoryTest.java delete mode 100644 src/test/java/ru/practicum/shareit/user/service/UserServiceImplTest.java delete mode 100644 src/test/java/ru/practicum/shareit/validation/PagingParametersCheckerTest.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..3ca1e8e15cc500f598f093707b48a20b666ca46b GIT binary patch literal 6148 zcmeHKOKQVF43!c?4cTPbsj*Tp)oKZ%PWGY01v3oU2Fc(}z;ybW_NtJc0CP zG`!?eRn#(yw0j`Cye_b19)%p z{F8qi;?~sQ?wA0^bVQ_o2WIYvLH_pAG~c0e}tC zZdm&)0W6jP*2FOo8JGqY7*x#>LxYZd$-0_21_oU;hY!ssYfdQYPsjbm%SCG-BNdU0eU(!hf0nrzGyE02TOG3TV^s`VOy@y><3-)@uuV54W06xEayczv+1}-BU!wv!}(BXiP)}h9Ha5BVz7#4J`N!$hpP?ZJT;p-M7niPoe*4 zlD(hPmhNanHSO=8Uw8ZdWm}f>rk%rHTu$CUU#{M+4`UX;#;hNI@HF^9iS9n0tIeuu zS2gV5*2Nic2AlzBz!^9i19qX3jpN{$=hZ9FdpPd0`pv%Be zmt(pAZ}7?VHu>EYUpWKLz=<)yqp~VzcqzME4_;61+JJG3AtG@}6bSUrPXHEjj!d#s c{XulZMZ=^hRm7gtf&L?q3GvAp_yY#M0N*k+C;$Ke literal 0 HcmV?d00001 diff --git a/gateway/Dockerfile b/gateway/Dockerfile new file mode 100644 index 0000000..c20c6ca --- /dev/null +++ b/gateway/Dockerfile @@ -0,0 +1,3 @@ +FROM amazoncorretto:11 +COPY gateway/target/*.jar app.jar +ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file diff --git a/gateway/pom.xml b/gateway/pom.xml new file mode 100644 index 0000000..14fe65e --- /dev/null +++ b/gateway/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + + ru.practicum + shareit + 0.0.1-SNAPSHOT + + + shareit-gateway + 0.0.1-SNAPSHOT + + ShareIt Gateway + + + 11 + 11 + UTF-8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-validation + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.apache.httpcomponents + httpclient + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.projectlombok + lombok + true + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + \ No newline at end of file diff --git a/gateway/src/main/java/ru/practicum/shareit/ShareItGateway.java b/gateway/src/main/java/ru/practicum/shareit/ShareItGateway.java new file mode 100644 index 0000000..4cbc16c --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/ShareItGateway.java @@ -0,0 +1,12 @@ +package ru.practicum.shareit; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ShareItGateway { + public static void main(String[] args) { + SpringApplication.run(ShareItGateway.class, args); + } + +} \ No newline at end of file diff --git a/gateway/src/main/java/ru/practicum/shareit/booking/BookingClient.java b/gateway/src/main/java/ru/practicum/shareit/booking/BookingClient.java new file mode 100644 index 0000000..cef20bd --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/booking/BookingClient.java @@ -0,0 +1,66 @@ +package ru.practicum.shareit.booking; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.util.DefaultUriBuilderFactory; +import ru.practicum.shareit.booking.dto.BookingShortDto; +import ru.practicum.shareit.booking.dto.BookingState; +import ru.practicum.shareit.client.BaseClient; + +import java.util.Map; + +@Service +public class BookingClient extends BaseClient { + private static final String API_PREFIX = "/bookings"; + + @Autowired + public BookingClient(@Value("${shareit-server.url}") String serverUrl, RestTemplateBuilder builder) { + super( + builder + .uriTemplateHandler(new DefaultUriBuilderFactory(serverUrl + API_PREFIX)) + .requestFactory(HttpComponentsClientHttpRequestFactory::new) + .build() + ); + } + + public ResponseEntity createBooking(BookingShortDto bookingShortDto, Long userId) { + return post("", userId, bookingShortDto); + } + + public ResponseEntity approveBooking(Long bookingId, Boolean approved, Long userId) { + Map parameters = Map.of( + "approved", approved.toString() + ); + return patch("/" + bookingId + "?approved={approved}", userId, parameters, null); + } + + public ResponseEntity getBooking(Long bookingId, Long userId) { + return get("/" + bookingId, userId); + } + + @GetMapping + public ResponseEntity getAllBookings(Long userId, BookingState state, Long from, Long size) { + Map parameters = Map.of( + "state", state, + "from", from, + "size", size + ); + return get("?state={state}&from={from}&size={size}", userId, parameters); + } + + @GetMapping("/owner") + public ResponseEntity getOwnerBookings(Long userId, BookingState state, Long from, Long size) { + + Map parameters = Map.of( + "state", state, + "from", from, + "size", size + ); + return get("/owner?state={state}&from={from}&size={size}", userId, parameters); + } +} \ No newline at end of file diff --git a/gateway/src/main/java/ru/practicum/shareit/booking/BookingController.java b/gateway/src/main/java/ru/practicum/shareit/booking/BookingController.java new file mode 100644 index 0000000..cd92202 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/booking/BookingController.java @@ -0,0 +1,68 @@ +package ru.practicum.shareit.booking; + +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.MethodParameter; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.BeanPropertyBindingResult; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.*; +import ru.practicum.shareit.booking.dto.BookingShortDto; +import ru.practicum.shareit.booking.dto.BookingState; + +@RestController +@RequestMapping("/bookings") +@Validated +@Slf4j +public class BookingController { + private final BookingClient bookingClient; + + @Autowired + public BookingController(BookingClient bookingClient) { + this.bookingClient = bookingClient; + } + + @SneakyThrows + @PostMapping + public ResponseEntity createBooking(@Validated @RequestBody BookingShortDto bookingShortDto, + @RequestHeader("X-Sharer-User-Id") Long userId) { + if (bookingShortDto.getStart().equals(bookingShortDto.getEnd()) + || bookingShortDto.getStart().isAfter(bookingShortDto.getEnd())) { + throw new MethodArgumentNotValidException(new MethodParameter( + this.getClass().getDeclaredMethod("createBooking", BookingShortDto.class, Long.class), 0), new BeanPropertyBindingResult(bookingShortDto, "bookingShortDto")); + } + + return bookingClient.createBooking(bookingShortDto, userId); + } + + @PatchMapping("/{bookingId}") + public ResponseEntity approveBooking(@PathVariable Long bookingId, + @RequestParam(name = "approved") Boolean approved, + @RequestHeader("X-Sharer-User-Id") Long userId) { + return bookingClient.approveBooking(bookingId, approved, userId); + } + + @GetMapping("/{bookingId}") + public ResponseEntity getBooking(@PathVariable Long bookingId, + @RequestHeader("X-Sharer-User-Id") Long userId) { + return bookingClient.getBooking(bookingId, userId); + } + + @GetMapping + public ResponseEntity getAllBookings(@RequestHeader("X-Sharer-User-Id") Long userId, + @RequestParam(name = "state", defaultValue = "ALL") BookingState state, + @RequestParam(name = "from", defaultValue = "0") Long from, + @RequestParam(name = "size", defaultValue = "20") Long size) { + return bookingClient.getAllBookings(userId, state, from, size); + } + + @GetMapping("/owner") + public ResponseEntity getOwnerBookings(@RequestHeader("X-Sharer-User-Id") Long userId, + @RequestParam(name = "state", defaultValue = "ALL") BookingState state, + @RequestParam(name = "from", defaultValue = "0") Long from, + @RequestParam(name = "size", defaultValue = "20") Long size) { + return bookingClient.getOwnerBookings(userId, state, from, size); + } +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/booking/dto/BookingDto.java b/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingDto.java similarity index 90% rename from src/main/java/ru/practicum/shareit/booking/dto/BookingDto.java rename to gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingDto.java index 2cd63d0..8e7259e 100644 --- a/src/main/java/ru/practicum/shareit/booking/dto/BookingDto.java +++ b/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingDto.java @@ -4,7 +4,6 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import ru.practicum.shareit.booking.BookingStatus; import javax.validation.constraints.FutureOrPresent; import javax.validation.constraints.NotNull; @@ -26,8 +25,6 @@ public class BookingDto { @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") private final LocalDateTime end; - private final BookingStatus status; - private final Item item; private final User booker; diff --git a/src/main/java/ru/practicum/shareit/booking/dto/BookingShortDto.java b/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingShortDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/dto/BookingShortDto.java rename to gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingShortDto.java diff --git a/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingState.java b/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingState.java new file mode 100644 index 0000000..e323915 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingState.java @@ -0,0 +1,10 @@ +package ru.practicum.shareit.booking.dto; + +public enum BookingState { + CURRENT, + PAST, + FUTURE, + ALL, + REJECTED, + WAITING +} \ No newline at end of file diff --git a/gateway/src/main/java/ru/practicum/shareit/client/BaseClient.java b/gateway/src/main/java/ru/practicum/shareit/client/BaseClient.java new file mode 100644 index 0000000..f9781be --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/client/BaseClient.java @@ -0,0 +1,121 @@ +package ru.practicum.shareit.client; + +import java.util.List; +import java.util.Map; + +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.lang.Nullable; +import org.springframework.web.client.HttpStatusCodeException; +import org.springframework.web.client.RestTemplate; + +public class BaseClient { + protected final RestTemplate rest; + + public BaseClient(RestTemplate rest) { + this.rest = rest; + } + + protected ResponseEntity get(String path) { + return get(path, null, null); + } + + protected ResponseEntity get(String path, long userId) { + return get(path, userId, null); + } + + protected ResponseEntity get(String path, Long userId, @Nullable Map parameters) { + return makeAndSendRequest(HttpMethod.GET, path, userId, parameters, null); + } + + protected ResponseEntity post(String path, T body) { + return post(path, null, null, body); + } + + protected ResponseEntity post(String path, long userId, T body) { + return post(path, userId, null, body); + } + + protected ResponseEntity post(String path, Long userId, @Nullable Map parameters, T body) { + return makeAndSendRequest(HttpMethod.POST, path, userId, parameters, body); + } + + protected ResponseEntity put(String path, long userId, T body) { + return put(path, userId, null, body); + } + + protected ResponseEntity put(String path, long userId, @Nullable Map parameters, T body) { + return makeAndSendRequest(HttpMethod.PUT, path, userId, parameters, body); + } + + protected ResponseEntity patch(String path, T body) { + return patch(path, null, null, body); + } + + protected ResponseEntity patch(String path, long userId) { + return patch(path, userId, null, null); + } + + protected ResponseEntity patch(String path, long userId, T body) { + return patch(path, userId, null, body); + } + + protected ResponseEntity patch(String path, Long userId, @Nullable Map parameters, T body) { + return makeAndSendRequest(HttpMethod.PATCH, path, userId, parameters, body); + } + + protected ResponseEntity delete(String path) { + return delete(path, null, null); + } + + protected ResponseEntity delete(String path, long userId) { + return delete(path, userId, null); + } + + protected ResponseEntity delete(String path, Long userId, @Nullable Map parameters) { + return makeAndSendRequest(HttpMethod.DELETE, path, userId, parameters, null); + } + + private ResponseEntity makeAndSendRequest(HttpMethod method, String path, Long userId, @Nullable Map parameters, @Nullable T body) { + HttpEntity requestEntity = new HttpEntity<>(body, defaultHeaders(userId)); + + ResponseEntity shareitServerResponse; + try { + if (parameters != null) { + shareitServerResponse = rest.exchange(path, method, requestEntity, Object.class, parameters); + } else { + shareitServerResponse = rest.exchange(path, method, requestEntity, Object.class); + } + } catch (HttpStatusCodeException e) { + return ResponseEntity.status(e.getStatusCode()).body(e.getResponseBodyAsByteArray()); + } + return prepareGatewayResponse(shareitServerResponse); + } + + private HttpHeaders defaultHeaders(Long userId) { + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.setAccept(List.of(MediaType.APPLICATION_JSON)); + if (userId != null) { + headers.set("X-Sharer-User-Id", String.valueOf(userId)); + } + return headers; + } + + private static ResponseEntity prepareGatewayResponse(ResponseEntity response) { + if (response.getStatusCode().is2xxSuccessful()) { + return response; + } + + ResponseEntity.BodyBuilder responseBuilder = ResponseEntity.status(response.getStatusCode()); + + if (response.hasBody()) { + return responseBuilder.body(response.getBody()); + } + + return responseBuilder.build(); + } +} \ No newline at end of file diff --git a/gateway/src/main/java/ru/practicum/shareit/error/ErrorHandler.java b/gateway/src/main/java/ru/practicum/shareit/error/ErrorHandler.java new file mode 100644 index 0000000..183d5e8 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/error/ErrorHandler.java @@ -0,0 +1,38 @@ +package ru.practicum.shareit.error; + +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseStatus; +import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; + +import java.util.Objects; +import java.util.stream.Collectors; + +@RestControllerAdvice +@Slf4j +public class ErrorHandler { + private final Logger logger = LoggerFactory.getLogger(ErrorHandler.class); + + @ExceptionHandler + @ResponseStatus(HttpStatus.BAD_REQUEST) + public ErrorResponse validationError(final MethodArgumentNotValidException e) { + logger.error("validation failed: {}", e.getMessage(), e); + return new ErrorResponse(e.getBindingResult().getFieldErrors().stream() + .map(FieldError::getField) + .collect(Collectors.toList()) + .toString()); + } + + @ExceptionHandler({MethodArgumentTypeMismatchException.class}) + @ResponseStatus(HttpStatus.BAD_REQUEST) + public ErrorResponse conversionError(final MethodArgumentTypeMismatchException e) { + logger.info("conversion error: {}", e.getMessage(), e); + return new ErrorResponse("Unknown state: " + Objects.requireNonNull(e.getValue())); + } +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/error/ErrorResponse.java b/gateway/src/main/java/ru/practicum/shareit/error/ErrorResponse.java similarity index 100% rename from src/main/java/ru/practicum/shareit/error/ErrorResponse.java rename to gateway/src/main/java/ru/practicum/shareit/error/ErrorResponse.java diff --git a/gateway/src/main/java/ru/practicum/shareit/item/ItemClient.java b/gateway/src/main/java/ru/practicum/shareit/item/ItemClient.java new file mode 100644 index 0000000..56c54cc --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/item/ItemClient.java @@ -0,0 +1,68 @@ +package ru.practicum.shareit.item; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.util.DefaultUriBuilderFactory; +import ru.practicum.shareit.client.BaseClient; +import ru.practicum.shareit.item.dto.CommentDto; +import ru.practicum.shareit.item.dto.ItemDto; + +import java.util.Collections; +import java.util.Map; + +@Service +public class ItemClient extends BaseClient { + private static final String API_PREFIX = "/items"; + + @Autowired + public ItemClient(@Value("${shareit-server.url}") String serverUrl, RestTemplateBuilder builder) { + super( + builder + .uriTemplateHandler(new DefaultUriBuilderFactory(serverUrl + API_PREFIX)) + .requestFactory(HttpComponentsClientHttpRequestFactory::new) + .build() + ); + } + + public ResponseEntity createItem(ItemDto itemDto, Long userId) { + return post("", userId, itemDto); + } + + public ResponseEntity changeItem(ItemDto itemDto, Long itemId, Long userId) { + return patch("/" + itemId, userId, itemDto); + } + + public ResponseEntity getItem(Long itemId, Long userId) { + return get("/" + itemId, userId); + } + + @GetMapping + public ResponseEntity getAllItems(Long userId, Long from, Long size) { + Map parameters = Map.of( + "from", from, + "size", size + ); + return get("", userId, parameters); + } + + public ResponseEntity searchItems(Long userId, String text, Long from, Long size) { + if (text.isBlank()) return new ResponseEntity<>(Collections.emptyList(), HttpStatus.OK); + Map parameters = Map.of( + "text", text, + "from", from, + "size", size + ); + return get("/search?text={text}&from={from}&size={size}", userId, parameters); + } + + public ResponseEntity addComment(Long itemId, CommentDto commentDto, Long userId) { + + return post("/" + itemId + "/comment", userId, commentDto); + } +} \ No newline at end of file diff --git a/gateway/src/main/java/ru/practicum/shareit/item/ItemController.java b/gateway/src/main/java/ru/practicum/shareit/item/ItemController.java new file mode 100644 index 0000000..bccbfc6 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/item/ItemController.java @@ -0,0 +1,68 @@ +package ru.practicum.shareit.item; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import ru.practicum.shareit.item.dto.CommentDto; +import ru.practicum.shareit.item.dto.ItemDto; +import ru.practicum.shareit.validation.ValidationGroups; + +import javax.validation.constraints.Positive; +import javax.validation.constraints.PositiveOrZero; + +@RestController +@RequestMapping(path = "/items") +@Validated +public class ItemController { + + private final ItemClient itemClient; + + @Autowired + public ItemController(ItemClient itemClient) { + this.itemClient = itemClient; + } + + @PostMapping + public ResponseEntity createItem(@Validated(ValidationGroups.Create.class) @RequestBody ItemDto itemDto, + @RequestHeader("X-Sharer-User-Id") Long userId) { + return itemClient.createItem(itemDto, userId); + } + + @PatchMapping("/{itemId}") + public ResponseEntity changeItem(@Validated(ValidationGroups.Update.class) @RequestBody ItemDto itemDto, + @PathVariable Long itemId, + @RequestHeader("X-Sharer-User-Id") Long userId) { + return itemClient.changeItem(itemDto, itemId, userId); + } + + @GetMapping("/{itemId}") + public ResponseEntity getItem(@PathVariable Long itemId, + @RequestHeader("X-Sharer-User-Id") Long userId) { + return itemClient.getItem(itemId, userId); + } + + @GetMapping + public ResponseEntity getAllItems(@RequestHeader("X-Sharer-User-Id") Long userId, + @PositiveOrZero @RequestParam(name = "from", defaultValue = "0") Long from, + @Positive @RequestParam(name = "size", defaultValue = "20") Long size) { + return itemClient.getAllItems(userId, from, size); + } + + @Validated + @GetMapping("/search") + public ResponseEntity searchItems(@RequestParam(name = "text") String text, + @RequestHeader("X-Sharer-User-Id") Long userId, + @PositiveOrZero @RequestParam(name = "from", defaultValue = "0") Long from, + @Positive @RequestParam(name = "size", defaultValue = "20") Long size) { + return itemClient.searchItems(userId, text, from, size); + } + + @Validated + @PostMapping("/{itemId}/comment") + public ResponseEntity addComment(@PathVariable Long itemId, + @Validated @RequestBody CommentDto commentDto, + @RequestHeader("X-Sharer-User-Id") Long userId) { + return itemClient.addComment(itemId, commentDto, userId); + } +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/item/dto/CommentDto.java b/gateway/src/main/java/ru/practicum/shareit/item/dto/CommentDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/dto/CommentDto.java rename to gateway/src/main/java/ru/practicum/shareit/item/dto/CommentDto.java diff --git a/src/main/java/ru/practicum/shareit/item/dto/ItemDto.java b/gateway/src/main/java/ru/practicum/shareit/item/dto/ItemDto.java similarity index 87% rename from src/main/java/ru/practicum/shareit/item/dto/ItemDto.java rename to gateway/src/main/java/ru/practicum/shareit/item/dto/ItemDto.java index a59e3d5..8bbdb80 100644 --- a/src/main/java/ru/practicum/shareit/item/dto/ItemDto.java +++ b/gateway/src/main/java/ru/practicum/shareit/item/dto/ItemDto.java @@ -3,7 +3,6 @@ import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; -import ru.practicum.shareit.booking.dto.BookingShortDto; import ru.practicum.shareit.validation.FieldUpdateConstraint; import ru.practicum.shareit.validation.ValidationGroups; @@ -30,9 +29,6 @@ public class ItemDto { @NotNull(groups = ValidationGroups.Create.class) private final Boolean available; - private final BookingShortDto lastBooking; - private final BookingShortDto nextBooking; - private Long requestId; private final Collection comments; diff --git a/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestClient.java b/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestClient.java new file mode 100644 index 0000000..c335e56 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestClient.java @@ -0,0 +1,49 @@ +package ru.practicum.shareit.request; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Service; +import org.springframework.web.util.DefaultUriBuilderFactory; +import ru.practicum.shareit.client.BaseClient; +import ru.practicum.shareit.request.dto.ItemRequestDto; + +import java.util.Map; + +@Service +public class ItemRequestClient extends BaseClient { + + private static final String API_PREFIX = "/requests"; + + @Autowired + public ItemRequestClient(@Value("${shareit-server.url}") String serverUrl, RestTemplateBuilder builder) { + super( + builder + .uriTemplateHandler(new DefaultUriBuilderFactory(serverUrl + API_PREFIX)) + .requestFactory(HttpComponentsClientHttpRequestFactory::new) + .build() + ); + } + + public ResponseEntity addItemRequest(ItemRequestDto itemRequestDto, Long userId) { + return post("", userId, itemRequestDto); + } + + public ResponseEntity getItemRequests(Long userId) { + return get("", userId); + } + + public ResponseEntity getItemRequest(Long userId, Long requestId) { + return get("/" + requestId, userId); + } + + public ResponseEntity getOtherItemRequests(Long userId, Long from, Long size) { + Map parameters = Map.of( + "from", from, + "size", size + ); + return get("/all?from={from}&size={size}", userId, parameters); + } +} \ No newline at end of file diff --git a/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestController.java b/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestController.java new file mode 100644 index 0000000..f6a507e --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestController.java @@ -0,0 +1,45 @@ +package ru.practicum.shareit.request; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import ru.practicum.shareit.request.dto.ItemRequestDto; + +import javax.validation.constraints.Positive; +import javax.validation.constraints.PositiveOrZero; + +@RestController +@RequestMapping(path = "/requests") +public class ItemRequestController { + private final ItemRequestClient itemRequestClient; + + @Autowired + public ItemRequestController(ItemRequestClient itemRequestClient) { + this.itemRequestClient = itemRequestClient; + } + + @PostMapping + public ResponseEntity addItemRequest(@Validated @RequestBody ItemRequestDto itemRequestDto, + @RequestHeader("X-Sharer-User-Id") Long userId) { + return itemRequestClient.addItemRequest(itemRequestDto, userId); + } + + @GetMapping + public ResponseEntity getItemRequests(@RequestHeader("X-Sharer-User-Id") Long userId) { + return itemRequestClient.getItemRequests(userId); + } + + @GetMapping("/{requestId}") + public ResponseEntity getItemRequest(@RequestHeader("X-Sharer-User-Id") Long userId, + @PathVariable Long requestId) { + return itemRequestClient.getItemRequest(userId, requestId); + } + + @GetMapping("/all") + public ResponseEntity getOtherItemRequests(@RequestHeader("X-Sharer-User-Id") Long userId, + @PositiveOrZero @RequestParam(name = "from", defaultValue = "0") Long from, + @Positive @RequestParam(name = "size", defaultValue = "20") Long size) { + return itemRequestClient.getOtherItemRequests(userId, from, size); + } +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/request/dto/ItemRequestDto.java b/gateway/src/main/java/ru/practicum/shareit/request/dto/ItemRequestDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/dto/ItemRequestDto.java rename to gateway/src/main/java/ru/practicum/shareit/request/dto/ItemRequestDto.java diff --git a/gateway/src/main/java/ru/practicum/shareit/user/UserClient.java b/gateway/src/main/java/ru/practicum/shareit/user/UserClient.java new file mode 100644 index 0000000..467d903 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/user/UserClient.java @@ -0,0 +1,48 @@ +package ru.practicum.shareit.user; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.web.client.RestTemplateBuilder; +import org.springframework.http.ResponseEntity; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Service; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.util.DefaultUriBuilderFactory; +import ru.practicum.shareit.client.BaseClient; +import ru.practicum.shareit.user.dto.UserDto; + +@Service +public class UserClient extends BaseClient { + + private static final String API_PREFIX = "/users"; + + @Autowired + public UserClient(@Value("${shareit-server.url}") String serverUrl, RestTemplateBuilder builder) { + super( + builder + .uriTemplateHandler(new DefaultUriBuilderFactory(serverUrl + API_PREFIX)) + .requestFactory(HttpComponentsClientHttpRequestFactory::new) + .build() + ); + } + + public ResponseEntity createUser(UserDto userDto) { + return post("", userDto); + } + + public ResponseEntity getUser(Long userId) { + return get("/" + userId); + } + + public ResponseEntity getAllUsers() { + return get(""); + } + + public ResponseEntity updateUser(Long userId, UserDto userDto) { + return patch("/" + userId, userDto); + } + + public ResponseEntity deleteUser(@PathVariable Long userId) { + return delete("/" + userId); + } +} \ No newline at end of file diff --git a/gateway/src/main/java/ru/practicum/shareit/user/UserController.java b/gateway/src/main/java/ru/practicum/shareit/user/UserController.java new file mode 100644 index 0000000..eb3b852 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/user/UserController.java @@ -0,0 +1,46 @@ +package ru.practicum.shareit.user; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import ru.practicum.shareit.user.dto.UserDto; +import ru.practicum.shareit.validation.ValidationGroups; + +@RestController +@RequestMapping(path = "/users") +@Validated +public class UserController { + private final UserClient userClient; + + @Autowired + public UserController(UserClient userClient) { + this.userClient = userClient; + } + + @PostMapping + public ResponseEntity createUser(@Validated(ValidationGroups.Create.class) @RequestBody UserDto userDto) { + return userClient.createUser(userDto); + } + + @GetMapping("/{userId}") + public ResponseEntity getUser(@PathVariable Long userId) { + return userClient.getUser(userId); + } + + @GetMapping + public ResponseEntity getAllUsers() { + return userClient.getAllUsers(); + } + + @PatchMapping("/{userId}") + public ResponseEntity updateUser(@PathVariable Long userId, + @Validated(ValidationGroups.Update.class) @RequestBody UserDto userDto) { + return userClient.updateUser(userId, userDto); + } + + @DeleteMapping("/{userId}") + public ResponseEntity deleteUser(@PathVariable Long userId) { + return userClient.deleteUser(userId); + } +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/user/dto/UserDto.java b/gateway/src/main/java/ru/practicum/shareit/user/dto/UserDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/user/dto/UserDto.java rename to gateway/src/main/java/ru/practicum/shareit/user/dto/UserDto.java diff --git a/src/main/java/ru/practicum/shareit/validation/FieldUpdateConstraint.java b/gateway/src/main/java/ru/practicum/shareit/validation/FieldUpdateConstraint.java similarity index 100% rename from src/main/java/ru/practicum/shareit/validation/FieldUpdateConstraint.java rename to gateway/src/main/java/ru/practicum/shareit/validation/FieldUpdateConstraint.java diff --git a/src/main/java/ru/practicum/shareit/validation/FieldUpdateConstraintValidator.java b/gateway/src/main/java/ru/practicum/shareit/validation/FieldUpdateConstraintValidator.java similarity index 100% rename from src/main/java/ru/practicum/shareit/validation/FieldUpdateConstraintValidator.java rename to gateway/src/main/java/ru/practicum/shareit/validation/FieldUpdateConstraintValidator.java diff --git a/src/main/java/ru/practicum/shareit/validation/ValidationGroups.java b/gateway/src/main/java/ru/practicum/shareit/validation/ValidationGroups.java similarity index 100% rename from src/main/java/ru/practicum/shareit/validation/ValidationGroups.java rename to gateway/src/main/java/ru/practicum/shareit/validation/ValidationGroups.java diff --git a/gateway/src/main/resources/application.properties b/gateway/src/main/resources/application.properties new file mode 100644 index 0000000..2ee0851 --- /dev/null +++ b/gateway/src/main/resources/application.properties @@ -0,0 +1,7 @@ +logging.level.org.springframework.web.client.RestTemplate=DEBUG +#logging.level.org.apache.http=DEBUG +#logging.level.httpclient.wire=DEBUG + +server.port=8080 + +shareit-server.url=http://localhost:9090 \ No newline at end of file diff --git a/pom.xml b/pom.xml index ad047a0..b2796d9 100644 --- a/pom.xml +++ b/pom.xml @@ -5,83 +5,43 @@ org.springframework.boot spring-boot-starter-parent - 2.7.2 + 2.7.9 ru.practicum shareit + pom 0.0.1-SNAPSHOT ShareIt - 11 + 11 + 11 + UTF-8 - - - org.springframework.boot - spring-boot-starter-web - - - org.postgresql - postgresql - runtime - - - com.h2database - h2 - runtime - - - org.springframework.boot - spring-boot-configuration-processor - true - - - org.projectlombok - lombok - true - - - org.springframework.boot - spring-boot-starter-test - test - - - org.springframework.boot - spring-boot-starter-validation - - - org.springframework.boot - spring-boot-starter-data-jpa - - + + gateway + server + - - - src/main/resources - true - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - org.projectlombok - lombok - - - - - + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + org.apache.maven.plugins maven-surefire-plugin @@ -228,17 +188,5 @@ - - coverage - - - - org.jacoco - jacoco-maven-plugin - - - - - \ No newline at end of file diff --git a/postman/sprint.json b/postman/sprint.json new file mode 100644 index 0000000..cef1cb0 --- /dev/null +++ b/postman/sprint.json @@ -0,0 +1,11050 @@ +{ + "info": { + "_postman_id": "02b3b696-d51d-4750-b4dc-35e6712fd023", + "name": "Sprint 16 ShareIt (add-docker)", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "2036415" + }, + "item": [ + { + "name": "users", + "item": [ + { + "name": "User 1 create", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has user create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"user@user.com\"').to.eql('user@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"user\"').to.eql('user');", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"user\",\n \"email\": \"user@user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "User 2 create fail duplicate email", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 409\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([409, 500]);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"user\",\n \"email\": \"user@user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "User create fail no email", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"user\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "User create fail invalid email", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"user\",\n \"email\": \"user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "User 1 update", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has user update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"update@user.com\"').to.eql('update@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"update\"').to.eql('update');", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"update\",\n \"email\": \"update@user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "User 3 create", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has user create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 3').to.eql(3);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"user@user.com\"').to.eql('user@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"user\"').to.eql('user');", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"user\",\n \"email\": \"user@user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "User 1 update name", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has user update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"update@user.com\"').to.eql('update@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"updateName\"').to.eql('updateName');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"updateName\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "User 1 update email", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has user update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"updateName@user.com\"').to.eql('updateName@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"updateName\"').to.eql('updateName');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"email\": \"updateName@user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "User 1 update with same email", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has user update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"updateName@user.com\"').to.eql('updateName@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"updateName\"').to.eql('updateName');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"email\": \"updateName@user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "User 1 name update fail email exists", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 409\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([409, 500]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"email\": \"user@user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "User 1 get updated", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has user update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"updateName@user.com\"').to.eql('updateName@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"updateName\"').to.eql('updateName');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "User 3 get", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has user update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 3').to.eql(3);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"user@user.com\"').to.eql('user@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"user\"').to.eql('user');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "3" + } + ] + } + }, + "response": [] + }, + { + "name": "User 100 get unkonwn", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "100" + } + ] + } + }, + "response": [] + }, + { + "name": "User 3 delete", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,204]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "DELETE", + "header": [ + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "3" + } + ] + } + }, + "response": [] + }, + { + "name": "User 4 create after delete", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has user create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 4').to.eql(4);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"user@user.com\"').to.eql('user@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"user\"').to.eql('user');", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"user\",\n \"email\": \"user@user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "User get all", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list user response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test user[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test user[0] 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('email');", + " pm.expect(jsonData[0].email, '\"email\" must be \"updateName@user.com\"').to.eql('updateName@user.com');", + "});", + "pm.test(\"Test user[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('name');", + " pm.expect(jsonData[0].name, '\"name\" must be \"updateName\"').to.eql('updateName');", + "});", + "", + "pm.test(\"Test user[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 4').to.eql(4);", + "});", + "pm.test(\"Test user[1] 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('email');", + " pm.expect(jsonData[1].email, '\"email\" must be \"user@user.com\"').to.eql('user@user.com');", + "});", + "pm.test(\"Test user[1] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('name');", + " pm.expect(jsonData[1].name, '\"name\" must be \"user\"').to.eql('user');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "items", + "item": [ + { + "name": "Item 1 create by user 1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has item create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Дрель\"').to.eql('Дрель');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Простая дрель\"').to.eql('Простая дрель');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Дрель\",\n \"description\": \"Простая дрель\",\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item create without X-Sharer-User-Id", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500, 400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text", + "disabled": true + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Дрель\",\n \"description\": \"Простая дрель\",\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item create with not found user", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404,403]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "10", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Дрель\",\n \"description\": \"Простая дрель\",\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item create without available", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "3", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Отвертка\",\n \"description\": \"Аккумуляторная отвертка\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item create with empty name", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "3", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"\",\n \"description\": \"Аккумуляторная отвертка\",\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item create with empty description", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "3", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Отвертка\",\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "item 1 update", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Дрель+\"').to.eql('Дрель+');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"false\"').to.false;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"id\": 1,\n \"name\": \"Дрель+\",\n \"description\": \"Аккумуляторная дрель\",\n \"available\": false\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "item 1 update without X-Sharer-User-Id", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500, 400]);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text", + "disabled": true + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"id\": 1,\n \"name\": \"Дрель\",\n \"description\": \"Простая дрель\",\n \"available\": false\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "item 1 update with other user 3", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500, 404, 403]);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "3", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Дрель\",\n \"description\": \"Простая дрель\",\n \"available\": false\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "item 1 update available", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Дрель+\"').to.eql('Дрель+');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "item 1 update description", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Дрель+\"').to.eql('Дрель+');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"description\": \"Аккумуляторная дрель + аккумулятор\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "item 1 update name", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "", + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Аккумуляторная дрель\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 1 get from owner user 1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "", + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 1 get from user 4", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Test get item\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.id, '\"id\" field').to.eql(1);", + " pm.expect(jsonData.name, '\"name\" field').to.eql('Аккумуляторная дрель');", + " pm.expect(jsonData.description, '\"description\" field').to.eql('Аккумуляторная дрель + аккумулятор');", + " pm.expect(jsonData.available, '\"available\" field').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 100 get from user 4", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "100" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 2 create by user 4", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has item create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Отвертка\",\n \"description\": \"Аккумуляторная отвертка\",\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item 3 create by user 4", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has item create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 3').to.eql(3);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Тюбик суперклея марки Момент\"').to.eql('Тюбик суперклея марки Момент');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Клей Момент\",\n \"description\": \"Тюбик суперклея марки Момент\",\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item get all user 1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test item[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('name');", + " pm.expect(jsonData[0].name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", + "});", + "pm.test(\"Test item[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('available');", + " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item get all user 4", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test item[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('name');", + " pm.expect(jsonData[0].name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('available');", + " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "", + "", + "pm.test(\"Test item[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 3').to.eql(3);", + "});", + "pm.test(\"Test item[1] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('name');", + " pm.expect(jsonData[1].name, '\"name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "pm.test(\"Test item[1] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('description');", + " pm.expect(jsonData[1].description, '\"description\" must be \"Тюбик суперклея марки Момент\"').to.eql('Тюбик суперклея марки Момент');", + "});", + "pm.test(\"Test item[1] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('available');", + " pm.expect(jsonData[1].available, '\"available\" must be \"true\"').to.true;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item search аккумуляторная", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test item[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('name');", + " pm.expect(jsonData[0].name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", + "});", + "pm.test(\"Test item[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('available');", + " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "", + "pm.test(\"Test item[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item[1] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('name');", + " pm.expect(jsonData[1].name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item[1] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('description');", + " pm.expect(jsonData[1].description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item[1] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('available');", + " pm.expect(jsonData[1].available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/search?text=аккУМУляторная", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + "search" + ], + "query": [ + { + "key": "text", + "value": "аккУМУляторная" + } + ] + } + }, + "response": [] + }, + { + "name": "item 2 update set unavailable", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"false\"').to.false;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"available\": false\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Item search дрель", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test search item response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test item[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('name');", + " pm.expect(jsonData[0].name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", + "});", + "pm.test(\"Test item[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('available');", + " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/search?text=дРелЬ", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + "search" + ], + "query": [ + { + "key": "text", + "value": "дРелЬ" + } + ] + } + }, + "response": [] + }, + { + "name": "Item search аккумуляторная available", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test search item response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test item[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('name');", + " pm.expect(jsonData[0].name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", + "});", + "pm.test(\"Test item[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('available');", + " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/search?text=аккУМУляторная", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + "search" + ], + "query": [ + { + "key": "text", + "value": "аккУМУляторная" + } + ] + } + }, + "response": [] + }, + { + "name": "item 2 update set available", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Item search отвертка", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test search item response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "pm.test(\"Test item[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('name');", + " pm.expect(jsonData[0].name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('available');", + " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/search?text=оТверТ", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + "search" + ], + "query": [ + { + "key": "text", + "value": "оТверТ" + } + ] + } + }, + "response": [] + }, + { + "name": "Item search empty", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test search item response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 0').to.eql(0);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/search?text=", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + "search" + ], + "query": [ + { + "key": "text", + "value": "" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "bookings", + "item": [ + { + "name": "item 2 update set unavailable", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"false\"').to.false;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"available\": false\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking create from user1 to item2 unavailable", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(1, 'd');\r", + "var end = moment().add(2, 'd');\r", + "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "item 2 update set available", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking create failed by wrong userId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500, 404, 403]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(1, 'd');\r", + "var end = moment().add(2, 'd');\r", + "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "100", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking create failed by not found itemId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(1, 'd');\r", + "var end = moment().add(2, 'd');\r", + "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 200,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking create failed by end in past", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(1, 'd');\r", + "var end = moment().add(-1, 'd');\r", + "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking create failed by end before start", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(2, 'd');\r", + "var end = moment().add(1, 'd');\r", + "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking create failed by start equal end", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(2, 'd');\r", + "pm.environment.set('start_equal_end', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start_equal_end}}\",\n \"end\": \"{{start_equal_end}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking create failed by start equal null", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(2, 'd');\r", + "pm.environment.set('start_null', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"end\": \"{{start_null}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking create failed by end equal null", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(2, 'd');\r", + "pm.environment.set('end_null', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{end_null}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking create failed by start in past", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(-1, 'd');\r", + "var end = moment().add(1, 'd');\r", + "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking 1 create from user 1 to item 2 current", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(3, 's');\r", + "var end = moment().add(4, 's')\r", + "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking set approve by owner current", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Has booking patch response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "true" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 2 create from user 1 to item 2", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(1, 'd');\r", + "var end = moment().add(2, 'd');\r", + "pm.environment.set('start2', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end2', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start2}}\",\n \"end\": \"{{end2}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking 2 get by user 1 (booker)", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Has booking get response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "variable": [ + { + "key": "bookingId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 2 get by user 4 (owner)", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Has booking get response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "variable": [ + { + "key": "bookingId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for wrong user 100", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,404,403]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "100", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "" + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for wrong owner user 100", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,404,403]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "100", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", + "});", + "pm.test(\"Test booking[1] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", + "});", + "pm.test(\"Test booking[1] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[1] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[1] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 1 by ALL state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", + "});", + "pm.test(\"Test booking[1] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", + "});", + "pm.test(\"Test booking[1] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[1] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[1] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?state=ALL", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "state", + "value": "ALL" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 1 by FUTURE state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(new Date(jsonData[0].start), '\"start\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(new Date(jsonData[0].end), '\"end\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + "});", + "pm.test(\"Test booking[1] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(new Date(jsonData[1].start), '\"start\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "", + "});", + "pm.test(\"Test booking[1] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(new Date(jsonData[1].end), '\"end\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "});", + "pm.test(\"Test booking[1] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[1] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[1] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?state=FUTURE", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "state", + "value": "FUTURE" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 1 by wrong state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});", + "pm.test(\"Test get user bookings by 'UNSUPPORTED_STATUS' state\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.error, 'Error message').to.be.eql('Unknown state: UNSUPPORTED_STATUS');", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?state=UNSUPPORTED_STATUS", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "state", + "value": "UNSUPPORTED_STATUS" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for owner", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", + "});", + "pm.test(\"Test booking[1] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", + "});", + "pm.test(\"Test booking[1] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[1] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[1] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for owner by ALL state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", + "});", + "pm.test(\"Test booking[1] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", + "});", + "pm.test(\"Test booking[1] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[1] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[1] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?state=ALL", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "state", + "value": "ALL" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for owner by FUTURE state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(new Date(jsonData[0].start), '\"start\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(new Date(jsonData[0].end), '\"end\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + "});", + "pm.test(\"Test booking[1] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(new Date(jsonData[1].start), '\"start\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "", + "});", + "pm.test(\"Test booking[1] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(new Date(jsonData[1].end), '\"end\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "});", + "pm.test(\"Test booking[1] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[1] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[1] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?state=FUTURE", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "state", + "value": "FUTURE" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for owner by wrong state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});", + "pm.test(\"Test get owner bookings by 'UNSUPPORTED_STATUS' state\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.error, 'Error message').to.be.eql('Unknown state: UNSUPPORTED_STATUS');", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?state=UNSUPPORTED_STATUS", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "state", + "value": "UNSUPPORTED_STATUS" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 1000 get from user 4", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "variable": [ + { + "key": "bookingId", + "value": "1000" + } + ] + } + }, + "response": [] + }, + { + "name": "User 5 create", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has user create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"other@other.com\"').to.eql('other@other.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"other\"').to.eql('other');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"other\",\n \"email\": \"other@other.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "Booking 1 get from user 5", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "5", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "variable": [ + { + "key": "bookingId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 2 change status from user 5 fail", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "5", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "variable": [ + { + "key": "bookingId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 2 change status by user 1 (booker)", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "true" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 2 set approve by user 4 (owner)", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Has booking get response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "true" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 2 change status by user 4 (owner) after approve", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "true" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "User 6 create", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has user create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 6').to.eql(6);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"practicum@yandex.ru\"').to.eql('practicum@yandex.ru');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"practicum\"').to.eql('practicum');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"practicum\",\n \"email\": \"practicum@yandex.ru\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "Booking create from user 1 to item 1 failed", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(2, 'd');\r", + "var end = moment().add(3, 'd');\r", + "pm.environment.set('start3', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end3', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 1,\n \"start\": \"{{start3}}\",\n \"end\": \"{{end3}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking 3 create from user 4 to item 1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 3').to.eql(3);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start3') + '\"').to.eql(pm.environment.get('start3'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end3') + '\"').to.eql(pm.environment.get('end3'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"4\"').to.eql(4);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(1, 'd');\r", + "var end = moment().add(1, 'd').add(1, 'h');\r", + "pm.environment.set('start3', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end3', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 1,\n \"start\": \"{{start3}}\",\n \"end\": \"{{end3}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking 3 set rejected by user 1 (owner)", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.ok;", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 3').to.eql(3);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start3') + '\"').to.eql(pm.environment.get('start3'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end3') + '\"').to.eql(pm.environment.get('end3'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"4\"').to.eql(4);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=false", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "false" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "3" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 4 create from user 5 to item 2", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 4').to.eql(4);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start4') + '\"').to.eql(pm.environment.get('start4'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end4') + '\"').to.eql(pm.environment.get('end4'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"5\"').to.eql(5);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(1, 'h');\r", + "var end = moment().add(2, 'h');\r", + "pm.environment.set('start4', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end4', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "5", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start4}}\",\n \"end\": \"{{end4}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking 4 set approve by user 4 (owner)", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Has booking get response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 4').to.eql(4);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start4') + '\"').to.eql(pm.environment.get('start4'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end4') + '\"').to.eql(pm.environment.get('end4'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"5\"').to.eql(5);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "true" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "4" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 2 get by user 4 (owner) with bookings", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "", + "pm.test(\"Test item 'lastBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking).to.have.property('id');", + " pm.expect(jsonData.lastBooking.id, '\"lastBooking.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test item 'lastBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking).to.have.property('bookerId');", + " pm.expect(jsonData.lastBooking.bookerId, '\"lastBooking.bookerId\" must be \"1\"').to.eql(1);", + "});", + "", + "pm.test(\"Test item 'nextBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking).to.have.property('id');", + " pm.expect(jsonData.nextBooking.id, '\"nextBooking.id\" must be \"1\"').to.eql(4);", + "});", + "pm.test(\"Test item 'nextBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking).to.have.property('bookerId');", + " pm.expect(jsonData.nextBooking.bookerId, '\"nextBooking.bookerId\" must be \"1\"').to.eql(5);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var time = setTimeout(function(){}, 4000);\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 2 get by user 1 without bookings", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "", + "pm.test(\"Test item 'lastBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking, '\"lastBooking\" must be \"null\"').null;", + "});", + "pm.test(\"Test item 'nextBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 2 get by user 5 without bookings", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "", + "pm.test(\"Test item 'lastBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking, '\"lastBooking\" must be \"null\"').null;", + "});", + "pm.test(\"Test item 'nextBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "5", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Item get all user 4 with bookings", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test item[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('name');", + " pm.expect(jsonData[0].name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('available');", + " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test item[0] 'lastBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('lastBooking');", + " pm.expect(jsonData[0].lastBooking).to.have.property('id');", + " pm.expect(jsonData[0].lastBooking.id, '\"lastBooking.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test item[0] 'lastBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('lastBooking');", + " pm.expect(jsonData[0].lastBooking).to.have.property('bookerId');", + " pm.expect(jsonData[0].lastBooking.bookerId, '\"lastBooking.bookerId\" must be \"1\"').to.eql(1);", + "});", + "", + "pm.test(\"Test item[0] 'nextBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('nextBooking');", + " pm.expect(jsonData[0].nextBooking).to.have.property('id');", + " pm.expect(jsonData[0].nextBooking.id, '\"nextBooking.id\" must be \"1\"').to.eql(4);", + "});", + "pm.test(\"Test item[0] 'nextBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('nextBooking');", + " pm.expect(jsonData[0].nextBooking).to.have.property('bookerId');", + " pm.expect(jsonData[0].nextBooking.bookerId, '\"nextBooking.bookerId\" must be \"1\"').to.eql(5);", + "});", + "", + "", + "pm.test(\"Test item[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 3').to.eql(3);", + "});", + "pm.test(\"Test item[1] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('name');", + " pm.expect(jsonData[1].name, '\"name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "pm.test(\"Test item[1] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('description');", + " pm.expect(jsonData[1].description, '\"description\" must be \"Тюбик суперклея марки Момент\"').to.eql('Тюбик суперклея марки Момент');", + "});", + "pm.test(\"Test item[1] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('available');", + " pm.expect(jsonData[1].available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test item[1] 'lastBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('lastBooking');", + " pm.expect(jsonData[1].lastBooking, '\"lastBooking\" must be \"null\"').null;", + "});", + "pm.test(\"Test item[1] 'nextBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('nextBooking');", + " pm.expect(jsonData[1].nextBooking, '\"nextBooking\" must be \"null\"').null;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Booking 5 create from user 1 to item 3 current", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"3\"').to.eql(3);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(3, 's');\r", + "var end = moment().add(1, 'd')\r", + "pm.environment.set('start5', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end5', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 3,\n \"start\": \"{{start5}}\",\n \"end\": \"{{end5}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 1 by WAITING state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?state=WAITING", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "state", + "value": "WAITING" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 4 (owner) by WAITING state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?state=WAITING", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "state", + "value": "WAITING" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 6 create from user 1 to item 2 current", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 6').to.eql(6);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start6') + '\"').to.eql(pm.environment.get('start6'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end6') + '\"').to.eql(pm.environment.get('end6'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(3, 's');\r", + "var end = moment().add(4, 's')\r", + "pm.environment.set('start6', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end6', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start6}}\",\n \"end\": \"{{end6}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking 5 set rejected by user 4 (owner)", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"3\"').to.eql(3);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=false", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "false" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "5" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 1 by REJECTED state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?state=REJECTED", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "state", + "value": "REJECTED" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 4 (owner) by REJECTED state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?state=REJECTED", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "state", + "value": "REJECTED" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 6 set approve by owner 4 current", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Has booking patch response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 6').to.eql(6);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start6') + '\"').to.eql(pm.environment.get('start6'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end6') + '\"').to.eql(pm.environment.get('end6'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "true" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "6" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "comments", + "item": [ + { + "name": "Item 4 create by user 6", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has item create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 4').to.eql(4);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Кухонный стол\"').to.eql('Кухонный стол');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Стол для празднования\"').to.eql('Стол для празднования');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "6", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Кухонный стол\",\n \"description\": \"Стол для празднования\",\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item 1 get from user 1 (owner) without comments", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "", + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test item 'lastBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking, '\"lastBooking\" must be \"null\"').null;", + "});", + "pm.test(\"Test item 'nextBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", + "});", + "pm.test(\"Test item 'comments' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('comments');", + " pm.expect(jsonData.comments.length, 'length of \"comments\" must be \"0\"').to.eql(0);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 7 future create from user 5 to item 1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 7').to.eql(7);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start7') + '\"').to.eql(pm.environment.get('start7'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end7') + '\"').to.eql(pm.environment.get('end7'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"5\"').to.eql(5);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(10, 'd');\r", + "var end = moment().add(11, 'd')\r", + "pm.environment.set('start7', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end7', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "5", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 1,\n \"start\": \"{{start7}}\",\n \"end\": \"{{end7}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking 8 create from user 1 to item 4 start past and end future", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 8').to.eql(8);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start8') + '\"').to.eql(pm.environment.get('start8'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end8') + '\"').to.eql(pm.environment.get('end8'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"4\"').to.eql(4);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Кухонный стол\"').to.eql('Кухонный стол');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(2, 's');\r", + "var end = moment().add(1, 'h');\r", + "pm.environment.set('start8', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end8', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 4,\n \"start\": \"{{start8}}\",\n \"end\": \"{{end8}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking 8 set approve by user 6 (owner)", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Has booking get response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 8').to.eql(8);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start8') + '\"').to.eql(pm.environment.get('start8'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end8') + '\"').to.eql(pm.environment.get('end8'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"4\"').to.eql(4);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Кухонный стол\"').to.eql('Кухонный стол');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "6", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "true" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "8" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 2 get from user 1 without comments", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test item 'lastBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking, '\"lastBooking\" must be \"null\"').null;", + "});", + "pm.test(\"Test item 'nextBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", + "});", + "", + "pm.test(\"Test item 'comments' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('comments');", + " pm.expect(jsonData.comments.length, 'length of \"comments\" must be \"0\"').to.eql(0);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var time = setTimeout(function(){}, 3000);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 2 get from user 4 (owner) without comments", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "", + "pm.test(\"Test item 'lastBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking).to.have.property('id');", + " pm.expect(jsonData.lastBooking.id, '\"lastBooking.id\" must be \"6\"').to.eql(6);", + "});", + "pm.test(\"Test item 'lastBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking).to.have.property('bookerId');", + " pm.expect(jsonData.lastBooking.bookerId, '\"lastBooking.bookerId\" must be \"1\"').to.eql(1);", + "});", + "", + "pm.test(\"Test item 'nextBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking).to.have.property('id');", + " pm.expect(jsonData.nextBooking.id, '\"nextBooking.id\" must be \"1\"').to.eql(4);", + "});", + "pm.test(\"Test item 'nextBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking).to.have.property('bookerId');", + " pm.expect(jsonData.nextBooking.bookerId, '\"nextBooking.bookerId\" must be \"1\"').to.eql(5);", + "});", + "", + "pm.test(\"Test item 'comments' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('comments');", + " pm.expect(jsonData.comments.length, 'length of \"comments\" must be \"0\"').to.eql(0);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var time = setTimeout(function(){}, 3000);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Comment from user 4 to item 1 without booking failed", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + }, + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"text\": \"Comment for item 1\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId/comment", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId", + "comment" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Comment from user 1 to item 2 empty failed", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + }, + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"text\": \"\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId/comment", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId", + "comment" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Comment 1 from user 1 to item 2", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Test add comment to item 2 from user1\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.id, '\"id\" field').to.eql(1);", + " pm.expect(jsonData.text, '\"text\" field').to.eql(\"Add comment from user1\");", + " pm.expect(jsonData.authorName, '\"authorName\" field').to.eql(\"updateName\");", + " pm.expect(jsonData.created, '\"created\" field').not.null;", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment();\r", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + }, + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"text\": \"Add comment from user1\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId/comment", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId", + "comment" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 2 get by user 1 with comments", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test item 'lastBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking, '\"lastBooking\" must be \"null\"').null;", + "});", + "pm.test(\"Test item 'nextBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", + "});", + "", + "pm.test(\"Test item 'comments' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('comments');", + " pm.expect(jsonData.comments.length, 'length of \"comments\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test item 'comments[0].id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.comments[0]).to.have.property('id');", + " pm.expect(jsonData.comments[0].id, '\"id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test item 'comments[0].text' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.comments[0]).to.have.property('text');", + " pm.expect(jsonData.comments[0].text, '\"text\" must be \"Add comment from user1\"').to.eql('Add comment from user1');", + "});", + "pm.test(\"Test item 'comments[0].authorName' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.comments[0]).to.have.property('authorName');", + " pm.expect(jsonData.comments[0].authorName, '\"authorName\" must be \"updateName\"').to.eql(\"updateName\");", + "});", + "pm.test(\"Test item 'comments[0].created' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.comments[0]).to.have.property('created');", + " pm.expect(new Date(jsonData.comments[0].created), '\"created\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 2 get by user 4 (owner) with comments", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "", + "pm.test(\"Test item 'lastBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking).to.have.property('id');", + " pm.expect(jsonData.lastBooking.id, '\"lastBooking.id\" must be \"6\"').to.eql(6);", + "});", + "pm.test(\"Test item 'lastBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking).to.have.property('bookerId');", + " pm.expect(jsonData.lastBooking.bookerId, '\"lastBooking.bookerId\" must be \"1\"').to.eql(1);", + "});", + "", + "pm.test(\"Test item 'nextBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking).to.have.property('id');", + " pm.expect(jsonData.nextBooking.id, '\"nextBooking.id\" must be \"1\"').to.eql(4);", + "});", + "pm.test(\"Test item 'nextBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking).to.have.property('bookerId');", + " pm.expect(jsonData.nextBooking.bookerId, '\"nextBooking.bookerId\" must be \"1\"').to.eql(5);", + "});", + "", + "pm.test(\"Test item 'comments' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('comments');", + " pm.expect(jsonData.comments.length, 'length of \"comments\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test item 'comments[0].id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.comments[0]).to.have.property('id');", + " pm.expect(jsonData.comments[0].id, '\"id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test item 'comments[0].text' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.comments[0]).to.have.property('text');", + " pm.expect(jsonData.comments[0].text, '\"text\" must be \"Add comment from user1\"').to.eql('Add comment from user1');", + "});", + "pm.test(\"Test item 'comments[0].authorName' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.comments[0]).to.have.property('authorName');", + " pm.expect(jsonData.comments[0].authorName, '\"authorName\" must be \"updateName\"').to.eql(\"updateName\");", + "});", + "pm.test(\"Test item 'comments[0].created' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.comments[0]).to.have.property('created');", + " pm.expect(new Date(jsonData.comments[0].created), '\"created\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 7 set approve by owner future", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 7').to.eql(7);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start7') + '\"').to.eql(pm.environment.get('start7'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end7') + '\"').to.eql(pm.environment.get('end7'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"5\"').to.eql(5);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "true" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "7" + } + ] + } + }, + "response": [] + }, + { + "name": "Add comment to item 1 from user5 failed by future booking", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + }, + { + "key": "X-Sharer-User-Id", + "value": "5", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"text\": \"Add comment from user5\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId/comment", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId", + "comment" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 1 by CURRENT state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 8').to.eql(8);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start8') + '\"').to.eql(pm.environment.get('start8'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end8') + '\"').to.eql(pm.environment.get('end8'));", + "});", + "pm.test(\"Test booking[1] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"4\"').to.eql(4);", + "});", + "pm.test(\"Test booking[1] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Кухонный стол\"').to.eql('Кухонный стол');", + "});", + "", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?state=CURRENT", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "state", + "value": "CURRENT" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 4 (owner) by CURRENT state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?state=CURRENT", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "state", + "value": "CURRENT" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 1 by PAST state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 6').to.eql(6);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start6') + '\"').to.eql(pm.environment.get('start6'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end6') + '\"').to.eql(pm.environment.get('end6'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?state=PAST", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "state", + "value": "PAST" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 4 (owner) by PAST state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 6').to.eql(6);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start6') + '\"').to.eql(pm.environment.get('start6'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end6') + '\"').to.eql(pm.environment.get('end6'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?state=PAST", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "state", + "value": "PAST" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 4 get by user 6 (owner) without comments", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 4').to.eql(4);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Кухонный стол\"').to.eql('Кухонный стол');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Стол для празднования\"').to.eql('Стол для празднования');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "", + "pm.test(\"Test item 'lastBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking).to.have.property('id');", + " pm.expect(jsonData.lastBooking.id, '\"lastBooking.id\" must be \"8\"').to.eql(8);", + "});", + "pm.test(\"Test item 'lastBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking).to.have.property('bookerId');", + " pm.expect(jsonData.lastBooking.bookerId, '\"lastBooking.bookerId\" must be \"1\"').to.eql(1);", + "});", + "", + "pm.test(\"Test item 'nextBooking'\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "6", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "4" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "item requests", + "item": [ + { + "name": "Add item request with wrong user", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,404,403]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "99", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"description\": \"Хотел бы воспользоваться щёткой для обуви\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{baseUrl}}/requests", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests" + ] + } + }, + "response": [] + }, + { + "name": "Add item request with empty description", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"description\": null\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{baseUrl}}/requests", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests" + ] + } + }, + "response": [] + }, + { + "name": "Requests get own by wrong user id", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,404,403]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "99", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests" + ] + } + }, + "response": [] + }, + { + "name": "Requests get own by user id without requests", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item requests response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 0').to.eql(0);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests" + ] + } + }, + "response": [] + }, + { + "name": "Requests get all without pagination params", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item requests response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 0').to.eql(0);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/all", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "all" + ] + } + }, + "response": [] + }, + { + "name": "Requests get all with from = 0 & size = 0", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/all?from=0&size=0", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "all" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "0" + } + ] + } + }, + "response": [] + }, + { + "name": "Requests get all with from = -1 & size = 20", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/all?from=-1&size=20", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "all" + ], + "query": [ + { + "key": "from", + "value": "-1" + }, + { + "key": "size", + "value": "20" + } + ] + } + }, + "response": [] + }, + { + "name": "Requests get all with from = 0 & size = -1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/all?from=0&size=-1", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "all" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "-1" + } + ] + } + }, + "response": [] + }, + { + "name": "Requests get all with from = 0 & size = 20 when empty", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item requests response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 0').to.eql(0);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/all?from=0&size=20", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "all" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "20" + } + ] + } + }, + "response": [] + }, + { + "name": "Add item request 1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has item request create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item request 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item request 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", + "});", + "pm.test(\"Test item request 'created' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('created');", + " pm.expect(jsonData.created, '\"created\" must be not null').is.not.null;", + "", + " var current = pm.environment.get('currentDateTime');", + " var created = new Date(jsonData.created);", + " var future = new Date(current);", + " future.setSeconds(future.getSeconds() + 2);", + " pm.expect(created, '\"created\" must be > ' + pm.environment.get('currentDateTime')).to.gte(new Date(current));", + " pm.expect(created, '\"created\" must be < ' + future).to.lte(future);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"description\": \"Хотел бы воспользоваться щёткой для обуви\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{baseUrl}}/requests", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests" + ] + } + }, + "response": [] + }, + { + "name": "Requests get own by user id with requests empty items", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item requests response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test item request[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item request[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", + "});", + "pm.test(\"Test item request[0] 'created' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('created');", + " pm.expect(jsonData[0].created, '\"created\" must be not null').is.not.null;", + "});", + "pm.test(\"Test item request[0] 'items' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('items');", + " pm.expect(jsonData[0].items, '\"items\" must be not null').is.not.null;", + " pm.expect(jsonData[0].items.length, 'items count in total').to.eql(0);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var time = setTimeout(function(){}, 1000);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests" + ] + } + }, + "response": [] + }, + { + "name": "Add item 5 to request 1 from user 4", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has item create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Щётка для обуви\"').to.eql('Щётка для обуви');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Стандартная щётка для обуви\"').to.eql('Стандартная щётка для обуви');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test item 'requestId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('requestId');", + " pm.expect(jsonData.requestId, '\"requestId\" must be \"1\"').to.eq(1);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Щётка для обуви\",\n \"description\": \"Стандартная щётка для обуви\",\n \"available\": true,\n \"requestId\": 1\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Requests get own by user id with requests", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item requests response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test item request[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item request[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", + "});", + "pm.test(\"Test item request[0] 'created' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('created');", + " pm.expect(jsonData[0].created, '\"created\" must be not null').is.not.null;", + " ", + " var created = new Date(jsonData[0].created);", + " var future = new Date(pm.environment.get('currentDateTime'));", + " pm.expect(created, '\"created\" must be < ' + pm.environment.get('currentDateTime')).to.lte(future);", + "});", + "pm.test(\"Test item request[0] 'items' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('items');", + " pm.expect(jsonData[0].items, '\"items\" must be not null').is.not.null;", + " pm.expect(jsonData[0].items.length, 'items count must be 1').to.eql(1);", + "});", + "pm.test(\"Test request[0].items[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('id');", + " pm.expect(jsonData[0].items[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test request[0].items[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('name');", + " pm.expect(jsonData[0].items[0].name, '\"name\" must be \"Щётка для обуви\"').to.eql('Щётка для обуви');", + "});", + "pm.test(\"Test request[0].items[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('description');", + " pm.expect(jsonData[0].items[0].description, '\"description\" must be \"Стандартная щётка для обуви\"').to.eql('Стандартная щётка для обуви');", + "});", + "pm.test(\"Test request[0].items[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('available');", + " pm.expect(jsonData[0].items[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test request[0].items[0] 'requestId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('requestId');", + " pm.expect(jsonData[0].items[0].requestId, '\"requestId\" must be \"1\"').to.eq(1);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss.sss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests" + ] + } + }, + "response": [] + }, + { + "name": "Requests get all with from = 0 & size = 20 for request owner", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item requests response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 0').to.eql(0);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/all?from=0&size=20", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "all" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "20" + } + ] + } + }, + "response": [] + }, + { + "name": "Requests get all with from = 0 & size = 20 for other user", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item requests response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test item request[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item request[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", + "});", + "pm.test(\"Test item request[0] 'created' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('created');", + " pm.expect(jsonData[0].created, '\"created\" must be not null').is.not.null;", + " ", + " var created = new Date(jsonData[0].created);", + " var future = new Date(pm.environment.get('currentDateTime'));", + " pm.expect(created, '\"created\" must be < ' + pm.environment.get('currentDateTime')).to.lte(future);", + "});", + "pm.test(\"Test item request[0] 'items' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('items');", + " pm.expect(jsonData[0].items, '\"items\" must be not null').is.not.null;", + " pm.expect(jsonData[0].items.length, 'items count must be 1').to.eql(1);", + "});", + "pm.test(\"Test request[0].items[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('id');", + " pm.expect(jsonData[0].items[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test request[0].items[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('name');", + " pm.expect(jsonData[0].items[0].name, '\"name\" must be \"Щётка для обуви\"').to.eql('Щётка для обуви');", + "});", + "pm.test(\"Test request[0].items[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('description');", + " pm.expect(jsonData[0].items[0].description, '\"description\" must be \"Стандартная щётка для обуви\"').to.eql('Стандартная щётка для обуви');", + "});", + "pm.test(\"Test request[0].items[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('available');", + " pm.expect(jsonData[0].items[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test request[0].items[0] 'requestId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('requestId');", + " pm.expect(jsonData[0].items[0].requestId, '\"requestId\" must be \"1\"').to.eq(1);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss.sss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/all?from=0&size=20", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "all" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "20" + } + ] + } + }, + "response": [] + }, + { + "name": "Requests get by id for wrong user", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500, 404, 403]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "99", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/1", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "1" + ] + } + }, + "response": [] + }, + { + "name": "Requests get by wrong id", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/99", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "99" + ] + } + }, + "response": [] + }, + { + "name": "Requests get by id for other user", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test item request response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "", + "pm.test(\"Test item request 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item request 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", + "});", + "pm.test(\"Test item request 'created' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('created');", + " pm.expect(jsonData.created, '\"created\" must be not null').is.not.null;", + "", + " var created = new Date(jsonData.created);", + " var future = new Date(pm.environment.get('currentDateTime'));", + " pm.expect(created, '\"created\" must be < ' + pm.environment.get('currentDateTime')).to.lte(future);", + "});", + "pm.test(\"Test item request 'items' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('items');", + " pm.expect(jsonData.items, '\"items\" must be not null').is.not.null;", + " pm.expect(jsonData.items.length, 'items count must be 1').to.eql(1);", + "});", + "pm.test(\"Test request.items[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('id');", + " pm.expect(jsonData.items[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test request.items[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('name');", + " pm.expect(jsonData.items[0].name, '\"name\" must be \"Щётка для обуви\"').to.eql('Щётка для обуви');", + "});", + "pm.test(\"Test request.items[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('description');", + " pm.expect(jsonData.items[0].description, '\"description\" must be \"Стандартная щётка для обуви\"').to.eql('Стандартная щётка для обуви');", + "});", + "pm.test(\"Test request.items[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('available');", + " pm.expect(jsonData.items[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test request.items[0] 'requestId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('requestId');", + " pm.expect(jsonData.items[0].requestId, '\"requestId\" must be \"1\"').to.eq(1);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment();\r", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss.sss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/1", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "1" + ] + } + }, + "response": [] + }, + { + "name": "Requests get by id", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test item request response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "", + "pm.test(\"Test item request 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item request 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", + "});", + "pm.test(\"Test item request 'created' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('created');", + " pm.expect(jsonData.created, '\"created\" must be not null').is.not.null;", + "", + " var created = new Date(jsonData.created);", + " var future = new Date(pm.environment.get('currentDateTime'));", + " pm.expect(created, '\"created\" must be < ' + pm.environment.get('currentDateTime')).to.lte(future);", + "});", + "pm.test(\"Test item request 'items' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('items');", + " pm.expect(jsonData.items, '\"items\" must be not null').is.not.null;", + " pm.expect(jsonData.items.length, 'items count must be 1').to.eql(1);", + "});", + "pm.test(\"Test request.items[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('id');", + " pm.expect(jsonData.items[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test request.items[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('name');", + " pm.expect(jsonData.items[0].name, '\"name\" must be \"Щётка для обуви\"').to.eql('Щётка для обуви');", + "});", + "pm.test(\"Test request.items[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('description');", + " pm.expect(jsonData.items[0].description, '\"description\" must be \"Стандартная щётка для обуви\"').to.eql('Стандартная щётка для обуви');", + "});", + "pm.test(\"Test request.items[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('available');", + " pm.expect(jsonData.items[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test request.items[0] 'requestId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('requestId');", + " pm.expect(jsonData.items[0].requestId, '\"requestId\" must be \"1\"').to.eq(1);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss.sss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/1", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "1" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Pagination", + "item": [ + { + "name": "Bookings get all with from = 0 & size = 0", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?from=0&size=0", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "0" + } + ] + } + }, + "response": [] + }, + { + "name": "Bookings owner get all with from = 0 & size = 0", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?from=0&size=0", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "0" + } + ] + } + }, + "response": [] + }, + { + "name": "Bookings get all with from = -1 & size = 20", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?from=-1&size=20", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "from", + "value": "-1" + }, + { + "key": "size", + "value": "20" + } + ] + } + }, + "response": [] + }, + { + "name": "Bookings owner get all with from = -1 & size = 20", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?from=-1&size=20", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "from", + "value": "-1" + }, + { + "key": "size", + "value": "20" + } + ] + } + }, + "response": [] + }, + { + "name": "Bookings get all with from = 0 & size = -1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?from=0&size=-1", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "-1" + } + ] + } + }, + "response": [] + }, + { + "name": "Bookings owner get all with from = 0 & size = -1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?from=0&size=-1", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "-1" + } + ] + } + }, + "response": [] + }, + { + "name": "Bookings get all with from = 4 & size = 2 when all=5", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Test get all bookings\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'bookings count in total').to.eql(1);", + " pm.expect(jsonData[0].id, 'result[0]: \"id\" field').to.eql(1);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?from=4&size=2", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "from", + "value": "4" + }, + { + "key": "size", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Bookings owner get all with from = 1 & size = 1 when all=2", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Test get all owner bookings\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'owner bookings count in total').to.eql(1);", + " pm.expect(jsonData[0].id, 'result[0]: \"id\" field').to.eql(3);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?from=1&size=1", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "from", + "value": "1" + }, + { + "key": "size", + "value": "1" + } + ] + } + }, + "response": [] + } + ] + } + ], + "variable": [ + { + "key": "baseUrl", + "value": "http://localhost:8080" + } + ] +} \ No newline at end of file diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..396cccb --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,4 @@ +FROM amazoncorretto:11 +COPY server/target/*.jar app.jar +EXPOSE 9090 +ENTRYPOINT ["java","-jar","/app.jar", "--server.port=9090"] \ No newline at end of file diff --git a/server/pom.xml b/server/pom.xml new file mode 100644 index 0000000..5dd8414 --- /dev/null +++ b/server/pom.xml @@ -0,0 +1,86 @@ + + + 4.0.0 + + ru.practicum + shareit + 0.0.1-SNAPSHOT + + + shareit-server + 0.0.1-SNAPSHOT + + ShareIt Server + + + + org.springframework.boot + spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-actuator + + + + org.postgresql + postgresql + runtime + + + + com.h2database + h2 + runtime + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + org.projectlombok + lombok + true + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + + + coverage + + + + org.jacoco + jacoco-maven-plugin + + + + + + + \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/ShareItApp.java b/server/src/main/java/ru/practicum/shareit/ShareItApp.java similarity index 65% rename from src/main/java/ru/practicum/shareit/ShareItApp.java rename to server/src/main/java/ru/practicum/shareit/ShareItApp.java index a00ad56..0fdb8ca 100644 --- a/src/main/java/ru/practicum/shareit/ShareItApp.java +++ b/server/src/main/java/ru/practicum/shareit/ShareItApp.java @@ -6,8 +6,8 @@ @SpringBootApplication public class ShareItApp { - public static void main(String[] args) { - SpringApplication.run(ShareItApp.class, args); - } + public static void main(String[] args) { + SpringApplication.run(ShareItApp.class, args); + } -} +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/booking/BookingState.java b/server/src/main/java/ru/practicum/shareit/booking/BookingState.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/BookingState.java rename to server/src/main/java/ru/practicum/shareit/booking/BookingState.java diff --git a/src/main/java/ru/practicum/shareit/booking/BookingStatus.java b/server/src/main/java/ru/practicum/shareit/booking/BookingStatus.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/BookingStatus.java rename to server/src/main/java/ru/practicum/shareit/booking/BookingStatus.java diff --git a/src/main/java/ru/practicum/shareit/booking/controller/BookingController.java b/server/src/main/java/ru/practicum/shareit/booking/controller/BookingController.java similarity index 61% rename from src/main/java/ru/practicum/shareit/booking/controller/BookingController.java rename to server/src/main/java/ru/practicum/shareit/booking/controller/BookingController.java index 2e3c2a7..0961dd5 100644 --- a/src/main/java/ru/practicum/shareit/booking/controller/BookingController.java +++ b/server/src/main/java/ru/practicum/shareit/booking/controller/BookingController.java @@ -1,15 +1,12 @@ package ru.practicum.shareit.booking.controller; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import ru.practicum.shareit.booking.BookingState; import ru.practicum.shareit.booking.dto.BookingDto; import ru.practicum.shareit.booking.dto.BookingShortDto; import ru.practicum.shareit.booking.service.BookingService; -import javax.validation.constraints.Positive; -import javax.validation.constraints.PositiveOrZero; import java.util.Collection; @RestController @@ -23,37 +20,37 @@ public BookingController(BookingService bookingService) { } @PostMapping - public BookingDto create(@Validated @RequestBody BookingShortDto bookingShortDto, + public BookingDto createBooking(@RequestBody BookingShortDto bookingShortDto, @RequestHeader("X-Sharer-User-Id") Long userId) { return bookingService.createBooking(bookingShortDto, userId); } @PatchMapping("/{bookingId}") - public BookingDto approve(@PathVariable Long bookingId, + public BookingDto approveBooking(@PathVariable Long bookingId, @RequestParam(name = "approved") Boolean approved, @RequestHeader("X-Sharer-User-Id") Long userId) { return bookingService.approveBooking(bookingId, approved, userId); } @GetMapping("/{bookingId}") - public BookingDto get(@PathVariable Long bookingId, + public BookingDto getBooking(@PathVariable Long bookingId, @RequestHeader("X-Sharer-User-Id") Long userId) { return bookingService.getBooking(bookingId, userId); } @GetMapping - public Collection getAll(@RequestHeader("X-Sharer-User-Id") Long userId, + public Collection getAllBookings(@RequestHeader("X-Sharer-User-Id") Long userId, @RequestParam(name = "state", required = false, defaultValue = "ALL") BookingState state, - @PositiveOrZero @RequestParam(name = "from", required = false, defaultValue = "0") Long from, - @Positive @RequestParam(name = "size", required = false, defaultValue = "20") Long size) { + @RequestParam(name = "from", required = false, defaultValue = "0") Long from, + @RequestParam(name = "size", required = false, defaultValue = "20") Long size) { return bookingService.getAllBookings(userId, state, from, size); } @GetMapping("/owner") - public Collection getByOwnerBookings(@RequestHeader("X-Sharer-User-Id") Long userId, + public Collection getOwnerBookings(@RequestHeader("X-Sharer-User-Id") Long userId, @RequestParam(name = "state", required = false, defaultValue = "ALL") BookingState state, - @PositiveOrZero @RequestParam(name = "from", required = false, defaultValue = "0") Long from, - @Positive @RequestParam(name = "size", required = false, defaultValue = "20") Long size) { + @RequestParam(name = "from", required = false, defaultValue = "0") Long from, + @RequestParam(name = "size", required = false, defaultValue = "20") Long size) { return bookingService.getOwnerBookings(userId, state, from, size); } } \ No newline at end of file diff --git a/server/src/main/java/ru/practicum/shareit/booking/dto/BookingDto.java b/server/src/main/java/ru/practicum/shareit/booking/dto/BookingDto.java new file mode 100644 index 0000000..e497d77 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/booking/dto/BookingDto.java @@ -0,0 +1,39 @@ +package ru.practicum.shareit.booking.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import ru.practicum.shareit.booking.BookingStatus; + +import java.time.LocalDateTime; + +@Data +@AllArgsConstructor +@Builder +public class BookingDto { + private final Long id; + + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") + private final LocalDateTime start; + + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") + private final LocalDateTime end; + + private final BookingStatus status; + + private final Item item; + private final User booker; + + @Data + public static class Item { + private final Long id; + private final String name; + } + + @Data + public static class User { + private final Long id; + private final String name; + } +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/booking/dto/BookingMapper.java b/server/src/main/java/ru/practicum/shareit/booking/dto/BookingMapper.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/dto/BookingMapper.java rename to server/src/main/java/ru/practicum/shareit/booking/dto/BookingMapper.java diff --git a/server/src/main/java/ru/practicum/shareit/booking/dto/BookingShortDto.java b/server/src/main/java/ru/practicum/shareit/booking/dto/BookingShortDto.java new file mode 100644 index 0000000..9879173 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/booking/dto/BookingShortDto.java @@ -0,0 +1,25 @@ +package ru.practicum.shareit.booking.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; + +import java.time.LocalDateTime; + +@Data +@AllArgsConstructor +@Builder +public class BookingShortDto { + private final Long id; + + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") + private final LocalDateTime start; + + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss") + private final LocalDateTime end; + + private final Long itemId; + + private final Long bookerId; +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/booking/model/Booking.java b/server/src/main/java/ru/practicum/shareit/booking/model/Booking.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/model/Booking.java rename to server/src/main/java/ru/practicum/shareit/booking/model/Booking.java diff --git a/src/main/java/ru/practicum/shareit/booking/model/BookingShort.java b/server/src/main/java/ru/practicum/shareit/booking/model/BookingShort.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/model/BookingShort.java rename to server/src/main/java/ru/practicum/shareit/booking/model/BookingShort.java diff --git a/src/main/java/ru/practicum/shareit/booking/repository/BookingRepository.java b/server/src/main/java/ru/practicum/shareit/booking/repository/BookingRepository.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/repository/BookingRepository.java rename to server/src/main/java/ru/practicum/shareit/booking/repository/BookingRepository.java diff --git a/src/main/java/ru/practicum/shareit/booking/service/BookingService.java b/server/src/main/java/ru/practicum/shareit/booking/service/BookingService.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/service/BookingService.java rename to server/src/main/java/ru/practicum/shareit/booking/service/BookingService.java diff --git a/src/main/java/ru/practicum/shareit/booking/service/BookingServiceImpl.java b/server/src/main/java/ru/practicum/shareit/booking/service/impl/BookingServiceImpl.java similarity index 88% rename from src/main/java/ru/practicum/shareit/booking/service/BookingServiceImpl.java rename to server/src/main/java/ru/practicum/shareit/booking/service/impl/BookingServiceImpl.java index c11b9cb..8376ac4 100644 --- a/src/main/java/ru/practicum/shareit/booking/service/BookingServiceImpl.java +++ b/server/src/main/java/ru/practicum/shareit/booking/service/impl/BookingServiceImpl.java @@ -1,16 +1,12 @@ -package ru.practicum.shareit.booking.service; +package ru.practicum.shareit.booking.service.impl; -import lombok.SneakyThrows; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.core.MethodParameter; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.stereotype.Service; -import org.springframework.validation.BeanPropertyBindingResult; -import org.springframework.web.bind.MethodArgumentNotValidException; import ru.practicum.shareit.booking.BookingState; import ru.practicum.shareit.booking.BookingStatus; import ru.practicum.shareit.booking.dto.BookingDto; @@ -18,6 +14,7 @@ import ru.practicum.shareit.booking.dto.BookingShortDto; import ru.practicum.shareit.booking.model.Booking; import ru.practicum.shareit.booking.repository.BookingRepository; +import ru.practicum.shareit.booking.service.BookingService; import ru.practicum.shareit.error.*; import ru.practicum.shareit.item.model.Item; import ru.practicum.shareit.item.repository.ItemRepository; @@ -45,15 +42,8 @@ public BookingServiceImpl(BookingRepository bookingRepository, ItemRepository it this.userRepository = userRepository; } - @SneakyThrows @Override public BookingDto createBooking(BookingShortDto bookingShortDto, Long userId) { - if (bookingShortDto.getStart().equals(bookingShortDto.getEnd()) - || bookingShortDto.getStart().isAfter(bookingShortDto.getEnd())) { - throw new MethodArgumentNotValidException(new MethodParameter( - this.getClass().getDeclaredMethod("createBooking", BookingShortDto.class, Long.class), 0), new BeanPropertyBindingResult(bookingShortDto, "bookingShortDto")); - } - Long itemId = bookingShortDto.getItemId(); Optional optionalItem = itemRepository.findById(itemId); Optional optionalUser = userRepository.findById(userId); @@ -69,7 +59,7 @@ public BookingDto createBooking(BookingShortDto bookingShortDto, Long userId) { Item item = optionalItem.get(); if (Boolean.FALSE.equals(item.getAvailable())) { - throw new ItemNotAvailableException("Вещь " + itemId + " недоступна"); + throw new ItemUnavailableException("Вещь " + itemId + " недоступна"); } if (userId.equals(item.getOwner().getId())) { @@ -110,7 +100,7 @@ public BookingDto approveBooking(Long bookingId, Boolean approved, Long userId) Long ownerId = booking.getItem().getOwner().getId(); if (!userId.equals(ownerId)) { - throw new AccessDeniedException("Пользователь " + userId + " не является владельцем вещи " + booking.getItem().getId()); + throw new UserAccessDeniedException("Пользователь " + userId + " не является владельцем вещи " + booking.getItem().getId()); } BookingStatus status = Boolean.TRUE.equals(approved) ? BookingStatus.APPROVED : BookingStatus.REJECTED; @@ -137,7 +127,7 @@ public BookingDto getBooking(Long bookingId, Long userId) { Long ownerId = booking.getItem().getOwner().getId(); if (!bookerId.equals(userId) && !ownerId.equals(userId)) { - throw new AccessDeniedException("Пользователь " + userId + " не является ни арендатором ни владельцем"); + throw new UserAccessDeniedException("Пользователь " + userId + " не является ни арендатором ни владельцем"); } return BookingMapper.toBookingDto(booking); diff --git a/src/main/java/ru/practicum/shareit/error/BookingNotFoundException.java b/server/src/main/java/ru/practicum/shareit/error/BookingNotFoundException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/error/BookingNotFoundException.java rename to server/src/main/java/ru/practicum/shareit/error/BookingNotFoundException.java diff --git a/src/main/java/ru/practicum/shareit/error/BookingStatusChangeDeniedException.java b/server/src/main/java/ru/practicum/shareit/error/BookingStatusChangeDeniedException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/error/BookingStatusChangeDeniedException.java rename to server/src/main/java/ru/practicum/shareit/error/BookingStatusChangeDeniedException.java diff --git a/src/main/java/ru/practicum/shareit/error/ErrorHandler.java b/server/src/main/java/ru/practicum/shareit/error/ErrorHandler.java similarity index 94% rename from src/main/java/ru/practicum/shareit/error/ErrorHandler.java rename to server/src/main/java/ru/practicum/shareit/error/ErrorHandler.java index e0453a3..0bc32e1 100644 --- a/src/main/java/ru/practicum/shareit/error/ErrorHandler.java +++ b/server/src/main/java/ru/practicum/shareit/error/ErrorHandler.java @@ -22,7 +22,7 @@ public class ErrorHandler { @ExceptionHandler({ ItemNotFoundException.class, UserNotFoundException.class, - AccessDeniedException.class, + UserAccessDeniedException.class, BookingNotFoundException.class, ItemRequestNotFoundException.class }) @@ -42,7 +42,7 @@ public ErrorResponse validationError(final MethodArgumentNotValidException e) { .toString()); } - @ExceptionHandler({ItemNotAvailableException.class, BookingStatusChangeDeniedException.class}) + @ExceptionHandler({ItemUnavailableException.class, BookingStatusChangeDeniedException.class}) @ResponseStatus(HttpStatus.BAD_REQUEST) public ErrorResponse itemUnavailableError(final RuntimeException e) { logger.info("item unavailable error: {}", e.getMessage(), e); diff --git a/server/src/main/java/ru/practicum/shareit/error/ErrorResponse.java b/server/src/main/java/ru/practicum/shareit/error/ErrorResponse.java new file mode 100644 index 0000000..a7936d3 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/error/ErrorResponse.java @@ -0,0 +1,13 @@ +package ru.practicum.shareit.error; + +public class ErrorResponse { + private final String error; + + public ErrorResponse(String error) { + this.error = error; + } + + public String getError() { + return error; + } +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/error/ItemNotFoundException.java b/server/src/main/java/ru/practicum/shareit/error/ItemNotFoundException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/error/ItemNotFoundException.java rename to server/src/main/java/ru/practicum/shareit/error/ItemNotFoundException.java diff --git a/src/main/java/ru/practicum/shareit/error/ItemRequestNotFoundException.java b/server/src/main/java/ru/practicum/shareit/error/ItemRequestNotFoundException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/error/ItemRequestNotFoundException.java rename to server/src/main/java/ru/practicum/shareit/error/ItemRequestNotFoundException.java diff --git a/server/src/main/java/ru/practicum/shareit/error/ItemUnavailableException.java b/server/src/main/java/ru/practicum/shareit/error/ItemUnavailableException.java new file mode 100644 index 0000000..bd8b8b1 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/error/ItemUnavailableException.java @@ -0,0 +1,7 @@ +package ru.practicum.shareit.error; + +public class ItemUnavailableException extends RuntimeException { + public ItemUnavailableException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/server/src/main/java/ru/practicum/shareit/error/UserAccessDeniedException.java b/server/src/main/java/ru/practicum/shareit/error/UserAccessDeniedException.java new file mode 100644 index 0000000..86e77ec --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/error/UserAccessDeniedException.java @@ -0,0 +1,7 @@ +package ru.practicum.shareit.error; + +public class UserAccessDeniedException extends RuntimeException { + public UserAccessDeniedException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/error/UserNotFoundException.java b/server/src/main/java/ru/practicum/shareit/error/UserNotFoundException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/error/UserNotFoundException.java rename to server/src/main/java/ru/practicum/shareit/error/UserNotFoundException.java diff --git a/src/main/java/ru/practicum/shareit/item/controller/ItemController.java b/server/src/main/java/ru/practicum/shareit/item/controller/ItemController.java similarity index 59% rename from src/main/java/ru/practicum/shareit/item/controller/ItemController.java rename to server/src/main/java/ru/practicum/shareit/item/controller/ItemController.java index 4f56739..b1b4f9b 100644 --- a/src/main/java/ru/practicum/shareit/item/controller/ItemController.java +++ b/server/src/main/java/ru/practicum/shareit/item/controller/ItemController.java @@ -6,10 +6,7 @@ import ru.practicum.shareit.item.dto.CommentDto; import ru.practicum.shareit.item.dto.ItemDto; import ru.practicum.shareit.item.service.ItemService; -import ru.practicum.shareit.validation.ValidationGroups; -import javax.validation.constraints.Positive; -import javax.validation.constraints.PositiveOrZero; import java.util.Collection; import java.util.Collections; @@ -24,36 +21,36 @@ public ItemController(ItemService itemService) { } @PostMapping - public ItemDto create(@Validated(ValidationGroups.Create.class) @RequestBody ItemDto itemDto, + public ItemDto createItem(@RequestBody ItemDto itemDto, @RequestHeader("X-Sharer-User-Id") Long userId) { return itemService.createItem(itemDto, userId); } @PatchMapping("/{itemId}") - public ItemDto change(@Validated(ValidationGroups.Update.class) @RequestBody ItemDto itemDto, + public ItemDto changeItem(@RequestBody ItemDto itemDto, @PathVariable Long itemId, @RequestHeader("X-Sharer-User-Id") Long userId) { return itemService.changeItem(itemId, itemDto, userId); } @GetMapping("/{itemId}") - public ItemDto get(@PathVariable Long itemId, + public ItemDto getItem(@PathVariable Long itemId, @RequestHeader("X-Sharer-User-Id") Long userId) { return itemService.getItem(itemId, userId); } @GetMapping - public Collection getAll(@RequestHeader("X-Sharer-User-Id") Long userId, - @PositiveOrZero @RequestParam(name = "from", required = false, defaultValue = "0") Long from, - @Positive @RequestParam(name = "size", required = false, defaultValue = "20") Long size) { + public Collection getAllItems(@RequestHeader("X-Sharer-User-Id") Long userId, + @RequestParam(name = "from", required = false, defaultValue = "0") Long from, + @RequestParam(name = "size", required = false, defaultValue = "20") Long size) { return itemService.getAllItems(userId, from, size); } @Validated @GetMapping("/search") - public Collection search(@RequestParam(name = "text") String text, - @PositiveOrZero @RequestParam(name = "from", required = false, defaultValue = "0") Long from, - @Positive @RequestParam(name = "size", required = false, defaultValue = "20") Long size) { + public Collection searchItems(@RequestParam(name = "text") String text, + @RequestParam(name = "from", required = false, defaultValue = "0") Long from, + @RequestParam(name = "size", required = false, defaultValue = "20") Long size) { if (text.isBlank()) return Collections.emptyList(); return itemService.searchItems(text, from, size); } @@ -61,7 +58,7 @@ public Collection search(@RequestParam(name = "text") String text, @Validated @PostMapping("/{itemId}/comment") public CommentDto addComment(@PathVariable Long itemId, - @Validated @RequestBody CommentDto commentDto, + @RequestBody CommentDto commentDto, @RequestHeader("X-Sharer-User-Id") Long userId) { return itemService.addComment(itemId, commentDto, userId); } diff --git a/server/src/main/java/ru/practicum/shareit/item/dto/CommentDto.java b/server/src/main/java/ru/practicum/shareit/item/dto/CommentDto.java new file mode 100644 index 0000000..124be73 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/item/dto/CommentDto.java @@ -0,0 +1,25 @@ +package ru.practicum.shareit.item.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.time.LocalDateTime; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +public class CommentDto { + + private Long id; + + private String text; + + private String authorName; + + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS") + private LocalDateTime created; +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/item/dto/CommentMapper.java b/server/src/main/java/ru/practicum/shareit/item/dto/CommentMapper.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/dto/CommentMapper.java rename to server/src/main/java/ru/practicum/shareit/item/dto/CommentMapper.java diff --git a/server/src/main/java/ru/practicum/shareit/item/dto/ItemDto.java b/server/src/main/java/ru/practicum/shareit/item/dto/ItemDto.java new file mode 100644 index 0000000..1175438 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/item/dto/ItemDto.java @@ -0,0 +1,28 @@ +package ru.practicum.shareit.item.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import ru.practicum.shareit.booking.dto.BookingShortDto; + +import java.util.Collection; + +@Data +@AllArgsConstructor +@Builder +public class ItemDto { + private final Long id; + + private final String name; + + private final String description; + + private final Boolean available; + + private final BookingShortDto lastBooking; + private final BookingShortDto nextBooking; + + private Long requestId; + + private final Collection comments; +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/item/dto/ItemMapper.java b/server/src/main/java/ru/practicum/shareit/item/dto/ItemMapper.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/dto/ItemMapper.java rename to server/src/main/java/ru/practicum/shareit/item/dto/ItemMapper.java diff --git a/src/main/java/ru/practicum/shareit/item/model/Comment.java b/server/src/main/java/ru/practicum/shareit/item/model/Comment.java similarity index 82% rename from src/main/java/ru/practicum/shareit/item/model/Comment.java rename to server/src/main/java/ru/practicum/shareit/item/model/Comment.java index 4f9bb04..1ae4be7 100644 --- a/src/main/java/ru/practicum/shareit/item/model/Comment.java +++ b/server/src/main/java/ru/practicum/shareit/item/model/Comment.java @@ -1,18 +1,18 @@ package ru.practicum.shareit.item.model; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; import org.hibernate.annotations.CreationTimestamp; import ru.practicum.shareit.user.model.User; import javax.persistence.*; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; import java.time.LocalDateTime; @Entity @Table(name = "COMMENTS") -@Getter -@Setter +@Data @AllArgsConstructor @NoArgsConstructor @Builder @@ -22,8 +22,6 @@ public class Comment { private Long id; @Column(name = "TEXT") - @NotNull - @NotBlank private String text; @ManyToOne(fetch = FetchType.LAZY) diff --git a/src/main/java/ru/practicum/shareit/item/model/Item.java b/server/src/main/java/ru/practicum/shareit/item/model/Item.java similarity index 88% rename from src/main/java/ru/practicum/shareit/item/model/Item.java rename to server/src/main/java/ru/practicum/shareit/item/model/Item.java index a0e8818..48eeb01 100644 --- a/src/main/java/ru/practicum/shareit/item/model/Item.java +++ b/server/src/main/java/ru/practicum/shareit/item/model/Item.java @@ -1,6 +1,9 @@ package ru.practicum.shareit.item.model; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; import ru.practicum.shareit.booking.model.BookingShort; import ru.practicum.shareit.request.model.ItemRequest; import ru.practicum.shareit.user.model.User; @@ -9,8 +12,7 @@ @Entity @Table(name = "ITEMS") -@Getter -@Setter +@Data @AllArgsConstructor @NoArgsConstructor @Builder diff --git a/src/main/java/ru/practicum/shareit/item/repository/CommentRepository.java b/server/src/main/java/ru/practicum/shareit/item/repository/CommentRepository.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/repository/CommentRepository.java rename to server/src/main/java/ru/practicum/shareit/item/repository/CommentRepository.java diff --git a/src/main/java/ru/practicum/shareit/item/repository/ItemRepository.java b/server/src/main/java/ru/practicum/shareit/item/repository/ItemRepository.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/repository/ItemRepository.java rename to server/src/main/java/ru/practicum/shareit/item/repository/ItemRepository.java diff --git a/src/main/java/ru/practicum/shareit/item/service/ItemService.java b/server/src/main/java/ru/practicum/shareit/item/service/ItemService.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/service/ItemService.java rename to server/src/main/java/ru/practicum/shareit/item/service/ItemService.java diff --git a/src/main/java/ru/practicum/shareit/item/service/ItemServiceImpl.java b/server/src/main/java/ru/practicum/shareit/item/service/impl/ItemServiceImpl.java similarity index 89% rename from src/main/java/ru/practicum/shareit/item/service/ItemServiceImpl.java rename to server/src/main/java/ru/practicum/shareit/item/service/impl/ItemServiceImpl.java index 75f10e0..24bc2a3 100644 --- a/src/main/java/ru/practicum/shareit/item/service/ItemServiceImpl.java +++ b/server/src/main/java/ru/practicum/shareit/item/service/impl/ItemServiceImpl.java @@ -1,4 +1,4 @@ -package ru.practicum.shareit.item.service; +package ru.practicum.shareit.item.service.impl; import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; @@ -12,7 +12,10 @@ import ru.practicum.shareit.booking.BookingStatus; import ru.practicum.shareit.booking.model.BookingShort; import ru.practicum.shareit.booking.repository.BookingRepository; -import ru.practicum.shareit.error.*; +import ru.practicum.shareit.error.ItemNotFoundException; +import ru.practicum.shareit.error.ItemUnavailableException; +import ru.practicum.shareit.error.UserAccessDeniedException; +import ru.practicum.shareit.error.UserNotFoundException; import ru.practicum.shareit.item.dto.CommentDto; import ru.practicum.shareit.item.dto.CommentMapper; import ru.practicum.shareit.item.dto.ItemDto; @@ -21,6 +24,7 @@ import ru.practicum.shareit.item.model.Item; import ru.practicum.shareit.item.repository.CommentRepository; import ru.practicum.shareit.item.repository.ItemRepository; +import ru.practicum.shareit.item.service.ItemService; import ru.practicum.shareit.request.model.ItemRequest; import ru.practicum.shareit.request.repository.ItemRequestRepository; import ru.practicum.shareit.user.model.User; @@ -72,8 +76,8 @@ public ItemDto createItem(ItemDto itemDto, Long userId) { Optional optionalItemRequest = itemRequestRepository.findById(requestId); optionalItemRequest.ifPresent(item::setRequest); } - Item createdItem = item; - itemRepository.save(item); + + Item createdItem = itemRepository.save(item); logger.info("Создана вещь с id={}", createdItem.getId()); return ItemMapper.toItemDto(createdItem); @@ -90,7 +94,7 @@ public ItemDto changeItem(Long itemId, ItemDto itemDto, Long userId) { Long ownerId = item.get().getOwner().getId(); if (!Objects.equals(ownerId, userId)) { - throw new AccessDeniedException("У пользователя " + userId + " нет прав на изменение вещи " + itemId); + throw new UserAccessDeniedException("У пользователя " + userId + " нет прав на изменение вещи " + itemId); } String itemName = itemDto.getName(); @@ -167,7 +171,7 @@ public Collection getAllItems(Long userId, Long from, Long size) { logger.info("Запрошено {} вещей", items.size()); - return itemDtos; + return itemDtos.stream().sorted(Comparator.comparing(ItemDto::getId)).collect(Collectors.toList()); } @Override @@ -206,7 +210,7 @@ public CommentDto addComment(Long itemId, CommentDto commentDto, Long userId) { Item item = optionalItem.get(); if (bookingRepository.findAllByBookerIdAndItemIdAndEndBefore(userId, itemId, LocalDateTime.now()).isEmpty()) { - throw new ItemNotAvailableException("Пользователь " + userId + " не бронировал вещь " + itemId); + throw new ItemUnavailableException("Пользователь " + userId + " не бронировал вещь " + itemId); } Comment comment = CommentMapper.toComment(commentDto); @@ -221,7 +225,12 @@ private void addItemBookings(Item item, Long userId) { if (Objects.equals(item.getOwner().getId(), userId)) { LocalDateTime now = LocalDateTime.now(); - BookingShort lastBooking = bookingRepository.findFirstByItemIdAndStartBefore(item.getId(), now, Sort.by(Sort.Direction.DESC, "start")); + BookingShort lastBooking = bookingRepository.findFirstByItemIdAndStartBefore( + item.getId(), + now, + Sort.by(Sort.Direction.DESC, "start") + ); + BookingShort nextBooking = bookingRepository.findFirstByItemIdAndStartAfterAndStatusNot( item.getId(), now, diff --git a/src/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java b/server/src/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java similarity index 72% rename from src/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java rename to server/src/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java index 4e945b8..b3513db 100644 --- a/src/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java +++ b/server/src/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java @@ -1,13 +1,10 @@ package ru.practicum.shareit.request.controller; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import ru.practicum.shareit.request.dto.ItemRequestDto; import ru.practicum.shareit.request.service.ItemRequestService; -import javax.validation.constraints.Positive; -import javax.validation.constraints.PositiveOrZero; import java.util.Collection; @RestController @@ -21,7 +18,7 @@ public ItemRequestController(ItemRequestService itemRequestService) { } @PostMapping - public ItemRequestDto addItemRequest(@Validated @RequestBody ItemRequestDto itemRequestDto, + public ItemRequestDto addItemRequest(@RequestBody ItemRequestDto itemRequestDto, @RequestHeader("X-Sharer-User-Id") Long userId) { return itemRequestService.addItemRequest(itemRequestDto, userId); } @@ -39,8 +36,8 @@ public ItemRequestDto getItemRequest(@RequestHeader("X-Sharer-User-Id") Long use @GetMapping("/all") public Collection getOtherItemRequests(@RequestHeader("X-Sharer-User-Id") Long userId, - @PositiveOrZero @RequestParam(name = "from", required = false, defaultValue = "0") Long from, - @Positive @RequestParam(name = "size", required = false, defaultValue = "20") Long size) { + @RequestParam(name = "from", required = false, defaultValue = "0") Long from, + @RequestParam(name = "size", required = false, defaultValue = "20") Long size) { return itemRequestService.getOtherItemRequests(userId, from, size); } } \ No newline at end of file diff --git a/server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestDto.java b/server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestDto.java new file mode 100644 index 0000000..838cfc8 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestDto.java @@ -0,0 +1,23 @@ +package ru.practicum.shareit.request.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import ru.practicum.shareit.item.dto.ItemDto; + +import java.time.LocalDateTime; +import java.util.Collection; + +@Data +@AllArgsConstructor +@Builder +public class ItemRequestDto { + private final Long id; + private final String description; + + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS") + private final LocalDateTime created; + + private Collection items; +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/request/dto/ItemRequestMapper.java b/server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestMapper.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/dto/ItemRequestMapper.java rename to server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestMapper.java diff --git a/src/main/java/ru/practicum/shareit/request/model/ItemRequest.java b/server/src/main/java/ru/practicum/shareit/request/model/ItemRequest.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/model/ItemRequest.java rename to server/src/main/java/ru/practicum/shareit/request/model/ItemRequest.java diff --git a/src/main/java/ru/practicum/shareit/request/repository/ItemRequestRepository.java b/server/src/main/java/ru/practicum/shareit/request/repository/ItemRequestRepository.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/repository/ItemRequestRepository.java rename to server/src/main/java/ru/practicum/shareit/request/repository/ItemRequestRepository.java diff --git a/src/main/java/ru/practicum/shareit/request/service/ItemRequestService.java b/server/src/main/java/ru/practicum/shareit/request/service/ItemRequestService.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/service/ItemRequestService.java rename to server/src/main/java/ru/practicum/shareit/request/service/ItemRequestService.java diff --git a/src/main/java/ru/practicum/shareit/request/service/impl/ItemRequestServiceImpl.java b/server/src/main/java/ru/practicum/shareit/request/service/impl/ItemRequestServiceImpl.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/service/impl/ItemRequestServiceImpl.java rename to server/src/main/java/ru/practicum/shareit/request/service/impl/ItemRequestServiceImpl.java diff --git a/src/main/java/ru/practicum/shareit/user/controller/UserController.java b/server/src/main/java/ru/practicum/shareit/user/controller/UserController.java similarity index 61% rename from src/main/java/ru/practicum/shareit/user/controller/UserController.java rename to server/src/main/java/ru/practicum/shareit/user/controller/UserController.java index 7fa60f1..3445708 100644 --- a/src/main/java/ru/practicum/shareit/user/controller/UserController.java +++ b/server/src/main/java/ru/practicum/shareit/user/controller/UserController.java @@ -1,10 +1,8 @@ package ru.practicum.shareit.user.controller; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import ru.practicum.shareit.user.dto.UserDto; import ru.practicum.shareit.user.service.UserService; -import ru.practicum.shareit.validation.ValidationGroups; import java.util.Collection; @@ -18,28 +16,28 @@ public UserController(UserService userService) { } @PostMapping - public UserDto create(@Validated(ValidationGroups.Create.class) @RequestBody UserDto userDto) { + public UserDto createUser(@RequestBody UserDto userDto) { return userService.createUser(userDto); } @GetMapping("/{userId}") - public UserDto get(@PathVariable Long userId) { + public UserDto getUser(@PathVariable Long userId) { return userService.getUser(userId); } @GetMapping - public Collection getAll() { + public Collection getAllUsers() { return userService.getAllUsers(); } @PatchMapping("/{userId}") - public UserDto update(@PathVariable Long userId, - @Validated(ValidationGroups.Update.class) @RequestBody UserDto userDto) { + public UserDto updateUser(@PathVariable Long userId, + @RequestBody UserDto userDto) { return userService.updateUser(userId, userDto); } @DeleteMapping("/{userId}") - public UserDto delete(@PathVariable Long userId) { + public UserDto deleteUser(@PathVariable Long userId) { return userService.deleteUser(userId); } } \ No newline at end of file diff --git a/server/src/main/java/ru/practicum/shareit/user/dto/UserDto.java b/server/src/main/java/ru/practicum/shareit/user/dto/UserDto.java new file mode 100644 index 0000000..d6c85ce --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/user/dto/UserDto.java @@ -0,0 +1,16 @@ +package ru.practicum.shareit.user.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; + +@Data +@AllArgsConstructor +@Builder +public class UserDto { + private final Long id; + + private final String name; + + private final String email; +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/user/dto/UserMapper.java b/server/src/main/java/ru/practicum/shareit/user/dto/UserMapper.java similarity index 100% rename from src/main/java/ru/practicum/shareit/user/dto/UserMapper.java rename to server/src/main/java/ru/practicum/shareit/user/dto/UserMapper.java diff --git a/src/main/java/ru/practicum/shareit/user/model/User.java b/server/src/main/java/ru/practicum/shareit/user/model/User.java similarity index 71% rename from src/main/java/ru/practicum/shareit/user/model/User.java rename to server/src/main/java/ru/practicum/shareit/user/model/User.java index 1277327..0df19c1 100644 --- a/src/main/java/ru/practicum/shareit/user/model/User.java +++ b/server/src/main/java/ru/practicum/shareit/user/model/User.java @@ -1,16 +1,16 @@ package ru.practicum.shareit.user.model; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; import javax.persistence.*; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotBlank; @Entity @Table(name = "USERS") -@Getter -@Setter +@Data @AllArgsConstructor @NoArgsConstructor @Builder @@ -20,12 +20,9 @@ public class User { @Column(name = "ID") private Long id; - @NotBlank @Column(name = "NAME") private String name; - @NotBlank - @Email @Column(name = "EMAIL", unique = true) private String email; } \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/user/repository/UserRepository.java b/server/src/main/java/ru/practicum/shareit/user/repository/UserRepository.java similarity index 100% rename from src/main/java/ru/practicum/shareit/user/repository/UserRepository.java rename to server/src/main/java/ru/practicum/shareit/user/repository/UserRepository.java diff --git a/src/main/java/ru/practicum/shareit/user/service/UserService.java b/server/src/main/java/ru/practicum/shareit/user/service/UserService.java similarity index 100% rename from src/main/java/ru/practicum/shareit/user/service/UserService.java rename to server/src/main/java/ru/practicum/shareit/user/service/UserService.java diff --git a/src/main/java/ru/practicum/shareit/user/service/impl/UserServiceImpl.java b/server/src/main/java/ru/practicum/shareit/user/service/impl/UserServiceImpl.java similarity index 100% rename from src/main/java/ru/practicum/shareit/user/service/impl/UserServiceImpl.java rename to server/src/main/java/ru/practicum/shareit/user/service/impl/UserServiceImpl.java diff --git a/src/main/java/ru/practicum/shareit/validation/PagingParametersChecker.java b/server/src/main/java/ru/practicum/shareit/validation/PagingParametersChecker.java similarity index 100% rename from src/main/java/ru/practicum/shareit/validation/PagingParametersChecker.java rename to server/src/main/java/ru/practicum/shareit/validation/PagingParametersChecker.java diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties new file mode 100644 index 0000000..fc3a9cf --- /dev/null +++ b/server/src/main/resources/application.properties @@ -0,0 +1,19 @@ +server.port=9090 + +spring.jpa.hibernate.ddl-auto=none +spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL10Dialect +spring.jpa.properties.hibernate.format_sql=true +spring.sql.init.mode=always + +spring.datasource.driverClassName=org.postgresql.Driver +spring.datasource.url=${SPRING_DATASOURCE_URL} +spring.datasource.username=${SPRING_DATASOURCE_USERNAME} +spring.datasource.password=${SPRING_DATASOURCE_PASSWORD} + +#--- +spring.config.activate.on-profile=ci,test +spring.datasource.driverClassName=org.h2.Driver +spring.datasource.url=jdbc:h2:mem:shareit +spring.datasource.username=test +spring.datasource.password=test +#--- \ No newline at end of file diff --git a/src/main/resources/schema.sql b/server/src/main/resources/schema.sql similarity index 100% rename from src/main/resources/schema.sql rename to server/src/main/resources/schema.sql diff --git a/src/main/java/ru/practicum/shareit/error/AccessDeniedException.java b/src/main/java/ru/practicum/shareit/error/AccessDeniedException.java deleted file mode 100644 index eeca398..0000000 --- a/src/main/java/ru/practicum/shareit/error/AccessDeniedException.java +++ /dev/null @@ -1,7 +0,0 @@ -package ru.practicum.shareit.error; - -public class AccessDeniedException extends RuntimeException { - public AccessDeniedException(String message) { - super(message); - } -} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/error/ItemNotAvailableException.java b/src/main/java/ru/practicum/shareit/error/ItemNotAvailableException.java deleted file mode 100644 index ca91ab6..0000000 --- a/src/main/java/ru/practicum/shareit/error/ItemNotAvailableException.java +++ /dev/null @@ -1,7 +0,0 @@ -package ru.practicum.shareit.error; - -public class ItemNotAvailableException extends RuntimeException { - public ItemNotAvailableException(String message) { - super(message); - } -} \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 184348e..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,21 +0,0 @@ -spring.sql.init.mode=always -spring.jpa.hibernate.ddl-auto=none -spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL10Dialect -spring.jpa.properties.hibernate.format_sql=true - -logging.level.org.springframework.orm.jpa=INFO -logging.level.org.springframework.transaction=INFO -logging.level.org.springframework.transaction.interceptor=TRACE -logging.level.org.springframework.orm.jpa.JpaTransactionManager=DEBUG - -#spring.config.activate.on-profile=runtime -#spring.datasource.driverClassName=org.postgresql.Driver -#spring.datasource.url=jdbc:postgresql://localhost:5432/postgres -#spring.datasource.username=postgres -#spring.datasource.password=postgres - -spring.config.activate.on-profile=ci,test -spring.datasource.driverClassName=org.h2.Driver -spring.datasource.url=jdbc:h2:mem:shareit -spring.datasource.username=test -spring.datasource.password=test \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/ShareItAppTest.java b/src/test/java/ru/practicum/shareit/ShareItAppTest.java deleted file mode 100644 index 30d6e18..0000000 --- a/src/test/java/ru/practicum/shareit/ShareItAppTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package ru.practicum.shareit; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -public class ShareItAppTest { - - @Test - public void contextLoads() { - } - -} diff --git a/src/test/java/ru/practicum/shareit/ShareItTests.java b/src/test/java/ru/practicum/shareit/ShareItTests.java deleted file mode 100644 index 4d79052..0000000 --- a/src/test/java/ru/practicum/shareit/ShareItTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package ru.practicum.shareit; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class ShareItTests { - - @Test - void contextLoads() { - } - -} diff --git a/src/test/java/ru/practicum/shareit/booking/controller/BookingControllerTest.java b/src/test/java/ru/practicum/shareit/booking/controller/BookingControllerTest.java deleted file mode 100644 index b5a507a..0000000 --- a/src/test/java/ru/practicum/shareit/booking/controller/BookingControllerTest.java +++ /dev/null @@ -1,184 +0,0 @@ -package ru.practicum.shareit.booking.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; -import ru.practicum.shareit.booking.dto.BookingDto; -import ru.practicum.shareit.booking.dto.BookingShortDto; -import ru.practicum.shareit.booking.service.BookingService; -import ru.practicum.shareit.item.dto.ItemDto; -import ru.practicum.shareit.user.dto.UserDto; - -import java.nio.charset.StandardCharsets; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -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; - -@WebMvcTest(controllers = BookingController.class) -class BookingControllerTest { - - @Autowired - ObjectMapper mapper; - - @MockBean - BookingService bookingService; - - @Autowired - private MockMvc mvc; - - private final List users = List.of( - UserDto.builder().id(1L).name("user1").email("user1@mail.ru").build(), - UserDto.builder().id(2L).name("user2").email("user2@mail.ru").build(), - UserDto.builder().id(3L).name("user3").email("user3@mail.ru").build() - ); - - private final List items = List.of( - ItemDto.builder().id(1L).name("item1").description("this is item1").available(true).build(), - ItemDto.builder().id(2L).description("this is item2").available(true).build(), - ItemDto.builder().id(3L).name("item3").available(true).build(), - ItemDto.builder().id(4L).name("item4").description("this is item4").build()); - - private static final List dates = new ArrayList<>(); - - @BeforeAll - public static void installDates() { - LocalDateTime now = LocalDateTime.now(); - LocalDateTime nowPlusOneDay = now.plusDays(1); - LocalDateTime nowPlusTwoDays = now.plusDays(2); - LocalDateTime nowPlusThreeDays = now.plusDays(3); - - dates.add(now); - dates.add(nowPlusOneDay); - dates.add(nowPlusTwoDays); - dates.add(nowPlusThreeDays); - } - - private final List bookings = List.of( - BookingDto.builder() - .id(1L) - .start(dates.get(0)) - .end(dates.get(1)) - .item(new BookingDto.Item(items.get(0).getId(), items.get(0).getName())) - .booker(new BookingDto.User(users.get(0).getId(), users.get(0).getName())) - .build(), - BookingDto.builder() - .id(2L) - .start(dates.get(1)) - .end(dates.get(2)) - .item(new BookingDto.Item(items.get(1).getId(), items.get(1).getName())) - .booker(new BookingDto.User(users.get(1).getId(), users.get(1).getName())) - .build(), - BookingDto.builder() - .id(3L) - .start(dates.get(2)) - .end(dates.get(3)) - .item(new BookingDto.Item(items.get(2).getId(), items.get(2).getName())) - .booker(new BookingDto.User(users.get(2).getId(), users.get(2).getName())) - .build()); - - private final List shortBookings = List.of( - BookingShortDto.builder() - .id(1L) - .start(dates.get(1)) - .end(dates.get(2)) - .itemId(items.get(0).getId()) - .bookerId(users.get(0).getId()) - .build(), - BookingShortDto.builder() - .id(2L) - .end(dates.get(2)) - .itemId(items.get(1).getId()) - .bookerId(users.get(1).getId()) - .build(), - BookingShortDto.builder() - .id(3L) - .start(dates.get(2)) - .itemId(items.get(2).getId()) - .bookerId(users.get(2).getId()) - .build()); - - @Test - void createBooking() throws Exception { - when(bookingService.createBooking(any(), anyLong())) - .thenReturn(bookings.get(0)); - - mvc.perform(post("/bookings") - .header("X-Sharer-User-Id", 1L) - .content(mapper.writeValueAsString(shortBookings.get(0))) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id", is(bookings.get(0).getId()), Long.class)) - .andExpect(jsonPath("$.status", is(bookings.get(0).getStatus()))); - - mvc.perform(post("/bookings") - .header("X-Sharer-User-Id", 1L) - .content(mapper.writeValueAsString(shortBookings.get(1))) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - - mvc.perform(post("/bookings") - .header("X-Sharer-User-Id", 1L) - .content(mapper.writeValueAsString(shortBookings.get(2))) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - - @Test - void getBooking() throws Exception { - when(bookingService.getBooking(anyLong(), anyLong())) - .thenReturn(bookings.get(0)); - - mvc.perform(get("/bookings/1") - .header("X-Sharer-User-Id", 1L)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id", is(bookings.get(0).getId()), Long.class)) - .andExpect(jsonPath("$.status", is(bookings.get(0).getStatus()))); - } - - @Test - void getAllBookings() throws Exception { - when(bookingService.getAllBookings(anyLong(), any(), anyLong(), anyLong())) - .thenReturn(bookings); - - mvc.perform(get("/bookings") - .header("X-Sharer-User-Id", 1L)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$", hasSize(3))) - .andExpect(jsonPath("$[0].id", is(bookings.get(0).getId()), Long.class)) - .andExpect(jsonPath("$[0].status", is(bookings.get(0).getStatus()))); - } - - @Test - void getOwnerBookings() throws Exception { - when(bookingService.getOwnerBookings(anyLong(), any(), anyLong(), anyLong())) - .thenReturn(bookings); - - mvc.perform(get("/bookings/owner") - .header("X-Sharer-User-Id", 1L)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$", hasSize(3))) - .andExpect(jsonPath("$[0].id", is(bookings.get(0).getId()), Long.class)) - .andExpect(jsonPath("$[0].status", is(bookings.get(0).getStatus()))); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/booking/dto/BookingDtoTest.java b/src/test/java/ru/practicum/shareit/booking/dto/BookingDtoTest.java deleted file mode 100644 index 99456bb..0000000 --- a/src/test/java/ru/practicum/shareit/booking/dto/BookingDtoTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package ru.practicum.shareit.booking.dto; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.json.JsonTest; -import org.springframework.boot.test.json.JacksonTester; -import org.springframework.boot.test.json.JsonContent; -import ru.practicum.shareit.booking.BookingStatus; - -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; - -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - -@JsonTest -class BookingDtoTest { - @Autowired - private JacksonTester json; - - @Test - void testBookingDto() throws Exception { - LocalDateTime now = LocalDateTime.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"); - - BookingDto bookingDto = BookingDto.builder() - .id(1L) - .start(now) - .end(now.plusDays(1)) - .status(BookingStatus.APPROVED) - .item(new BookingDto.Item(1L, "item1")) - .booker(new BookingDto.User(1L, "user1")) - .build(); - - JsonContent result = json.write(bookingDto); - - assertThat(result).extractingJsonPathNumberValue("$.id").isEqualTo(1); - assertThat(result).extractingJsonPathStringValue("$.start").isEqualTo(now.format(formatter)); - assertThat(result).extractingJsonPathStringValue("$.end").isEqualTo(now.plusDays(1).format(formatter)); - assertThat(result).extractingJsonPathStringValue("$.status").isEqualTo(BookingStatus.APPROVED.toString()); - assertThat(result).extractingJsonPathNumberValue("$.item.id").isEqualTo(1); - assertThat(result).extractingJsonPathStringValue("$.item.name").isEqualTo("item1"); - assertThat(result).extractingJsonPathNumberValue("$.booker.id").isEqualTo(1); - assertThat(result).extractingJsonPathStringValue("$.booker.name").isEqualTo("user1"); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/booking/dto/BookingMapperTest.java b/src/test/java/ru/practicum/shareit/booking/dto/BookingMapperTest.java deleted file mode 100644 index 819b570..0000000 --- a/src/test/java/ru/practicum/shareit/booking/dto/BookingMapperTest.java +++ /dev/null @@ -1,42 +0,0 @@ -package ru.practicum.shareit.booking.dto; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import ru.practicum.shareit.booking.model.Booking; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; - -public class BookingMapperTest { - - @Test - public void testPrivateConstructor() throws NoSuchMethodException { - Constructor constructor = BookingMapper.class.getDeclaredConstructor(); - constructor.setAccessible(true); - - try { - constructor.newInstance(); - Assertions.fail("Expected exception not thrown"); - } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { - Assertions.assertTrue(e.getCause() instanceof IllegalStateException); - Assertions.assertEquals("Mapper class", e.getCause().getMessage()); - } - } - - @Test - public void testToBooking() { - BookingShortDto bookingShortDto = BookingShortDto.builder() - .id(1L) - .bookerId(1L) - .build(); - - Booking booking = BookingMapper.toBooking(bookingShortDto); - - Assertions.assertNull(booking.getId()); - Assertions.assertNull(booking.getStart()); - Assertions.assertNull(booking.getEnd()); - Assertions.assertNull(booking.getItem()); - Assertions.assertNull(booking.getBooker()); - Assertions.assertNull(booking.getStatus()); - } -} diff --git a/src/test/java/ru/practicum/shareit/booking/dto/BookingShortDtoTest.java b/src/test/java/ru/practicum/shareit/booking/dto/BookingShortDtoTest.java deleted file mode 100644 index 2e8ddc4..0000000 --- a/src/test/java/ru/practicum/shareit/booking/dto/BookingShortDtoTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package ru.practicum.shareit.booking.dto; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.json.JsonTest; -import org.springframework.boot.test.json.JacksonTester; -import org.springframework.boot.test.json.JsonContent; - -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; - -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - -@JsonTest -class BookingShortDtoTest { - @Autowired - private JacksonTester json; - - @Test - void testBookingShortDto() throws Exception { - LocalDateTime now = LocalDateTime.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss"); - - BookingShortDto bookingShortDto = BookingShortDto.builder() - .id(1L) - .start(now) - .end(now.plusDays(1)) - .itemId(1L) - .bookerId(1L) - .build(); - - JsonContent result = json.write(bookingShortDto); - - assertThat(result).extractingJsonPathNumberValue("$.id").isEqualTo(1); - assertThat(result).extractingJsonPathStringValue("$.start").isEqualTo(now.format(formatter)); - assertThat(result).extractingJsonPathStringValue("$.end").isEqualTo(now.plusDays(1).format(formatter)); - assertThat(result).extractingJsonPathNumberValue("$.itemId").isEqualTo(1); - assertThat(result).extractingJsonPathNumberValue("$.bookerId").isEqualTo(1); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/booking/repository/BookingRepositoryTest.java b/src/test/java/ru/practicum/shareit/booking/repository/BookingRepositoryTest.java deleted file mode 100644 index 81ce47f..0000000 --- a/src/test/java/ru/practicum/shareit/booking/repository/BookingRepositoryTest.java +++ /dev/null @@ -1,331 +0,0 @@ -package ru.practicum.shareit.booking.repository; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; -import org.springframework.transaction.annotation.Transactional; -import ru.practicum.shareit.booking.BookingStatus; -import ru.practicum.shareit.booking.model.Booking; -import ru.practicum.shareit.booking.model.BookingShort; -import ru.practicum.shareit.item.model.Item; -import ru.practicum.shareit.user.model.User; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -@DataJpaTest -@Transactional -@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.ANY) -class BookingRepositoryTest { - @Autowired - private TestEntityManager testEntityManager; - - @Autowired - private BookingRepository bookingRepository; - - @Test - void contextLoads() { - Assertions.assertNotNull(testEntityManager); - } - - private final List users = List.of( - User.builder().name("user1").email("user1@mail.ru").build(), - User.builder().name("user2").email("user2@mail.ru").build(), - User.builder().name("user3").email("user3@mail.ru").build()); - - private final List items = List.of( - Item.builder().name("item1").description("this is item1").available(true).build(), - Item.builder().name("item2").description("this is item2").available(true).build(), - Item.builder().name("item3").description("this is item3").available(true).build()); - - private final List bookings = List.of( - Booking.builder().build(), - Booking.builder().build(), - Booking.builder().build() - ); - - private static final List dates = new ArrayList<>(); - - @BeforeAll - public static void installDates() { - LocalDateTime now = LocalDateTime.now(); - LocalDateTime nowPlusOneDay = now.plusDays(1); - LocalDateTime nowPlusTwoDays = now.plusDays(2); - LocalDateTime nowPlusThreeDays = now.plusDays(3); - - dates.add(now); - dates.add(nowPlusOneDay); - dates.add(nowPlusTwoDays); - dates.add(nowPlusThreeDays); - } - - @BeforeEach - public void installEntities() { - users.forEach(testEntityManager::persist); - - items.get(0).setOwner(users.get(0)); - items.get(1).setOwner(users.get(1)); - items.get(2).setOwner(users.get(1)); - items.forEach(testEntityManager::persist); - - bookings.get(0).setItem(items.get(0)); - bookings.get(1).setItem(items.get(1)); - bookings.get(2).setItem(items.get(2)); - - bookings.get(0).setBooker(users.get(2)); - bookings.get(1).setBooker(users.get(2)); - bookings.get(2).setBooker(users.get(2)); - - bookings.get(0).setStart(dates.get(0).minusHours(1)); - bookings.get(1).setStart(dates.get(1).minusHours(1)); - bookings.get(2).setStart(dates.get(2).minusHours(1)); - - bookings.get(0).setEnd(dates.get(3).minusHours(1)); - bookings.get(1).setEnd(dates.get(2).minusHours(1)); - bookings.get(2).setEnd(dates.get(3).minusHours(1)); - - bookings.get(0).setStatus(BookingStatus.APPROVED); - bookings.get(1).setStatus(BookingStatus.APPROVED); - bookings.get(2).setStatus(BookingStatus.REJECTED); - - bookings.forEach(testEntityManager::persist); - } - - @Test - void findAllByBookerId() { - List foundBookings = bookingRepository.findAllByBookerId( - users.get(0).getId(), - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(0, foundBookings.size()); - - foundBookings = bookingRepository.findAllByBookerId(users.get(2).getId(), PageRequest.of(0, 3)).toList(); - Assertions.assertEquals(3, foundBookings.size()); - Assertions.assertEquals("this is item1", foundBookings.get(0).getItem().getDescription()); - } - - @Test - void findAllByBookerIdAndStartAfter() { - List foundBookings = bookingRepository.findAllByBookerIdAndStartAfter( - users.get(0).getId(), - dates.get(0), - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(0, foundBookings.size()); - - foundBookings = bookingRepository.findAllByBookerIdAndStartAfter( - users.get(2).getId(), - dates.get(1), - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(1, foundBookings.size()); - Assertions.assertEquals("this is item3", foundBookings.get(0).getItem().getDescription()); - } - - @Test - void findAllByBookerIdAndStartBeforeAndEndAfter() { - List foundBookings = bookingRepository.findAllByBookerIdAndStartBeforeAndEndAfter( - users.get(0).getId(), - dates.get(0), - dates.get(0), - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(0, foundBookings.size()); - - foundBookings = bookingRepository.findAllByBookerIdAndStartBeforeAndEndAfter( - users.get(2).getId(), - dates.get(1), - dates.get(2), - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(1, foundBookings.size()); - Assertions.assertEquals("this is item1", foundBookings.get(0).getItem().getDescription()); - } - - @Test - void findAllByBookerIdAndEndBefore() { - List foundBookings = bookingRepository.findAllByBookerIdAndEndBefore( - users.get(0).getId(), - dates.get(0), - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(0, foundBookings.size()); - - foundBookings = bookingRepository.findAllByBookerIdAndEndBefore( - users.get(2).getId(), - dates.get(3), - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(3, foundBookings.size()); - Assertions.assertEquals("this is item1", foundBookings.get(0).getItem().getDescription()); - } - - @Test - void findAllByBookerIdAndStatus() { - List foundBookings = bookingRepository.findAllByBookerIdAndStatus( - users.get(0).getId(), - BookingStatus.APPROVED, - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(0, foundBookings.size()); - - foundBookings = bookingRepository.findAllByBookerIdAndStatus( - users.get(2).getId(), - BookingStatus.APPROVED, - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(2, foundBookings.size()); - Assertions.assertEquals("this is item1", foundBookings.get(0).getItem().getDescription()); - } - - @Test - void findAllByItemOwnerId() { - List foundBookings = bookingRepository.findAllByItemOwnerId( - users.get(2).getId(), - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(0, foundBookings.size()); - - foundBookings = bookingRepository.findAllByItemOwnerId( - users.get(1).getId(), - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(2, foundBookings.size()); - Assertions.assertEquals("this is item2", foundBookings.get(0).getItem().getDescription()); - } - - @Test - void findAllByItemOwnerIdAndStartAfter() { - List foundBookings = bookingRepository.findAllByItemOwnerIdAndStartAfter( - users.get(2).getId(), - dates.get(0), - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(0, foundBookings.size()); - - foundBookings = bookingRepository.findAllByItemOwnerIdAndStartAfter( - users.get(1).getId(), - dates.get(1), - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(1, foundBookings.size()); - Assertions.assertEquals("this is item3", foundBookings.get(0).getItem().getDescription()); - } - - @Test - void findAllByItemOwnerIdAndStartBeforeAndEndAfter() { - List foundBookings = bookingRepository.findAllByItemOwnerIdAndStartBeforeAndEndAfter( - users.get(2).getId(), - dates.get(0), - dates.get(0), - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(0, foundBookings.size()); - - foundBookings = bookingRepository.findAllByItemOwnerIdAndStartBeforeAndEndAfter( - users.get(1).getId(), - dates.get(2), - dates.get(2), - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(1, foundBookings.size()); - Assertions.assertEquals("this is item3", foundBookings.get(0).getItem().getDescription()); - } - - @Test - void findAllByItemOwnerIdAndEndBefore() { - List foundBookings = bookingRepository.findAllByItemOwnerIdAndEndBefore( - users.get(2).getId(), - dates.get(0), - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(0, foundBookings.size()); - - foundBookings = bookingRepository.findAllByItemOwnerIdAndEndBefore( - users.get(1).getId(), - dates.get(3), - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(2, foundBookings.size()); - Assertions.assertEquals("this is item2", foundBookings.get(0).getItem().getDescription()); - } - - @Test - void findAllByItemOwnerIdAndStatus() { - List foundBookings = bookingRepository.findAllByItemOwnerIdAndStatus( - users.get(2).getId(), - BookingStatus.APPROVED, - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(0, foundBookings.size()); - - foundBookings = bookingRepository.findAllByItemOwnerIdAndStatus( - users.get(1).getId(), - BookingStatus.APPROVED, - PageRequest.of(0, 3) - ).toList(); - Assertions.assertEquals(1, foundBookings.size()); - Assertions.assertEquals("this is item2", foundBookings.get(0).getItem().getDescription()); - } - - @Test - void findFirstByItemIdAndStartBefore() { - BookingShort foundBooking = bookingRepository.findFirstByItemIdAndStartBefore( - items.get(2).getId(), - dates.get(0), - Sort.by("start") - ); - Assertions.assertNull(foundBooking); - - foundBooking = bookingRepository.findFirstByItemIdAndStartBefore( - items.get(0).getId(), - dates.get(1), - Sort.by("start") - ); - Assertions.assertNotNull(foundBooking); - } - - @Test - void findFirstByItemIdAndStartAfterAndStatusNot() { - BookingShort foundBooking = bookingRepository.findFirstByItemIdAndStartAfterAndStatusNot( - items.get(2).getId(), - dates.get(3), - BookingStatus.APPROVED, - Sort.by("start") - ); - Assertions.assertNull(foundBooking); - - foundBooking = bookingRepository.findFirstByItemIdAndStartAfterAndStatusNot( - items.get(1).getId(), - dates.get(0), - BookingStatus.REJECTED, - Sort.by("start") - ); - Assertions.assertNotNull(foundBooking); - } - - @Test - void findAllByBookerIdAndItemIdAndEndBefore() { - List foundBookings = new ArrayList<>(bookingRepository.findAllByBookerIdAndItemIdAndEndBefore( - users.get(2).getId(), - items.get(2).getId(), - dates.get(0) - )); - Assertions.assertEquals(0, foundBookings.size()); - - foundBookings = new ArrayList<>(bookingRepository.findAllByBookerIdAndItemIdAndEndBefore( - users.get(2).getId(), - items.get(1).getId(), - dates.get(3) - )); - Assertions.assertEquals(1, foundBookings.size()); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/booking/service/BookingServiceImplTest.java b/src/test/java/ru/practicum/shareit/booking/service/BookingServiceImplTest.java deleted file mode 100644 index 73b3437..0000000 --- a/src/test/java/ru/practicum/shareit/booking/service/BookingServiceImplTest.java +++ /dev/null @@ -1,289 +0,0 @@ -package ru.practicum.shareit.booking.service; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; -import org.springframework.data.domain.Page; -import org.springframework.web.bind.MethodArgumentNotValidException; -import ru.practicum.shareit.booking.BookingState; -import ru.practicum.shareit.booking.BookingStatus; -import ru.practicum.shareit.booking.dto.BookingDto; -import ru.practicum.shareit.booking.dto.BookingShortDto; -import ru.practicum.shareit.booking.model.Booking; -import ru.practicum.shareit.booking.repository.BookingRepository; -import ru.practicum.shareit.error.*; -import ru.practicum.shareit.item.model.Item; -import ru.practicum.shareit.item.repository.ItemRepository; -import ru.practicum.shareit.user.model.User; -import ru.practicum.shareit.user.repository.UserRepository; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; - -class BookingServiceImplTest { - - private BookingService bookingService; - - private final List users = List.of( - User.builder().id(1L).name("user1").email("user1@mail.ru").build(), - User.builder().id(2L).name("user2").email("user2@mail.ru").build(), - User.builder().id(3L).name("user3").email("user3@mail.ru").build()); - - private final List items = List.of( - Item.builder() - .id(1L) - .name("item1") - .description("this is item1") - .available(true) - .owner(users.get(0)) - .build(), - Item.builder() - .id(2L) - .name("item2") - .description("this is item2") - .available(false) - .owner(users.get(1)) - .build(), - Item.builder() - .id(3L) - .name("item3") - .description("this is item3") - .available(true) - .owner(users.get(1)) - .build() - ); - - private final List bookings = List.of( - Booking.builder() - .id(1L) - .start(dates.get(0)) - .end(dates.get(1)) - .item(items.get(0)) - .booker(users.get(0)) - .status(BookingStatus.WAITING) - .build(), - Booking.builder() - .id(2L) - .start(dates.get(1)) - .end(dates.get(2)) - .item(items.get(1)) - .booker(users.get(1)) - .status(BookingStatus.APPROVED) - .build(), - Booking.builder() - .id(3L) - .start(dates.get(2)) - .end(dates.get(3)) - .item(items.get(2)) - .booker(users.get(2)) - .status(BookingStatus.REJECTED) - .build(), - Booking.builder() - .id(5L) - .start(dates.get(0)) - .end(dates.get(1)) - .item(items.get(1)) - .booker(users.get(0)) - .status(BookingStatus.APPROVED) - .build() - ); - - private final List shortBookingsDto = List.of( - BookingShortDto.builder() - .id(bookings.get(0).getId()) - .start(bookings.get(0).getStart()) - .end(bookings.get(0).getEnd()) - .itemId(bookings.get(0).getItem().getId()) - .bookerId(bookings.get(0).getBooker().getId()) - .build(), - BookingShortDto.builder() - .id(bookings.get(1).getId()) - .start(bookings.get(1).getStart()) - .end(bookings.get(1).getEnd()) - .itemId(4L) - .bookerId(bookings.get(1).getBooker().getId()) - .build(), - BookingShortDto.builder() - .id(bookings.get(2).getId()) - .start(bookings.get(2).getStart()) - .end(bookings.get(2).getStart()) - .itemId(bookings.get(2).getItem().getId()) - .bookerId(bookings.get(2).getBooker().getId()) - .build(), - BookingShortDto.builder() - .id(bookings.get(3).getId()) - .start(bookings.get(3).getStart()) - .end(bookings.get(3).getEnd()) - .itemId(2L) - .bookerId(bookings.get(3).getBooker().getId()) - .build() - ); - - private static final List dates = new ArrayList<>(); - - @BeforeAll - public static void installDates() { - LocalDateTime now = LocalDateTime.now(); - LocalDateTime nowPlusOneDay = now.plusDays(1); - LocalDateTime nowPlusTwoDays = now.plusDays(2); - LocalDateTime nowPlusThreeDays = now.plusDays(3); - - dates.add(now); - dates.add(nowPlusOneDay); - dates.add(nowPlusTwoDays); - dates.add(nowPlusThreeDays); - } - - @BeforeEach - public void installService() { - BookingRepository bookingRepository = Mockito.mock(BookingRepository.class); - ItemRepository itemRepository = Mockito.mock(ItemRepository.class); - UserRepository userRepository = Mockito.mock(UserRepository.class); - - for (int i = 0; i < 3; i++) { - Mockito.when(itemRepository.findById(items.get(i).getId())) - .thenReturn(Optional.of(items.get(i))); - - Mockito.when(userRepository.findById(users.get(i).getId())) - .thenReturn(Optional.of(users.get(i))); - - Mockito.when(bookingRepository.findById(bookings.get(i).getId())) - .thenReturn(Optional.of(bookings.get(i))); - } - - Mockito.when(bookingRepository.findById(bookings.get(3).getId())) - .thenReturn(Optional.of(bookings.get(3))); - - Mockito.when(bookingRepository.findAllByBookerIdAndStartBeforeAndEndAfter(anyLong(), any(), any(), any())) - .thenReturn(Page.empty()); - - Mockito.when(bookingRepository.findAllByItemOwnerIdAndStartBeforeAndEndAfter(anyLong(), any(), any(), any())) - .thenReturn(Page.empty()); - - Mockito.when(itemRepository.findById(4L)) - .thenReturn(Optional.empty()); - - Mockito.when(userRepository.findById(4L)) - .thenReturn(Optional.empty()); - - Mockito.when(bookingRepository.save(any())) - .thenReturn(bookings.get(0)); - - bookingService = new BookingServiceImpl(bookingRepository, itemRepository, userRepository); - } - - @Test - void createBooking() { - Assertions.assertThrows( - MethodArgumentNotValidException.class, - () -> bookingService.createBooking(shortBookingsDto.get(2), 2L)); - - UserNotFoundException userNotFoundException = Assertions.assertThrows( - UserNotFoundException.class, - () -> bookingService.createBooking(shortBookingsDto.get(0), 4L)); - - assertEquals("Пользователь 4 не найден", userNotFoundException.getMessage()); - - userNotFoundException = Assertions.assertThrows( - UserNotFoundException.class, - () -> bookingService.createBooking(shortBookingsDto.get(0), 1L)); - - assertEquals("Пользователь 1 является владельцем вещи 1", userNotFoundException.getMessage()); - - ItemNotFoundException itemNotFoundException = Assertions.assertThrows( - ItemNotFoundException.class, - () -> bookingService.createBooking(shortBookingsDto.get(1), 2L)); - - assertEquals("Вещь 4 не найдена", itemNotFoundException.getMessage()); - - ItemNotAvailableException itemNotAvailableException = Assertions.assertThrows( - ItemNotAvailableException.class, - () -> bookingService.createBooking(shortBookingsDto.get(3), 2L)); - - assertEquals("Вещь 2 недоступна", itemNotAvailableException.getMessage()); - - BookingDto savedBookingDto = bookingService.createBooking(shortBookingsDto.get(0), 2L); - assertEquals(bookings.get(0).getId(), savedBookingDto.getId()); - } - - @Test - void approveBooking() { - BookingStatusChangeDeniedException bookingStatusChangeDeniedException = Assertions.assertThrows( - BookingStatusChangeDeniedException.class, - () -> bookingService.approveBooking(shortBookingsDto.get(2).getId(), true, 2L)); - - assertEquals("Бронирование 3 уже имеет статус REJECTED", bookingStatusChangeDeniedException.getMessage()); - - BookingDto savedBookingDto = bookingService.approveBooking(shortBookingsDto.get(0).getId(), true, 1L); - assertEquals(bookings.get(0).getId(), savedBookingDto.getId()); - } - - @Test - void getBooking() { - UserNotFoundException userNotFoundException = Assertions.assertThrows( - UserNotFoundException.class, - () -> bookingService.getBooking(shortBookingsDto.get(0).getId(), 4L)); - - assertEquals("Пользователь 4 не найден", userNotFoundException.getMessage()); - - BookingNotFoundException bookingNotFoundException = Assertions.assertThrows( - BookingNotFoundException.class, - () -> bookingService.getBooking(4L, 1L)); - - assertEquals("Бронирование 4 не найдено", bookingNotFoundException.getMessage()); - - AccessDeniedException accessDeniedException = Assertions.assertThrows( - AccessDeniedException.class, - () -> bookingService.getBooking(shortBookingsDto.get(0).getId(), 2L)); - - assertEquals("Пользователь 2 не является ни арендатором ни владельцем", accessDeniedException.getMessage()); - - BookingDto savedBookingDto = bookingService.getBooking(shortBookingsDto.get(0).getId(), 1L); - assertEquals(bookings.get(0).getId(), savedBookingDto.getId()); - } - - @Test - void getAllBookings() { - UserNotFoundException userNotFoundException = Assertions.assertThrows( - UserNotFoundException.class, - () -> bookingService.getAllBookings(4L, BookingState.ALL, 0L, 2L)); - - assertEquals("Пользователь 4 не найден", userNotFoundException.getMessage()); - - IllegalArgumentException illegalArgumentException = Assertions.assertThrows( - IllegalArgumentException.class, - () -> bookingService.getAllBookings(1L, BookingState.ALL, -1L, 2L)); - - assertEquals("Некорректные параметры пагинации", illegalArgumentException.getMessage()); - - Collection savedBookingDtos = bookingService.getAllBookings(1L, BookingState.CURRENT, 0L, 2L); - assertEquals(0, savedBookingDtos.size()); - } - - @Test - void getOwnerBookings() { - UserNotFoundException userNotFoundException = Assertions.assertThrows( - UserNotFoundException.class, - () -> bookingService.getOwnerBookings(4L, BookingState.ALL, 0L, 2L)); - - assertEquals("Пользователь 4 не найден", userNotFoundException.getMessage()); - - IllegalArgumentException illegalArgumentException = Assertions.assertThrows( - IllegalArgumentException.class, - () -> bookingService.getOwnerBookings(1L, BookingState.ALL, -1L, 2L)); - - assertEquals("Некорректные параметры пагинации", illegalArgumentException.getMessage()); - - Collection savedBookingDtos = bookingService.getOwnerBookings(1L, BookingState.CURRENT, 0L, 2L); - assertEquals(0, savedBookingDtos.size()); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/booking/service/IntegrationBookingServiceImplTest.java b/src/test/java/ru/practicum/shareit/booking/service/IntegrationBookingServiceImplTest.java deleted file mode 100644 index caea200..0000000 --- a/src/test/java/ru/practicum/shareit/booking/service/IntegrationBookingServiceImplTest.java +++ /dev/null @@ -1,159 +0,0 @@ -package ru.practicum.shareit.booking.service; - -import lombok.RequiredArgsConstructor; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; -import ru.practicum.shareit.booking.BookingState; -import ru.practicum.shareit.booking.BookingStatus; -import ru.practicum.shareit.booking.dto.BookingDto; -import ru.practicum.shareit.booking.model.Booking; -import ru.practicum.shareit.error.BookingStatusChangeDeniedException; -import ru.practicum.shareit.error.AccessDeniedException; -import ru.practicum.shareit.item.model.Item; -import ru.practicum.shareit.user.model.User; - -import javax.persistence.EntityManager; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; -import static org.junit.jupiter.api.Assertions.*; - -@Transactional -@SpringBootTest( - properties = "db.name=test", - webEnvironment = SpringBootTest.WebEnvironment.NONE) -@RequiredArgsConstructor(onConstructor_ = @Autowired) -class IntegrationBookingServiceImplTest { - private final EntityManager em; - private final BookingService bookingService; - - private final List users = List.of( - User.builder().name("user1").email("user1@mail.ru").build(), - User.builder().name("user2").email("user2@mail.ru").build(), - User.builder().name("user3").email("user3@mail.ru").build()); - - private final List items = List.of( - Item.builder().name("item1").description("this is item1").available(true).build(), - Item.builder().name("item2").description("this is item2").available(true).build(), - Item.builder().name("item3").description("this is item3").available(true).build()); - - private final List bookings = List.of( - Booking.builder().build(), - Booking.builder().build(), - Booking.builder().build() - ); - - private static final List dates = new ArrayList<>(); - - @BeforeAll - public static void installDates() { - LocalDateTime now = LocalDateTime.now(); - LocalDateTime nowPlusOneDay = now.plusDays(1); - LocalDateTime nowPlusTwoDays = now.plusDays(2); - LocalDateTime nowPlusThreeDays = now.plusDays(3); - - dates.add(now); - dates.add(nowPlusOneDay); - dates.add(nowPlusTwoDays); - dates.add(nowPlusThreeDays); - } - - @BeforeEach - public void installEntities() { - users.forEach(em::persist); - - items.get(0).setOwner(users.get(0)); - items.get(1).setOwner(users.get(1)); - items.get(2).setOwner(users.get(1)); - items.forEach(em::persist); - - bookings.get(0).setItem(items.get(0)); - bookings.get(1).setItem(items.get(1)); - bookings.get(2).setItem(items.get(2)); - - bookings.get(0).setBooker(users.get(1)); - bookings.get(1).setBooker(users.get(2)); - bookings.get(2).setBooker(users.get(2)); - - bookings.get(0).setStart(dates.get(0).minusHours(1)); - bookings.get(1).setStart(dates.get(1).minusHours(1)); - bookings.get(2).setStart(dates.get(2).minusHours(1)); - - bookings.get(0).setEnd(dates.get(3).minusHours(1)); - bookings.get(1).setEnd(dates.get(2).minusHours(1)); - bookings.get(2).setEnd(dates.get(3).minusHours(1)); - - bookings.get(0).setStatus(BookingStatus.APPROVED); - bookings.get(1).setStatus(BookingStatus.WAITING); - bookings.get(2).setStatus(BookingStatus.REJECTED); - - bookings.forEach(em::persist); - } - - @Test - void approveBooking() { - Long bookingId1 = bookings.get(0).getId(); - Long userId1 = users.get(0).getId(); - - assertThrows(BookingStatusChangeDeniedException.class, () -> bookingService.approveBooking(bookingId1, true, userId1)); - - Long bookingId2 = bookings.get(1).getId(); - assertThrows(AccessDeniedException.class, () -> bookingService.approveBooking(bookingId2, true, userId1)); - - BookingDto approvedBooking = bookingService.approveBooking(bookingId2, true, users.get(1).getId()); - - assertThat(approvedBooking.getStatus(), equalTo(BookingStatus.APPROVED)); - } - - @Test - void getAllBookings() { - List ownerBookings = new ArrayList<>(bookingService.getAllBookings(users.get(2).getId(), BookingState.ALL, 0L, 5L)); - assertThat(ownerBookings, hasSize(2)); - assertThat(ownerBookings.get(0).getItem().getName(), equalTo(items.get(2).getName())); - - ownerBookings = new ArrayList<>(bookingService.getAllBookings(users.get(2).getId(), BookingState.REJECTED, 0L, 5L)); - assertThat(ownerBookings, hasSize(1)); - assertThat(ownerBookings.get(0).getItem().getName(), equalTo(items.get(2).getName())); - - ownerBookings = new ArrayList<>(bookingService.getAllBookings(users.get(2).getId(), BookingState.WAITING, 0L, 5L)); - assertThat(ownerBookings, hasSize(1)); - assertThat(ownerBookings.get(0).getItem().getName(), equalTo(items.get(1).getName())); - - ownerBookings = new ArrayList<>(bookingService.getAllBookings(users.get(2).getId(), BookingState.FUTURE, 0L, 5L)); - assertThat(ownerBookings, hasSize(2)); - assertThat(ownerBookings.get(0).getItem().getName(), equalTo(items.get(2).getName())); - - ownerBookings = new ArrayList<>(bookingService.getAllBookings(users.get(1).getId(), BookingState.PAST, 0L, 5L)); - assertThat(ownerBookings, empty()); - } - - @Test - void getOwnerBookings() { - List ownerBookings = new ArrayList<>(bookingService.getOwnerBookings(users.get(1).getId(), BookingState.ALL, 0L, 5L)); - assertThat(ownerBookings, hasSize(2)); - assertThat(ownerBookings.get(0).getItem().getName(), equalTo(items.get(2).getName())); - - ownerBookings = new ArrayList<>(bookingService.getOwnerBookings(users.get(1).getId(), BookingState.REJECTED, 0L, 5L)); - assertThat(ownerBookings, hasSize(1)); - assertThat(ownerBookings.get(0).getItem().getName(), equalTo(items.get(2).getName())); - - ownerBookings = new ArrayList<>(bookingService.getOwnerBookings(users.get(1).getId(), BookingState.WAITING, 0L, 5L)); - assertThat(ownerBookings, hasSize(1)); - assertThat(ownerBookings.get(0).getItem().getName(), equalTo(items.get(1).getName())); - - ownerBookings = new ArrayList<>(bookingService.getOwnerBookings(users.get(1).getId(), BookingState.FUTURE, 0L, 5L)); - assertThat(ownerBookings, hasSize(2)); - assertThat(ownerBookings.get(0).getItem().getName(), equalTo(items.get(2).getName())); - - ownerBookings = new ArrayList<>(bookingService.getOwnerBookings(users.get(1).getId(), BookingState.PAST, 0L, 5L)); - assertThat(ownerBookings, empty()); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/error/ErrorHandlerTest.java b/src/test/java/ru/practicum/shareit/error/ErrorHandlerTest.java deleted file mode 100644 index 3040356..0000000 --- a/src/test/java/ru/practicum/shareit/error/ErrorHandlerTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package ru.practicum.shareit.error; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class ErrorHandlerTest { - - @Test - public void testItemNotFoundHandler() { - ErrorHandler errorHandler = new ErrorHandler(); - ItemNotFoundException exception = new ItemNotFoundException("Item not found"); - ErrorResponse response = errorHandler.itemNotFound(exception); - - Assertions.assertEquals("Item not found", response.getError()); - } - - @Test - public void testItemUnavailableErrorHandler() { - ErrorHandler errorHandler = new ErrorHandler(); - ItemNotAvailableException exception = new ItemNotAvailableException("Item unavailable"); - ErrorResponse response = errorHandler.itemUnavailableError(exception); - - Assertions.assertEquals("Item unavailable", response.getError()); - } -} diff --git a/src/test/java/ru/practicum/shareit/item/controller/ItemControllerTest.java b/src/test/java/ru/practicum/shareit/item/controller/ItemControllerTest.java deleted file mode 100644 index cbc270b..0000000 --- a/src/test/java/ru/practicum/shareit/item/controller/ItemControllerTest.java +++ /dev/null @@ -1,222 +0,0 @@ -package ru.practicum.shareit.item.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; -import ru.practicum.shareit.item.dto.CommentDto; -import ru.practicum.shareit.item.dto.ItemDto; -import ru.practicum.shareit.item.service.ItemService; - -import java.nio.charset.StandardCharsets; -import java.time.LocalDateTime; -import java.util.List; - -import static org.hamcrest.Matchers.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@WebMvcTest(controllers = ItemController.class) -class ItemControllerTest { - - @Autowired - ObjectMapper mapper; - - @MockBean - ItemService itemService; - - @Autowired - private MockMvc mvc; - - private final List items = List.of( - ItemDto.builder().name("item1").description("this is item1").available(true).build(), - ItemDto.builder().description("this is item2").available(true).build(), - ItemDto.builder().name("item3").available(true).build(), - ItemDto.builder().name("item4").description("this is item4").build()); - - @Test - void createItem() throws Exception { - when(itemService.createItem(any(), anyLong())) - .thenReturn(items.get(0)); - - mvc.perform(post("/items") - .header("X-Sharer-User-Id", 1L) - .content(mapper.writeValueAsString(items.get(0))) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id", is(items.get(0).getId()), Long.class)) - .andExpect(jsonPath("$.name", is(items.get(0).getName()))) - .andExpect(jsonPath("$.description", is(items.get(0).getDescription()))) - .andExpect(jsonPath("$.available", is(items.get(0).getAvailable()))) - .andExpect(jsonPath("$.lastBooking", nullValue())) - .andExpect(jsonPath("$.nextBooking", nullValue())) - .andExpect(jsonPath("$.requestId", nullValue())) - .andExpect(jsonPath("$.comments", nullValue())); - - mvc.perform(post("/items") - .header("X-Sharer-User-Id", 1L) - .content(mapper.writeValueAsString(items.get(1))) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - - mvc.perform(post("/items") - .header("X-Sharer-User-Id", 1L) - .content(mapper.writeValueAsString(items.get(2))) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - - mvc.perform(post("/items") - .header("X-Sharer-User-Id", 1L) - .content(mapper.writeValueAsString(items.get(3))) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - - @Test - void changeItem() throws Exception { - when(itemService.changeItem(anyLong(), any(), anyLong())) - .thenReturn(items.get(0)); - - mvc.perform(patch("/items/1") - .header("X-Sharer-User-Id", 1L) - .content(mapper.writeValueAsString(items.get(0))) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id", is(items.get(0).getId()), Long.class)) - .andExpect(jsonPath("$.name", is(items.get(0).getName()))) - .andExpect(jsonPath("$.description", is(items.get(0).getDescription()))) - .andExpect(jsonPath("$.available", is(items.get(0).getAvailable()))) - .andExpect(jsonPath("$.lastBooking", nullValue())) - .andExpect(jsonPath("$.nextBooking", nullValue())) - .andExpect(jsonPath("$.requestId", nullValue())) - .andExpect(jsonPath("$.comments", nullValue())); - - ItemDto itemDtoUpdate = ItemDto.builder().name("").build(); - mvc.perform(patch("/items/1") - .header("X-Sharer-User-Id", 1L) - .content(mapper.writeValueAsString(itemDtoUpdate)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - - itemDtoUpdate = ItemDto.builder().description("").build(); - mvc.perform(patch("/items/1") - .header("X-Sharer-User-Id", 1L) - .content(mapper.writeValueAsString(itemDtoUpdate)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - - @Test - void getItem() throws Exception { - when(itemService.getItem(anyLong(), anyLong())) - .thenReturn(items.get(0)); - - mvc.perform(get("/items/1") - .header("X-Sharer-User-Id", 1L)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id", is(items.get(0).getId()), Long.class)) - .andExpect(jsonPath("$.name", is(items.get(0).getName()))) - .andExpect(jsonPath("$.description", is(items.get(0).getDescription()))) - .andExpect(jsonPath("$.available", is(items.get(0).getAvailable()))) - .andExpect(jsonPath("$.lastBooking", nullValue())) - .andExpect(jsonPath("$.nextBooking", nullValue())) - .andExpect(jsonPath("$.requestId", nullValue())) - .andExpect(jsonPath("$.comments", nullValue())); - } - - @Test - void getAllItems() throws Exception { - when(itemService.getAllItems(anyLong(), anyLong(), anyLong())) - .thenReturn(items); - - mvc.perform(get("/items") - .header("X-Sharer-User-Id", 1L)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$", hasSize(4))) - .andExpect(jsonPath("$[0].id", is(items.get(0).getId()), Long.class)) - .andExpect(jsonPath("$[0].name", is(items.get(0).getName()))) - .andExpect(jsonPath("$[0].description", is(items.get(0).getDescription()))) - .andExpect(jsonPath("$[0].available", is(items.get(0).getAvailable()))) - .andExpect(jsonPath("$[0].lastBooking", nullValue())) - .andExpect(jsonPath("$[0].nextBooking", nullValue())) - .andExpect(jsonPath("$[0].requestId", nullValue())) - .andExpect(jsonPath("$[0].comments", nullValue())); - } - - @Test - void searchItems() throws Exception { - when(itemService.searchItems(anyString(), anyLong(), anyLong())) - .thenReturn(items); - - mvc.perform(get("/items/search?text=item")) - .andExpect(status().isOk()) - .andExpect(jsonPath("$", hasSize(4))) - .andExpect(jsonPath("$[0].id", is(items.get(0).getId()), Long.class)) - .andExpect(jsonPath("$[0].name", is(items.get(0).getName()))) - .andExpect(jsonPath("$[0].description", is(items.get(0).getDescription()))) - .andExpect(jsonPath("$[0].available", is(items.get(0).getAvailable()))) - .andExpect(jsonPath("$[0].lastBooking", nullValue())) - .andExpect(jsonPath("$[0].nextBooking", nullValue())) - .andExpect(jsonPath("$[0].requestId", nullValue())) - .andExpect(jsonPath("$[0].comments", nullValue())); - } - - @Test - void addComment() throws Exception { - CommentDto commentDto = CommentDto.builder() - .id(1L) - .text("this is comment") - .authorName("author name") - .created(LocalDateTime.now()) - .build(); - - when(itemService.addComment(anyLong(), any(), anyLong())) - .thenReturn(commentDto); - - mvc.perform(post("/items/1/comment") - .header("X-Sharer-User-Id", 1L) - .content(mapper.writeValueAsString(commentDto)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id", is(commentDto.getId()), Long.class)) - .andExpect(jsonPath("$.text", is(commentDto.getText()))) - .andExpect(jsonPath("$.authorName", is(commentDto.getAuthorName()))); - - commentDto = CommentDto.builder() - .id(1L) - .created(LocalDateTime.now()) - .created(LocalDateTime.now()) - .build(); - - mvc.perform(post("/items/1/comment") - .header("X-Sharer-User-Id", 1L) - .content(mapper.writeValueAsString(commentDto)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/item/dto/CommentDtoTest.java b/src/test/java/ru/practicum/shareit/item/dto/CommentDtoTest.java deleted file mode 100644 index d0b9b7b..0000000 --- a/src/test/java/ru/practicum/shareit/item/dto/CommentDtoTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package ru.practicum.shareit.item.dto; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.json.JsonTest; -import org.springframework.boot.test.json.JacksonTester; -import org.springframework.boot.test.json.JsonContent; - -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; - -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - -@JsonTest -class CommentDtoTest { - @Autowired - private JacksonTester json; - - @Test - void testCommentDto() throws Exception { - LocalDateTime now = LocalDateTime.now(); - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS"); - - CommentDto commentDto = CommentDto.builder() - .id(1L) - .text("text") - .authorName("author name") - .created(now) - .build(); - - JsonContent result = json.write(commentDto); - - assertThat(result).extractingJsonPathNumberValue("$.id").isEqualTo(1); - assertThat(result).extractingJsonPathStringValue("$.text").isEqualTo("text"); - assertThat(result).extractingJsonPathStringValue("$.authorName").isEqualTo("author name"); - assertThat(result).extractingJsonPathStringValue("$.created").isEqualTo(now.format(formatter)); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/item/dto/CommentMapperTest.java b/src/test/java/ru/practicum/shareit/item/dto/CommentMapperTest.java deleted file mode 100644 index 56311ff..0000000 --- a/src/test/java/ru/practicum/shareit/item/dto/CommentMapperTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package ru.practicum.shareit.item.dto; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import ru.practicum.shareit.item.model.Comment; -import ru.practicum.shareit.user.model.User; - -import java.time.LocalDateTime; - -public class CommentMapperTest { - - @Test - public void testToCommentDto() { - Comment comment = Comment.builder() - .id(1L) - .text("Test comment") - .author(User.builder().name("John Doe").build()) - .created(LocalDateTime.now()) - .build(); - - CommentDto commentDto = CommentMapper.toCommentDto(comment); - - Assertions.assertEquals(comment.getId(), commentDto.getId()); - Assertions.assertEquals(comment.getText(), commentDto.getText()); - Assertions.assertEquals(comment.getAuthor().getName(), commentDto.getAuthorName()); - Assertions.assertEquals(comment.getCreated(), commentDto.getCreated()); - } - - @Test - public void testToComment() { - CommentDto commentDto = CommentDto.builder() - .id(1L) - .text("Test comment") - .created(LocalDateTime.now()) - .build(); - - Comment comment = CommentMapper.toComment(commentDto); - - Assertions.assertEquals(commentDto.getId(), comment.getId()); - Assertions.assertEquals(commentDto.getText(), comment.getText()); - Assertions.assertEquals(commentDto.getCreated(), comment.getCreated()); - } -} diff --git a/src/test/java/ru/practicum/shareit/item/dto/ItemDtoTest.java b/src/test/java/ru/practicum/shareit/item/dto/ItemDtoTest.java deleted file mode 100644 index 5cf014c..0000000 --- a/src/test/java/ru/practicum/shareit/item/dto/ItemDtoTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package ru.practicum.shareit.item.dto; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.json.JsonTest; -import org.springframework.boot.test.json.JacksonTester; -import org.springframework.boot.test.json.JsonContent; -import ru.practicum.shareit.booking.dto.BookingShortDto; - -import java.time.LocalDateTime; -import java.util.List; - -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; - -@JsonTest -class ItemDtoTest { - @Autowired - private JacksonTester json; - - @Test - void testItemDto() throws Exception { - BookingShortDto bookingShortDto = BookingShortDto.builder() - .id(1L) - .start(LocalDateTime.now()) - .end(LocalDateTime.now()) - .itemId(1L) - .bookerId(1L) - .build(); - - CommentDto commentDto = CommentDto.builder() - .id(1L) - .text("this is comment") - .authorName("author name") - .created(LocalDateTime.now()) - .build(); - - ItemDto itemDto = ItemDto.builder() - .id(1L) - .name("item") - .description("description") - .available(true) - .lastBooking(bookingShortDto) - .nextBooking(bookingShortDto) - .requestId(1L) - .comments(List.of(commentDto)) - .build(); - - JsonContent result = json.write(itemDto); - - assertThat(result).extractingJsonPathNumberValue("$.id").isEqualTo(1); - assertThat(result).extractingJsonPathStringValue("$.name").isEqualTo("item"); - assertThat(result).extractingJsonPathStringValue("$.description").isEqualTo("description"); - assertThat(result).extractingJsonPathBooleanValue("$.available").isEqualTo(true); - assertThat(result).extractingJsonPathNumberValue("$.lastBooking.id").isEqualTo(1); - assertThat(result).extractingJsonPathNumberValue("$.lastBooking.itemId").isEqualTo(1); - assertThat(result).extractingJsonPathNumberValue("$.lastBooking.bookerId").isEqualTo(1); - assertThat(result).extractingJsonPathNumberValue("$.requestId").isEqualTo(1); - assertThat(result).extractingJsonPathNumberValue("$.comments[0].id").isEqualTo(1); - assertThat(result).extractingJsonPathStringValue("$.comments[0].text").isEqualTo("this is comment"); - assertThat(result).extractingJsonPathStringValue("$.comments[0].authorName").isEqualTo("author name"); - } - -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/item/repository/CommentRepositoryTest.java b/src/test/java/ru/practicum/shareit/item/repository/CommentRepositoryTest.java deleted file mode 100644 index c45b719..0000000 --- a/src/test/java/ru/practicum/shareit/item/repository/CommentRepositoryTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package ru.practicum.shareit.item.repository; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; -import ru.practicum.shareit.item.model.Comment; -import ru.practicum.shareit.item.model.Item; -import ru.practicum.shareit.user.model.User; - -import java.util.ArrayList; -import java.util.List; - -@DataJpaTest -@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) -class CommentRepositoryTest { - @Autowired - private TestEntityManager testEntityManager; - - @Autowired - private CommentRepository commentRepository; - - @Test - void contextLoads() { - Assertions.assertNotNull(testEntityManager); - } - - private final List users = List.of( - User.builder().name("user1").email("user1@mail.ru").build(), - User.builder().name("user2").email("user2@mail.ru").build(), - User.builder().name("user3").email("user3@mail.ru").build()); - private final List items = List.of( - Item.builder().name("item1").description("this is item1").available(true).build(), - Item.builder().name("item2").description("this is item2").available(true).build(), - Item.builder().name("item3").description("this is item3").available(true).build()); - - private final List comments = List.of( - Comment.builder().text("comment1").build(), - Comment.builder().text("comment2").build(), - Comment.builder().text("comment3").build()); - - @BeforeEach - public void installEntities() { - users.forEach(testEntityManager::persist); - - items.get(0).setOwner(users.get(0)); - items.get(1).setOwner(users.get(1)); - items.get(2).setOwner(users.get(1)); - items.forEach(testEntityManager::persist); - - comments.get(0).setItem(items.get(0)); - comments.get(1).setItem(items.get(1)); - comments.get(2).setItem(items.get(1)); - - comments.get(0).setAuthor(users.get(2)); - comments.get(1).setAuthor(users.get(2)); - comments.get(2).setAuthor(users.get(2)); - comments.forEach(testEntityManager::persist); - } - - @Test - void findAllByItemId() { - List foundComments = new ArrayList<>(commentRepository.findAllByItemId(items.get(2).getId())); - Assertions.assertEquals(0, foundComments.size()); - - foundComments = new ArrayList<>(commentRepository.findAllByItemId(items.get(1).getId())); - Assertions.assertEquals(2, foundComments.size()); - Assertions.assertEquals("comment3", foundComments.get(1).getText()); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/item/repository/ItemRepositoryTest.java b/src/test/java/ru/practicum/shareit/item/repository/ItemRepositoryTest.java deleted file mode 100644 index 09ebf85..0000000 --- a/src/test/java/ru/practicum/shareit/item/repository/ItemRepositoryTest.java +++ /dev/null @@ -1,100 +0,0 @@ -package ru.practicum.shareit.item.repository; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; -import org.springframework.data.domain.PageRequest; -import ru.practicum.shareit.item.model.Item; -import ru.practicum.shareit.request.model.ItemRequest; -import ru.practicum.shareit.user.model.User; - -import java.util.ArrayList; -import java.util.List; - -@DataJpaTest -@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) -class ItemRepositoryTest { - @Autowired - private TestEntityManager testEntityManager; - - @Autowired - private ItemRepository itemRepository; - - @Test - void contextLoads() { - Assertions.assertNotNull(testEntityManager); - } - - private final List users = List.of( - User.builder().name("user1").email("user1@mail.ru").build(), - User.builder().name("user2").email("user2@mail.ru").build(), - User.builder().name("user3").email("user3@mail.ru").build()); - - private final List items = List.of( - Item.builder().name("item1").description("this is item1").available(true).build(), - Item.builder().name("item2").description("this is item2").available(true).build(), - Item.builder().name("item3").description("this is item3").available(true).build()); - - private final List requests = List.of( - ItemRequest.builder().description("this is request1").build(), - ItemRequest.builder().description("this is request2").build(), - ItemRequest.builder().description("this is request3").build()); - - @BeforeEach - public void installEntities() { - users.forEach(testEntityManager::persist); - - items.get(0).setOwner(users.get(0)); - items.get(1).setOwner(users.get(1)); - items.get(2).setOwner(users.get(1)); - - items.get(0).setRequest(requests.get(0)); - items.get(1).setRequest(requests.get(1)); - items.get(2).setRequest(requests.get(2)); - items.forEach(testEntityManager::persist); - - requests.get(0).setRequestor(users.get(1)); - requests.get(1).setRequestor(users.get(2)); - requests.get(2).setRequestor(users.get(2)); - requests.forEach(testEntityManager::persist); - } - - @Test - void findAllByOwner() { - List itemsByOwner = itemRepository.findAllByOwner(users.get(2), PageRequest.of(0, 3)).toList(); - Assertions.assertEquals(0, itemsByOwner.size()); - - itemsByOwner = itemRepository.findAllByOwner(users.get(0), PageRequest.of(0, 3)).toList(); - Assertions.assertEquals(1, itemsByOwner.size()); - Assertions.assertEquals("this is item1", itemsByOwner.get(0).getDescription()); - - itemsByOwner = itemRepository.findAllByOwner(users.get(1), PageRequest.of(0, 3)).toList(); - Assertions.assertEquals(2, itemsByOwner.size()); - Assertions.assertEquals("this is item3", itemsByOwner.get(1).getDescription()); - } - - @Test - void findAllByRequest() { - List itemsByRequest = new ArrayList<>(itemRepository.findAllByRequest(requests.get(2))); - Assertions.assertEquals(1, itemsByRequest.size()); - Assertions.assertEquals("this is item3", itemsByRequest.get(0).getDescription()); - } - - @Test - void search() { - List foundItems = itemRepository.search("unknown", PageRequest.of(0, 3)).toList(); - Assertions.assertEquals(0, foundItems.size()); - - foundItems = itemRepository.search(" item1", PageRequest.of(0, 3)).toList(); - Assertions.assertEquals(1, foundItems.size()); - Assertions.assertEquals("this is item1", foundItems.get(0).getDescription()); - - foundItems = itemRepository.search(" item", PageRequest.of(0, 3)).toList(); - Assertions.assertEquals(3, foundItems.size()); - Assertions.assertEquals("this is item3", foundItems.get(2).getDescription()); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/item/service/IntegrationItemServiceImplTest.java b/src/test/java/ru/practicum/shareit/item/service/IntegrationItemServiceImplTest.java deleted file mode 100644 index c752335..0000000 --- a/src/test/java/ru/practicum/shareit/item/service/IntegrationItemServiceImplTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package ru.practicum.shareit.item.service; - -import lombok.RequiredArgsConstructor; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; -import ru.practicum.shareit.item.dto.ItemDto; -import ru.practicum.shareit.item.model.Item; -import ru.practicum.shareit.user.model.User; - -import javax.persistence.EntityManager; -import java.util.ArrayList; -import java.util.List; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; - -@Transactional -@SpringBootTest( - properties = "db.name=test", - webEnvironment = SpringBootTest.WebEnvironment.NONE) -@RequiredArgsConstructor(onConstructor_ = @Autowired) -class IntegrationItemServiceImplTest { - private final EntityManager em; - private final ItemService itemService; - - private final List users = List.of( - User.builder().name("user1").email("user1@mail.ru").build(), - User.builder().name("user2").email("user2@mail.ru").build(), - User.builder().name("user3").email("user3@mail.ru").build()); - - private final List items = List.of( - Item.builder().name("item1").description("this is item1").available(true).build(), - Item.builder().name("item2").description("this is item2").available(true).build(), - Item.builder().name("item3").description("this is item3").available(true).build()); - - @BeforeEach - public void installEntities() { - users.forEach(em::persist); - - items.get(0).setOwner(users.get(0)); - items.get(1).setOwner(users.get(1)); - items.get(2).setOwner(users.get(1)); - items.forEach(em::persist); - } - - @Test - void getAllItems() { - List serviceItems = new ArrayList<>(itemService.getAllItems(users.get(1).getId(), 0L, 3L)); - - assertThat(serviceItems, hasSize(2)); - - for (int i = 0; i < serviceItems.size(); i++) { - assertThat(serviceItems.get(i).getId(), notNullValue()); - assertThat(serviceItems.get(i).getName(), equalTo(items.get(i + 1).getName())); - assertThat(serviceItems.get(i).getDescription(), equalTo(items.get(i + 1).getDescription())); - assertThat(serviceItems.get(i).getAvailable(), equalTo(items.get(i + 1).getAvailable())); - } - } - - @Test - void searchItems() { - List serviceItems = new ArrayList<>(itemService.searchItems("is it", 0L, 5L)); - - assertThat(serviceItems, hasSize(3)); - - for (int i = 0; i < serviceItems.size(); i++) { - assertThat(serviceItems.get(i).getId(), notNullValue()); - assertThat(serviceItems.get(i).getName(), equalTo(items.get(i).getName())); - assertThat(serviceItems.get(i).getDescription(), equalTo(items.get(i).getDescription())); - assertThat(serviceItems.get(i).getAvailable(), equalTo(items.get(i).getAvailable())); - } - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/item/service/ItemServiceImplTest.java b/src/test/java/ru/practicum/shareit/item/service/ItemServiceImplTest.java deleted file mode 100644 index 3224b0c..0000000 --- a/src/test/java/ru/practicum/shareit/item/service/ItemServiceImplTest.java +++ /dev/null @@ -1,277 +0,0 @@ -package ru.practicum.shareit.item.service; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; -import ru.practicum.shareit.booking.BookingStatus; -import ru.practicum.shareit.booking.model.Booking; -import ru.practicum.shareit.booking.repository.BookingRepository; -import ru.practicum.shareit.error.ItemNotFoundException; -import ru.practicum.shareit.error.ItemNotAvailableException; -import ru.practicum.shareit.error.AccessDeniedException; -import ru.practicum.shareit.error.UserNotFoundException; -import ru.practicum.shareit.item.dto.CommentMapper; -import ru.practicum.shareit.item.dto.ItemDto; -import ru.practicum.shareit.item.dto.ItemMapper; -import ru.practicum.shareit.item.model.Comment; -import ru.practicum.shareit.item.model.Item; -import ru.practicum.shareit.item.repository.CommentRepository; -import ru.practicum.shareit.item.repository.ItemRepository; -import ru.practicum.shareit.request.model.ItemRequest; -import ru.practicum.shareit.request.repository.ItemRequestRepository; -import ru.practicum.shareit.user.model.User; -import ru.practicum.shareit.user.repository.UserRepository; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; - -class ItemServiceImplTest { - private ItemService itemService; - - private final List users = List.of( - User.builder().id(1L).name("user1").email("user1@mail.ru").build(), - User.builder().id(2L).name("user2").email("user2@mail.ru").build(), - User.builder().id(3L).name("user3").email("user3@mail.ru").build()); - - private final List items = List.of( - Item.builder() - .id(1L) - .name("item1") - .description("this is item1") - .available(true) - .owner(users.get(0)) - .build(), - Item.builder() - .id(2L) - .name("item2") - .description("this is item2") - .available(false) - .owner(users.get(1)) - .build(), - Item.builder() - .id(3L) - .name("item3") - .description("this is item3") - .available(true) - .owner(users.get(1)) - .build() - ); - - private final List bookings = List.of( - Booking.builder() - .id(1L) - .start(dates.get(0)) - .end(dates.get(1)) - .item(items.get(0)) - .booker(users.get(0)) - .status(BookingStatus.WAITING) - .build(), - Booking.builder() - .id(2L) - .start(dates.get(1)) - .end(dates.get(2)) - .item(items.get(1)) - .booker(users.get(1)) - .status(BookingStatus.APPROVED) - .build(), - Booking.builder() - .id(3L) - .start(dates.get(2)) - .end(dates.get(3)) - .item(items.get(2)) - .booker(users.get(2)) - .status(BookingStatus.REJECTED) - .build(), - Booking.builder() - .id(5L) - .start(dates.get(0)) - .end(dates.get(1)) - .item(items.get(1)) - .booker(users.get(0)) - .status(BookingStatus.APPROVED) - .build() - ); - - private final List requests = List.of( - ItemRequest.builder() - .id(1L) - .description("this is request1") - .requestor(users.get(0)) - .build(), - ItemRequest.builder() - .id(2L) - .description("this is request2") - .requestor(users.get(1)) - .build(), - ItemRequest.builder() - .id(3L) - .description("this is request3") - .requestor(users.get(2)) - .build()); - - private final List comments = List.of( - Comment.builder() - .id(1L) - .text("comment1") - .author(users.get(0)) - .item(items.get(0)) - .created(dates.get(0)) - .build(), - Comment.builder() - .id(2L) - .text("comment2") - .author(users.get(1)) - .item(items.get(1)) - .created(dates.get(1)) - .build(), - Comment.builder() - .id(3L) - .text("comment3") - .author(users.get(2)) - .item(items.get(2)) - .created(dates.get(2)) - .build()); - private static final List dates = new ArrayList<>(); - - @BeforeAll - public static void installDates() { - LocalDateTime now = LocalDateTime.now(); - LocalDateTime nowPlusOneDay = now.plusDays(1); - LocalDateTime nowPlusTwoDays = now.plusDays(2); - LocalDateTime nowPlusThreeDays = now.plusDays(3); - - dates.add(now); - dates.add(nowPlusOneDay); - dates.add(nowPlusTwoDays); - dates.add(nowPlusThreeDays); - } - - @BeforeEach - public void installService() { - BookingRepository bookingRepository = Mockito.mock(BookingRepository.class); - ItemRepository itemRepository = Mockito.mock(ItemRepository.class); - UserRepository userRepository = Mockito.mock(UserRepository.class); - CommentRepository commentRepository = Mockito.mock(CommentRepository.class); - ItemRequestRepository itemRequestRepository = Mockito.mock(ItemRequestRepository.class); - - for (int i = 0; i < 3; i++) { - Mockito.when(itemRepository.findById(items.get(i).getId())) - .thenReturn(Optional.of(items.get(i))); - - Mockito.when(itemRepository.save(items.get(i))) - .thenReturn(items.get(i)); - - Mockito.when(userRepository.findById(users.get(i).getId())) - .thenReturn(Optional.of(users.get(i))); - - Mockito.when(bookingRepository.findById(bookings.get(i).getId())) - .thenReturn(Optional.of(bookings.get(i))); - - Mockito.when(itemRequestRepository.findById(requests.get(i).getId())) - .thenReturn(Optional.of(requests.get(i))); - - Mockito.when(commentRepository.findAllByItemId(items.get(i).getId())) - .thenReturn(List.of(comments.get(i))); - - Mockito.when(commentRepository.save(comments.get(i))) - .thenReturn(comments.get(i)); - } - - Mockito.when(bookingRepository.findById(bookings.get(3).getId())) - .thenReturn(Optional.of(bookings.get(3))); - - Mockito.when(bookingRepository.findAllByBookerIdAndItemIdAndEndBefore(eq(users.get(0).getId()), eq(items.get(0).getId()), any())) - .thenReturn(List.of(bookings.get(0))); - - Mockito.when(itemRepository.findById(4L)) - .thenReturn(Optional.empty()); - - Mockito.when(userRepository.findById(4L)) - .thenReturn(Optional.empty()); - - Mockito.when(bookingRepository.save(any())) - .thenReturn(bookings.get(0)); - - items.get(0).setRequest(requests.get(0)); - - itemService = new ItemServiceImpl( - itemRepository, - userRepository, - bookingRepository, - commentRepository, - itemRequestRepository); - } - - - @Test - void createItem() { - UserNotFoundException userNotFoundException = Assertions.assertThrows( - UserNotFoundException.class, - () -> itemService.createItem(ItemMapper.toItemDto(items.get(0)), 4L)); - - assertEquals("Пользователь 4 не существует", userNotFoundException.getMessage()); - - ItemDto itemDto = itemService.createItem(ItemMapper.toItemDto(items.get(0)), 1L); - assertEquals(items.get(0).getId(), itemDto.getId()); - } - - @Test - void changeItem() { - ItemNotFoundException itemNotFoundException = Assertions.assertThrows( - ItemNotFoundException.class, - () -> itemService.changeItem(4L, ItemMapper.toItemDto(items.get(0)), users.get(0).getId())); - - assertEquals("Вещь 4 не найдена", itemNotFoundException.getMessage()); - - AccessDeniedException accessDeniedException = Assertions.assertThrows( - AccessDeniedException.class, - () -> itemService.changeItem(items.get(0).getId(), ItemMapper.toItemDto(items.get(0)), users.get(1).getId())); - - assertEquals("У пользователя 2 нет прав на изменение вещи 1", accessDeniedException.getMessage()); - - ItemDto changedItemDto = itemService.changeItem(items.get(0).getId(), ItemMapper.toItemDto(items.get(1)), users.get(0).getId()); - assertEquals(items.get(0).getId(), changedItemDto.getId()); - assertEquals(items.get(1).getName(), changedItemDto.getName()); - } - - @Test - void getItem() { - ItemNotFoundException itemNotFoundException = Assertions.assertThrows( - ItemNotFoundException.class, - () -> itemService.getItem(4L, 0L)); - - assertEquals("Вещь 4 не найдена", itemNotFoundException.getMessage()); - - ItemDto itemDto = itemService.getItem(items.get(0).getId(), 1L); - assertEquals(items.get(0).getId(), itemDto.getId()); - } - - @Test - void addComment() { - UserNotFoundException userNotFoundException = Assertions.assertThrows( - UserNotFoundException.class, - () -> itemService.addComment(items.get(0).getId(), CommentMapper.toCommentDto(comments.get(0)), 4L)); - - assertEquals("Пользователь 4 не существует", userNotFoundException.getMessage()); - - ItemNotFoundException itemNotFoundException = Assertions.assertThrows( - ItemNotFoundException.class, - () -> itemService.addComment(4L, CommentMapper.toCommentDto(comments.get(0)), 1L)); - - assertEquals("Вещь 4 не существует", itemNotFoundException.getMessage()); - - ItemNotAvailableException itemNotAvailableException = Assertions.assertThrows( - ItemNotAvailableException.class, - () -> itemService.addComment(items.get(1).getId(), CommentMapper.toCommentDto(comments.get(0)), 1L)); - - assertEquals("Пользователь 1 не бронировал вещь 2", itemNotAvailableException.getMessage()); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/request/controller/ItemRequestControllerTest.java b/src/test/java/ru/practicum/shareit/request/controller/ItemRequestControllerTest.java deleted file mode 100644 index 1d9b163..0000000 --- a/src/test/java/ru/practicum/shareit/request/controller/ItemRequestControllerTest.java +++ /dev/null @@ -1,110 +0,0 @@ -package ru.practicum.shareit.request.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; -import ru.practicum.shareit.item.dto.ItemDto; -import ru.practicum.shareit.request.dto.ItemRequestDto; -import ru.practicum.shareit.request.service.ItemRequestService; - -import java.nio.charset.StandardCharsets; -import java.util.List; - -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -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; - -@WebMvcTest(controllers = ItemRequestController.class) -class ItemRequestControllerTest { - - @Autowired - ObjectMapper mapper; - - @MockBean - ItemRequestService itemRequestService; - - @Autowired - private MockMvc mvc; - - private final List items = List.of( - ItemDto.builder().name("item1").description("this is item1").available(true).build(), - ItemDto.builder().description("this is item2").available(true).build(), - ItemDto.builder().name("item3").available(true).build(), - ItemDto.builder().name("item4").description("this is item4").build()); - - private final List requests = List.of( - ItemRequestDto.builder().description("this is request1").items(items).build(), - ItemRequestDto.builder().items(items).build()); - - @Test - void addItemRequest() throws Exception { - when(itemRequestService.addItemRequest(any(), anyLong())) - .thenReturn(requests.get(0)); - - mvc.perform(post("/requests") - .header("X-Sharer-User-Id", 1L) - .content(mapper.writeValueAsString(requests.get(0))) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id", is(requests.get(0).getId()), Long.class)) - .andExpect(jsonPath("$.description", is(requests.get(0).getDescription()))); - - mvc.perform(post("/requests") - .header("X-Sharer-User-Id", 1L) - .content(mapper.writeValueAsString(requests.get(1))) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - - @Test - void getItemRequests() throws Exception { - when(itemRequestService.getItemRequests(anyLong())) - .thenReturn(requests); - - mvc.perform(get("/requests") - .header("X-Sharer-User-Id", 1L)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$", hasSize(2))) - .andExpect(jsonPath("$[0].id", is(requests.get(0).getId()), Long.class)) - .andExpect(jsonPath("$[0].description", is(requests.get(0).getDescription()))); - } - - @Test - void getItemRequest() throws Exception { - when(itemRequestService.getItemRequest(anyLong(), anyLong())) - .thenReturn(requests.get(0)); - - mvc.perform(get("/requests/1") - .header("X-Sharer-User-Id", 1L)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id", is(requests.get(0).getId()), Long.class)) - .andExpect(jsonPath("$.description", is(requests.get(0).getDescription()))); - } - - @Test - void getOtherItemRequests() throws Exception { - when(itemRequestService.getOtherItemRequests(anyLong(), anyLong(), anyLong())) - .thenReturn(requests); - - mvc.perform(get("/requests/all") - .header("X-Sharer-User-Id", 1L)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$", hasSize(2))) - .andExpect(jsonPath("$[0].id", is(requests.get(0).getId()), Long.class)) - .andExpect(jsonPath("$[0].description", is(requests.get(0).getDescription()))); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/request/dto/ItemRequestDtoTest.java b/src/test/java/ru/practicum/shareit/request/dto/ItemRequestDtoTest.java deleted file mode 100644 index 8e3c675..0000000 --- a/src/test/java/ru/practicum/shareit/request/dto/ItemRequestDtoTest.java +++ /dev/null @@ -1,90 +0,0 @@ -package ru.practicum.shareit.request.dto; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import ru.practicum.shareit.booking.dto.BookingShortDto; -import ru.practicum.shareit.item.dto.CommentDto; -import ru.practicum.shareit.item.dto.ItemDto; - -import javax.validation.ConstraintViolation; -import javax.validation.Validation; -import javax.validation.Validator; -import javax.validation.ValidatorFactory; -import java.time.LocalDateTime; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -public class ItemRequestDtoTest { - - private final ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); - private final Validator validator = factory.getValidator(); - - @Test - public void testItemRequestDtoConstructorAndGetters() { - Long id = 1L; - String description = "Sample description"; - LocalDateTime created = LocalDateTime.now(); - - LocalDateTime now = LocalDateTime.now(); - Long id1 = 1L; - LocalDateTime start1 = now.plusHours(1); - LocalDateTime end1 = now.plusHours(2); - Long itemId1 = 100L; - Long bookerId1 = 200L; - - BookingShortDto booking1 = BookingShortDto.builder() - .id(id1) - .start(start1) - .end(end1) - .itemId(itemId1) - .bookerId(bookerId1) - .build(); - - Long id2 = 2L; - LocalDateTime start2 = now.plusDays(1); - LocalDateTime end2 = now.plusDays(1).plusHours(2); - Long itemId2 = 101L; - Long bookerId2 = 201L; - - BookingShortDto booking2 = BookingShortDto.builder() - .id(id2) - .start(start2) - .end(end2) - .itemId(itemId2) - .bookerId(bookerId2) - .build(); - - CommentDto commentDto = CommentDto.builder() - .id(1L) - .text("This is a comment.") - .authorName("John Doe") - .created(LocalDateTime.now()) - .build(); - - Collection items = Collections.singletonList(new ItemDto(1L, "Sample item", "Hello", - true, booking1, booking2, 1L, List.of(commentDto))); - - ItemRequestDto requestDto = new ItemRequestDto(id, description, created, items); - - Assertions.assertEquals(id, requestDto.getId(), "ID should be equal"); - Assertions.assertEquals(description, requestDto.getDescription(), "Description should be equal"); - Assertions.assertEquals(created, requestDto.getCreated(), "Created date should be equal"); - Assertions.assertEquals(items, requestDto.getItems(), "Items collection should be equal"); - } - - @Test - public void testItemRequestDtoValidation() { - ItemRequestDto requestDto = new ItemRequestDto(null, null, null, null); - - Set> violations = validator.validate(requestDto); - Assertions.assertEquals(2, violations.size(), "Two validation errors should be present"); - - ConstraintViolation violation = violations.iterator().next(); - String invalidProperty = violation.getPropertyPath().toString(); - Assertions.assertTrue(invalidProperty.contains("description") || invalidProperty.contains("id"), - "Invalid property should be 'description' or 'id'"); - } - -} diff --git a/src/test/java/ru/practicum/shareit/request/dto/ItemRequestMapperTest.java b/src/test/java/ru/practicum/shareit/request/dto/ItemRequestMapperTest.java deleted file mode 100644 index 74347d9..0000000 --- a/src/test/java/ru/practicum/shareit/request/dto/ItemRequestMapperTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package ru.practicum.shareit.request.dto; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import ru.practicum.shareit.item.dto.ItemDto; -import ru.practicum.shareit.request.model.ItemRequest; -import ru.practicum.shareit.user.model.User; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Collection; - -public class ItemRequestMapperTest { - - @Test - public void testToItemRequestDto() { - ItemRequest itemRequest = ItemRequest.builder() - .id(1L) - .description("Test item request") - .created(LocalDateTime.now()) - .build(); - - ItemRequestDto itemRequestDto = ItemRequestMapper.toItemRequestDto(itemRequest); - - Assertions.assertEquals(itemRequest.getId(), itemRequestDto.getId()); - Assertions.assertEquals(itemRequest.getDescription(), itemRequestDto.getDescription()); - Assertions.assertEquals(itemRequest.getCreated(), itemRequestDto.getCreated()); - } - - @Test - public void testToItemRequestDtoWithItems() { - ItemRequest itemRequest = ItemRequest.builder() - .id(1L) - .description("Test item request") - .created(LocalDateTime.now()) - .build(); - - Collection items = new ArrayList<>(); - items.add(ItemDto.builder().id(1L).name("Item 1").build()); - items.add(ItemDto.builder().id(2L).name("Item 2").build()); - - ItemRequestDto itemRequestDto = ItemRequestMapper.toItemRequestDtoWithItems(itemRequest, items); - - Assertions.assertEquals(itemRequest.getId(), itemRequestDto.getId()); - Assertions.assertEquals(itemRequest.getDescription(), itemRequestDto.getDescription()); - Assertions.assertEquals(itemRequest.getCreated(), itemRequestDto.getCreated()); - Assertions.assertEquals(items, itemRequestDto.getItems()); - } - - @Test - public void testToItemRequest() { - ItemRequestDto itemRequestDto = new ItemRequestDto(1L, "Test Description", LocalDateTime.now(), null); - - User requestor = User.builder() - .id(1L) - .name("John Doe") - .email("johndoe@example.com") - .build(); - - ItemRequest itemRequest = ItemRequestMapper.toItemRequest(itemRequestDto, requestor); - - Assertions.assertEquals(itemRequestDto.getId(), itemRequest.getId()); - Assertions.assertEquals(itemRequestDto.getDescription(), itemRequest.getDescription()); - Assertions.assertEquals(requestor, itemRequest.getRequestor()); - Assertions.assertEquals(itemRequestDto.getCreated(), itemRequest.getCreated()); - } -} diff --git a/src/test/java/ru/practicum/shareit/request/repository/ItemRequestRepositoryTest.java b/src/test/java/ru/practicum/shareit/request/repository/ItemRequestRepositoryTest.java deleted file mode 100644 index 66d8a80..0000000 --- a/src/test/java/ru/practicum/shareit/request/repository/ItemRequestRepositoryTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package ru.practicum.shareit.request.repository; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; -import org.springframework.data.domain.PageRequest; -import ru.practicum.shareit.item.model.Item; -import ru.practicum.shareit.request.model.ItemRequest; -import ru.practicum.shareit.user.model.User; - -import java.util.ArrayList; -import java.util.List; - -@DataJpaTest -@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) -class ItemRequestRepositoryTest { - @Autowired - private TestEntityManager testEntityManager; - - @Autowired - private ItemRequestRepository itemRequestRepository; - - @Test - void contextLoads() { - Assertions.assertNotNull(testEntityManager); - } - - private final List users = List.of( - User.builder().name("user1").email("user1@mail.ru").build(), - User.builder().name("user2").email("user2@mail.ru").build(), - User.builder().name("user3").email("user3@mail.ru").build()); - - private final List items = List.of( - Item.builder().name("item1").description("this is item1").available(true).build(), - Item.builder().name("item2").description("this is item2").available(true).build(), - Item.builder().name("item3").description("this is item3").available(true).build()); - - private final List requests = List.of( - ItemRequest.builder().description("this is request1").build(), - ItemRequest.builder().description("this is request2").build(), - ItemRequest.builder().description("this is request3").build()); - - @BeforeEach - public void installEntities() { - users.forEach(testEntityManager::persist); - - items.get(0).setOwner(users.get(0)); - items.get(1).setOwner(users.get(1)); - items.get(2).setOwner(users.get(1)); - items.forEach(testEntityManager::persist); - - requests.get(0).setRequestor(users.get(1)); - requests.get(1).setRequestor(users.get(2)); - requests.get(2).setRequestor(users.get(2)); - requests.forEach(testEntityManager::persist); - } - - @Test - void findAllByRequestor() { - List requestsByRequestor = new ArrayList<>(itemRequestRepository.findAllByRequestor(users.get(0))); - Assertions.assertEquals(0, requestsByRequestor.size()); - - requestsByRequestor = new ArrayList<>(itemRequestRepository.findAllByRequestor(users.get(1))); - Assertions.assertEquals(1, requestsByRequestor.size()); - Assertions.assertEquals("this is request1", requestsByRequestor.get(0).getDescription()); - - requestsByRequestor = new ArrayList<>(itemRequestRepository.findAllByRequestor(users.get(2))); - Assertions.assertEquals(2, requestsByRequestor.size()); - Assertions.assertEquals("this is request3", requestsByRequestor.get(1).getDescription()); - } - - @Test - void findAllByRequestorIdNot() { - List requestsByRequestor = itemRequestRepository.findAllByRequestorIdNot(users.get(0).getId(), PageRequest.of(0, 3)).toList(); - Assertions.assertEquals(3, requestsByRequestor.size()); - Assertions.assertEquals("this is request2", requestsByRequestor.get(1).getDescription()); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/request/service/IntegrationItemRequestServiceImplTest.java b/src/test/java/ru/practicum/shareit/request/service/IntegrationItemRequestServiceImplTest.java deleted file mode 100644 index d275ea9..0000000 --- a/src/test/java/ru/practicum/shareit/request/service/IntegrationItemRequestServiceImplTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package ru.practicum.shareit.request.service; - -import lombok.RequiredArgsConstructor; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; -import ru.practicum.shareit.item.model.Item; -import ru.practicum.shareit.request.dto.ItemRequestDto; -import ru.practicum.shareit.request.model.ItemRequest; -import ru.practicum.shareit.user.model.User; - -import javax.persistence.EntityManager; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.List; -import java.util.stream.Collectors; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; - -@Transactional -@SpringBootTest( - properties = "db.name=test", - webEnvironment = SpringBootTest.WebEnvironment.NONE) -@RequiredArgsConstructor(onConstructor_ = @Autowired) -class IntegrationItemRequestServiceImplTest { - private final EntityManager em; - private final ItemRequestService itemRequestService; - - private final List users = List.of( - User.builder().name("user1").email("user1@mail.ru").build(), - User.builder().name("user2").email("user2@mail.ru").build(), - User.builder().name("user3").email("user3@mail.ru").build()); - - private final List items = List.of( - Item.builder().name("item1").description("this is item1").available(true).build(), - Item.builder().name("item2").description("this is item2").available(true).build(), - Item.builder().name("item3").description("this is item3").available(true).build()); - - private final List requests = List.of( - ItemRequest.builder().description("this is request1").build(), - ItemRequest.builder().description("this is request2").build(), - ItemRequest.builder().description("this is request3").build()); - - @BeforeEach - public void installEntities() { - users.forEach(em::persist); - - items.get(0).setOwner(users.get(0)); - items.get(1).setOwner(users.get(1)); - items.get(2).setOwner(users.get(1)); - items.forEach(em::persist); - - requests.get(0).setRequestor(users.get(1)); - requests.get(1).setRequestor(users.get(2)); - requests.get(2).setRequestor(users.get(2)); - requests.forEach(em::persist); - } - - @Test - void getItemRequests() { - List serviceItemRequests = new ArrayList<>(itemRequestService.getItemRequests(users.get(2).getId())); - - assertThat(serviceItemRequests, hasSize(2)); - - for (int i = 0; i < serviceItemRequests.size(); i++) { - assertThat(serviceItemRequests.get(i).getId(), notNullValue()); - assertThat(serviceItemRequests.get(i).getDescription(), equalTo(requests.get(i + 1).getDescription())); - } - } - - @Test - void getOtherItemRequests() { - List serviceItemRequests = new ArrayList<>(itemRequestService.getOtherItemRequests(users.get(0).getId(), 0L, 5L)); - - assertThat(serviceItemRequests, hasSize(3)); - - List sortedRequests = requests.stream() - .sorted(Comparator.comparing(ItemRequest::getCreated).reversed()) - .collect(Collectors.toList()); - - for (int i = 0; i < serviceItemRequests.size(); i++) { - assertThat(serviceItemRequests.get(i).getId(), notNullValue()); - assertThat(serviceItemRequests.get(i).getDescription(), equalTo(sortedRequests.get(i).getDescription())); - } - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/request/service/ItemRequestServiceImplTest.java b/src/test/java/ru/practicum/shareit/request/service/ItemRequestServiceImplTest.java deleted file mode 100644 index b89e9f1..0000000 --- a/src/test/java/ru/practicum/shareit/request/service/ItemRequestServiceImplTest.java +++ /dev/null @@ -1,141 +0,0 @@ -package ru.practicum.shareit.request.service; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; -import ru.practicum.shareit.error.ItemRequestNotFoundException; -import ru.practicum.shareit.error.UserNotFoundException; -import ru.practicum.shareit.item.model.Item; -import ru.practicum.shareit.item.repository.ItemRepository; -import ru.practicum.shareit.request.dto.ItemRequestDto; -import ru.practicum.shareit.request.dto.ItemRequestMapper; -import ru.practicum.shareit.request.model.ItemRequest; -import ru.practicum.shareit.request.repository.ItemRequestRepository; -import ru.practicum.shareit.request.service.impl.ItemRequestServiceImpl; -import ru.practicum.shareit.user.model.User; -import ru.practicum.shareit.user.repository.UserRepository; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class ItemRequestServiceImplTest { - - ItemRequestService itemRequestService; - - private final List users = List.of( - User.builder().id(1L).name("user1").email("user1@mail.ru").build(), - User.builder().id(2L).name("user2").email("user2@mail.ru").build(), - User.builder().id(3L).name("user3").email("user3@mail.ru").build()); - - private final List items = List.of( - Item.builder() - .id(1L) - .name("item1") - .description("this is item1") - .available(true) - .owner(users.get(0)) - .build(), - Item.builder() - .id(2L) - .name("item2") - .description("this is item2") - .available(false) - .owner(users.get(1)) - .build(), - Item.builder() - .id(3L) - .name("item3") - .description("this is item3") - .available(true) - .owner(users.get(1)) - .build() - ); - - private final List requests = List.of( - ItemRequest.builder() - .id(1L) - .description("this is request1") - .requestor(users.get(0)) - .created(LocalDateTime.now()) - .build(), - ItemRequest.builder() - .id(2L) - .description("this is request2") - .requestor(users.get(1)) - .created(LocalDateTime.now()) - .build(), - ItemRequest.builder() - .id(3L) - .description("this is request3") - .requestor(users.get(2)) - .created(LocalDateTime.now()) - .build()); - - @BeforeEach - public void installService() { - ItemRepository itemRepository = Mockito.mock(ItemRepository.class); - UserRepository userRepository = Mockito.mock(UserRepository.class); - ItemRequestRepository itemRequestRepository = Mockito.mock(ItemRequestRepository.class); - - for (int i = 0; i < 3; i++) { - Mockito.when(itemRepository.findById(items.get(i).getId())) - .thenReturn(Optional.of(items.get(i))); - - Mockito.when(itemRepository.save(items.get(i))) - .thenReturn(items.get(i)); - - Mockito.when(userRepository.findById(users.get(i).getId())) - .thenReturn(Optional.of(users.get(i))); - - Mockito.when(itemRequestRepository.findById(requests.get(i).getId())) - .thenReturn(Optional.of(requests.get(i))); - - Mockito.when(itemRequestRepository.save(requests.get(i))) - .thenReturn(requests.get(i)); - } - - Mockito.when(itemRepository.findById(4L)) - .thenReturn(Optional.empty()); - - Mockito.when(userRepository.findById(4L)) - .thenReturn(Optional.empty()); - - items.get(0).setRequest(requests.get(0)); - - itemRequestService = new ItemRequestServiceImpl( - itemRequestRepository, - userRepository, - itemRepository); - } - - @Test - void addItemRequest() { - UserNotFoundException userNotFoundException = Assertions.assertThrows( - UserNotFoundException.class, - () -> itemRequestService.addItemRequest(ItemRequestMapper.toItemRequestDto(requests.get(0)), 4L)); - - assertEquals("Пользователь 4 не найден", userNotFoundException.getMessage()); - } - - @Test - void getItemRequest() { - UserNotFoundException userNotFoundException = Assertions.assertThrows( - UserNotFoundException.class, - () -> itemRequestService.getItemRequest(4L, requests.get(0).getId())); - - assertEquals("Пользователь 4 не найден", userNotFoundException.getMessage()); - - ItemRequestNotFoundException itemRequestNotFoundException = Assertions.assertThrows( - ItemRequestNotFoundException.class, - () -> itemRequestService.getItemRequest(users.get(0).getId(), 4L)); - - assertEquals("Запрос 4 не найден", itemRequestNotFoundException.getMessage()); - - ItemRequestDto itemRequestDto = itemRequestService.getItemRequest(users.get(0).getId(), requests.get(0).getId()); - assertEquals(requests.get(0).getId(), itemRequestDto.getId()); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/user/controller/UserControllerTest.java b/src/test/java/ru/practicum/shareit/user/controller/UserControllerTest.java deleted file mode 100644 index e8910af..0000000 --- a/src/test/java/ru/practicum/shareit/user/controller/UserControllerTest.java +++ /dev/null @@ -1,139 +0,0 @@ -package ru.practicum.shareit.user.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; -import ru.practicum.shareit.user.dto.UserDto; -import ru.practicum.shareit.user.service.UserService; - -import java.nio.charset.StandardCharsets; -import java.util.List; - -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@WebMvcTest(controllers = UserController.class) -class UserControllerTest { - - @Autowired - ObjectMapper mapper; - - @MockBean - UserService userService; - - @Autowired - private MockMvc mvc; - - private final List users = List.of( - UserDto.builder().id(1L).name("user1").email("user@email.com").build(), - UserDto.builder().id(2L).name("user2").email("mail").build(), - UserDto.builder().id(3L).email("user@email.com").build() - ); - - @Test - void createUser() throws Exception { - when(userService.createUser(any())) - .thenReturn(users.get(0)); - - mvc.perform(post("/users") - .content(mapper.writeValueAsString(users.get(0))) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id", is(users.get(0).getId()), Long.class)) - .andExpect(jsonPath("$.name", is(users.get(0).getName()))) - .andExpect(jsonPath("$.email", is(users.get(0).getEmail()))); - - mvc.perform(post("/users") - .content(mapper.writeValueAsString(users.get(1))) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - - mvc.perform(post("/users") - .content(mapper.writeValueAsString(users.get(2))) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - - @Test - void getUser() throws Exception { - when(userService.getUser(anyLong())) - .thenReturn(users.get(0)); - - mvc.perform(get("/users/0")) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id", is(users.get(0).getId()), Long.class)) - .andExpect(jsonPath("$.name", is(users.get(0).getName()))) - .andExpect(jsonPath("$.email", is(users.get(0).getEmail()))); - } - - @Test - void getAllUsers() throws Exception { - when(userService.getAllUsers()) - .thenReturn(users); - - mvc.perform(get("/users")) - .andExpect(status().isOk()) - .andExpect(jsonPath("$", hasSize(3))) - .andExpect(jsonPath("$[0].id", is(users.get(0).getId()), Long.class)) - .andExpect(jsonPath("$[0].name", is(users.get(0).getName()))) - .andExpect(jsonPath("$[0].email", is(users.get(0).getEmail()))); - } - - @Test - void updateUser() throws Exception { - when(userService.updateUser(anyLong(), any())) - .thenReturn(users.get(0)); - - UserDto userUpdate = UserDto.builder().name("updated user1").email("user@email.com").build(); - - mvc.perform(patch("/users/0") - .content(mapper.writeValueAsString(userUpdate)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id", is(users.get(0).getId()), Long.class)) - .andExpect(jsonPath("$.name", is(users.get(0).getName()))) - .andExpect(jsonPath("$.email", is(userUpdate.getEmail()))); - - userUpdate = UserDto.builder().email("").build(); - - mvc.perform(patch("/users/0") - .content(mapper.writeValueAsString(userUpdate)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - - userUpdate = UserDto.builder().name("").build(); - - mvc.perform(patch("/users/0") - .content(mapper.writeValueAsString(userUpdate)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - - @Test - void deleteUser() throws Exception { - mvc.perform(delete("/users/0")) - .andExpect(status().isOk()); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/user/dto/UserDtoTest.java b/src/test/java/ru/practicum/shareit/user/dto/UserDtoTest.java deleted file mode 100644 index e6818de..0000000 --- a/src/test/java/ru/practicum/shareit/user/dto/UserDtoTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package ru.practicum.shareit.user.dto; - -import org.junit.jupiter.api.Test; - -import javax.validation.ConstraintViolation; -import javax.validation.Validation; -import javax.validation.Validator; -import javax.validation.ValidatorFactory; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.*; - -public class UserDtoTest { - private final Validator validator; - - public UserDtoTest() { - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); - validator = factory.getValidator(); - } - - @Test - public void testValidUserDto() { - UserDto userDto = UserDto.builder() - .id(1L) - .name("John Doe") - .email("johndoe@example.com") - .build(); - - Set> violations = validator.validate(userDto); - - assertTrue(violations.isEmpty()); - } -} diff --git a/src/test/java/ru/practicum/shareit/user/repository/UserRepositoryTest.java b/src/test/java/ru/practicum/shareit/user/repository/UserRepositoryTest.java deleted file mode 100644 index ee2b162..0000000 --- a/src/test/java/ru/practicum/shareit/user/repository/UserRepositoryTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package ru.practicum.shareit.user.repository; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager; -import ru.practicum.shareit.user.model.User; - -@DataJpaTest -@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) -class UserRepositoryTest { - - @Autowired - private TestEntityManager testEntityManager; - - @Autowired - private UserRepository userRepository; - - @Test - void contextLoads() { - Assertions.assertNotNull(testEntityManager); - } - - @Test - void findByEmail() { - User user = User.builder() - .name("user") - .email("user@mail.ru") - .build(); - - Assertions.assertNull(user.getId()); - testEntityManager.persist(user); - Assertions.assertNotNull(user.getId()); - Assertions.assertTrue(userRepository.findByEmail("unknown@mail.ru").isEmpty()); - Assertions.assertTrue(userRepository.findByEmail("user@mail.ru").isPresent()); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/user/service/UserServiceImplTest.java b/src/test/java/ru/practicum/shareit/user/service/UserServiceImplTest.java deleted file mode 100644 index 75ef2e5..0000000 --- a/src/test/java/ru/practicum/shareit/user/service/UserServiceImplTest.java +++ /dev/null @@ -1,108 +0,0 @@ -package ru.practicum.shareit.user.service; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; -import ru.practicum.shareit.error.UserNotFoundException; -import ru.practicum.shareit.user.dto.UserDto; -import ru.practicum.shareit.user.dto.UserMapper; -import ru.practicum.shareit.user.model.User; -import ru.practicum.shareit.user.repository.UserRepository; -import ru.practicum.shareit.user.service.impl.UserServiceImpl; - -import java.util.Collection; -import java.util.List; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.ArgumentMatchers.any; - -class UserServiceImplTest { - - UserService userService; - private final List users = List.of( - User.builder().id(1L).name("user1").email("user1@mail.ru").build(), - User.builder().id(2L).name("user2").email("user2@mail.ru").build(), - User.builder().id(3L).name("user3").email("user3@mail.ru").build()); - - @BeforeEach - public void installService() { - UserRepository userRepository = Mockito.mock(UserRepository.class); - - for (int i = 0; i < 3; i++) { - Mockito.when(userRepository.findById(users.get(i).getId())) - .thenReturn(Optional.of(users.get(i))); - - Mockito.when(userRepository.save(users.get(i))) - .thenReturn(users.get(i)); - } - - Mockito.when(userRepository.findAll()) - .thenReturn(users); - - Mockito.when(userRepository.findById(4L)) - .thenReturn(Optional.empty()); - - userService = new UserServiceImpl(userRepository); - } - - @Test - void createUser() { - UserDto userDto = UserMapper.toUserDto(users.get(0)); - assertEquals(users.get(0).getId(), userDto.getId()); - } - - @Test - void getUser() { - UserNotFoundException userNotFoundException = Assertions.assertThrows( - UserNotFoundException.class, - () -> userService.getUser(4L)); - - assertEquals("Пользователь 4 не существует", userNotFoundException.getMessage()); - - UserDto userDto = userService.getUser(users.get(0).getId()); - assertEquals(users.get(0).getId(), userDto.getId()); - } - - @Test - void getAllUsers() { - Collection userDtos = userService.getAllUsers(); - assertEquals(users.size(), userDtos.size()); - } - - @Test - void updateUser() { - User updatedUser = User.builder() - .id(users.get(0).getId()) - .name(users.get(1).getName()) - .email(users.get(1).getEmail()) - .build(); - - UserRepository userRepository = Mockito.mock(UserRepository.class); - - Mockito.when(userRepository.save(any())) - .thenReturn(updatedUser); - - Mockito.when(userRepository.findById(users.get(0).getId())) - .thenReturn(Optional.of(users.get(0))); - - userService = new UserServiceImpl(userRepository); - - UserDto userDto = userService.updateUser(users.get(0).getId(), UserMapper.toUserDto(users.get(1))); - assertEquals(users.get(0).getId(), userDto.getId()); - assertEquals(users.get(1).getName(), userDto.getName()); - } - - @Test - void deleteUser() { - UserNotFoundException userNotFoundException = Assertions.assertThrows( - UserNotFoundException.class, - () -> userService.deleteUser(4L)); - - assertEquals("Пользователь 4 не существует", userNotFoundException.getMessage()); - - UserDto userDto = userService.deleteUser(users.get(0).getId()); - assertEquals(users.get(0).getId(), userDto.getId()); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/validation/PagingParametersCheckerTest.java b/src/test/java/ru/practicum/shareit/validation/PagingParametersCheckerTest.java deleted file mode 100644 index a41a0a3..0000000 --- a/src/test/java/ru/practicum/shareit/validation/PagingParametersCheckerTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package ru.practicum.shareit.validation; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class PagingParametersCheckerTest { - - @Test - public void testCheckValidParameters() { - Assertions.assertDoesNotThrow(() -> PagingParametersChecker.check(10L, 20L)); - } - - @Test - public void testCheckNegativeFromParameter() { - Assertions.assertThrows(IllegalArgumentException.class, - () -> PagingParametersChecker.check(-5L, 20L)); - } - - @Test - public void testCheckZeroSizeParameter() { - Assertions.assertThrows(IllegalArgumentException.class, - () -> PagingParametersChecker.check(10L, 0L)); - } - - @Test - public void testCheckNegativeFromAndZeroSizeParameters() { - Assertions.assertThrows(IllegalArgumentException.class, - () -> PagingParametersChecker.check(-5L, 0L)); - } -} From 67537714a2b162cc6f15a64679f107767564ea55 Mon Sep 17 00:00:00 2001 From: boltaevt Date: Sat, 24 Jun 2023 23:19:21 +0500 Subject: [PATCH 2/7] changes --- postman/sprint.json | 11050 ------------------------------------------ 1 file changed, 11050 deletions(-) delete mode 100644 postman/sprint.json diff --git a/postman/sprint.json b/postman/sprint.json deleted file mode 100644 index cef1cb0..0000000 --- a/postman/sprint.json +++ /dev/null @@ -1,11050 +0,0 @@ -{ - "info": { - "_postman_id": "02b3b696-d51d-4750-b4dc-35e6712fd023", - "name": "Sprint 16 ShareIt (add-docker)", - "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", - "_exporter_id": "2036415" - }, - "item": [ - { - "name": "users", - "item": [ - { - "name": "User 1 create", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has user create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test user 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test user 'email' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('email');", - " pm.expect(jsonData.email, '\"email\" must be \"user@user.com\"').to.eql('user@user.com');", - "});", - "pm.test(\"Test user 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"user\"').to.eql('user');", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"user\",\n \"email\": \"user@user.com\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/users", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users" - ] - } - }, - "response": [] - }, - { - "name": "User 2 create fail duplicate email", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 409\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([409, 500]);", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"user\",\n \"email\": \"user@user.com\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/users", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users" - ] - } - }, - "response": [] - }, - { - "name": "User create fail no email", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"user\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/users", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users" - ] - } - }, - "response": [] - }, - { - "name": "User create fail invalid email", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"user\",\n \"email\": \"user.com\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/users", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users" - ] - } - }, - "response": [] - }, - { - "name": "User 1 update", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has user update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test user 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test user 'email' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('email');", - " pm.expect(jsonData.email, '\"email\" must be \"update@user.com\"').to.eql('update@user.com');", - "});", - "pm.test(\"Test user 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"update\"').to.eql('update');", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"update\",\n \"email\": \"update@user.com\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/users/:userId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users", - ":userId" - ], - "variable": [ - { - "key": "userId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "User 3 create", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has user create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test user 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 3').to.eql(3);", - "});", - "pm.test(\"Test user 'email' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('email');", - " pm.expect(jsonData.email, '\"email\" must be \"user@user.com\"').to.eql('user@user.com');", - "});", - "pm.test(\"Test user 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"user\"').to.eql('user');", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"user\",\n \"email\": \"user@user.com\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/users", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users" - ] - } - }, - "response": [] - }, - { - "name": "User 1 update name", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has user update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test user 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test user 'email' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('email');", - " pm.expect(jsonData.email, '\"email\" must be \"update@user.com\"').to.eql('update@user.com');", - "});", - "pm.test(\"Test user 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"updateName\"').to.eql('updateName');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"updateName\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/users/:userId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users", - ":userId" - ], - "variable": [ - { - "key": "userId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "User 1 update email", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has user update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test user 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test user 'email' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('email');", - " pm.expect(jsonData.email, '\"email\" must be \"updateName@user.com\"').to.eql('updateName@user.com');", - "});", - "pm.test(\"Test user 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"updateName\"').to.eql('updateName');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"email\": \"updateName@user.com\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/users/:userId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users", - ":userId" - ], - "variable": [ - { - "key": "userId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "User 1 update with same email", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has user update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test user 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test user 'email' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('email');", - " pm.expect(jsonData.email, '\"email\" must be \"updateName@user.com\"').to.eql('updateName@user.com');", - "});", - "pm.test(\"Test user 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"updateName\"').to.eql('updateName');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"email\": \"updateName@user.com\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/users/:userId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users", - ":userId" - ], - "variable": [ - { - "key": "userId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "User 1 name update fail email exists", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 409\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([409, 500]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"email\": \"user@user.com\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/users/:userId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users", - ":userId" - ], - "variable": [ - { - "key": "userId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "User 1 get updated", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has user update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test user 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test user 'email' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('email');", - " pm.expect(jsonData.email, '\"email\" must be \"updateName@user.com\"').to.eql('updateName@user.com');", - "});", - "pm.test(\"Test user 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"updateName\"').to.eql('updateName');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/users/:userId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users", - ":userId" - ], - "variable": [ - { - "key": "userId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "User 3 get", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has user update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test user 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 3').to.eql(3);", - "});", - "pm.test(\"Test user 'email' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('email');", - " pm.expect(jsonData.email, '\"email\" must be \"user@user.com\"').to.eql('user@user.com');", - "});", - "pm.test(\"Test user 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"user\"').to.eql('user');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/users/:userId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users", - ":userId" - ], - "variable": [ - { - "key": "userId", - "value": "3" - } - ] - } - }, - "response": [] - }, - { - "name": "User 100 get unkonwn", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 404\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([404]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/users/:userId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users", - ":userId" - ], - "variable": [ - { - "key": "userId", - "value": "100" - } - ] - } - }, - "response": [] - }, - { - "name": "User 3 delete", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,204]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "DELETE", - "header": [ - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/users/:userId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users", - ":userId" - ], - "variable": [ - { - "key": "userId", - "value": "3" - } - ] - } - }, - "response": [] - }, - { - "name": "User 4 create after delete", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has user create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test user 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 4').to.eql(4);", - "});", - "pm.test(\"Test user 'email' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('email');", - " pm.expect(jsonData.email, '\"email\" must be \"user@user.com\"').to.eql('user@user.com');", - "});", - "pm.test(\"Test user 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"user\"').to.eql('user');", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"user\",\n \"email\": \"user@user.com\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/users", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users" - ] - } - }, - "response": [] - }, - { - "name": "User get all", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list user response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", - "});", - "", - "pm.test(\"Test user[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test user[0] 'email' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('email');", - " pm.expect(jsonData[0].email, '\"email\" must be \"updateName@user.com\"').to.eql('updateName@user.com');", - "});", - "pm.test(\"Test user[0] 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('name');", - " pm.expect(jsonData[0].name, '\"name\" must be \"updateName\"').to.eql('updateName');", - "});", - "", - "pm.test(\"Test user[1] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('id');", - " pm.expect(jsonData[1].id, '\"id\" must be 4').to.eql(4);", - "});", - "pm.test(\"Test user[1] 'email' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('email');", - " pm.expect(jsonData[1].email, '\"email\" must be \"user@user.com\"').to.eql('user@user.com');", - "});", - "pm.test(\"Test user[1] 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('name');", - " pm.expect(jsonData[1].name, '\"name\" must be \"user\"').to.eql('user');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/users", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users" - ] - } - }, - "response": [] - } - ] - }, - { - "name": "items", - "item": [ - { - "name": "Item 1 create by user 1", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has item create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Дрель\"').to.eql('Дрель');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Простая дрель\"').to.eql('Простая дрель');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"Дрель\",\n \"description\": \"Простая дрель\",\n \"available\": true\n}" - }, - "url": { - "raw": "{{baseUrl}}/items", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items" - ] - } - }, - "response": [] - }, - { - "name": "Item create without X-Sharer-User-Id", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 500\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500, 400]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text", - "disabled": true - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"Дрель\",\n \"description\": \"Простая дрель\",\n \"available\": true\n}" - }, - "url": { - "raw": "{{baseUrl}}/items", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items" - ] - } - }, - "response": [] - }, - { - "name": "Item create with not found user", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 404\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([404,403]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "10", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"Дрель\",\n \"description\": \"Простая дрель\",\n \"available\": true\n}" - }, - "url": { - "raw": "{{baseUrl}}/items", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items" - ] - } - }, - "response": [] - }, - { - "name": "Item create without available", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "3", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"Отвертка\",\n \"description\": \"Аккумуляторная отвертка\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/items", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items" - ] - } - }, - "response": [] - }, - { - "name": "Item create with empty name", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "3", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"\",\n \"description\": \"Аккумуляторная отвертка\",\n \"available\": true\n}" - }, - "url": { - "raw": "{{baseUrl}}/items", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items" - ] - } - }, - "response": [] - }, - { - "name": "Item create with empty description", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "3", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"Отвертка\",\n \"available\": true\n}" - }, - "url": { - "raw": "{{baseUrl}}/items", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items" - ] - } - }, - "response": [] - }, - { - "name": "item 1 update", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Дрель+\"').to.eql('Дрель+');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"false\"').to.false;", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"id\": 1,\n \"name\": \"Дрель+\",\n \"description\": \"Аккумуляторная дрель\",\n \"available\": false\n}" - }, - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "item 1 update without X-Sharer-User-Id", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 500\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500, 400]);", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text", - "disabled": true - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"id\": 1,\n \"name\": \"Дрель\",\n \"description\": \"Простая дрель\",\n \"available\": false\n}" - }, - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "item 1 update with other user 3", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 404\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500, 404, 403]);", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "3", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"Дрель\",\n \"description\": \"Простая дрель\",\n \"available\": false\n}" - }, - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "item 1 update available", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Дрель+\"').to.eql('Дрель+');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"available\": true\n}" - }, - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "item 1 update description", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Дрель+\"').to.eql('Дрель+');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"description\": \"Аккумуляторная дрель + аккумулятор\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "item 1 update name", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "", - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"Аккумуляторная дрель\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "Item 1 get from owner user 1", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "", - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "Item 1 get from user 4", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200]);", - "});", - "pm.test(\"Test get item\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.id, '\"id\" field').to.eql(1);", - " pm.expect(jsonData.name, '\"name\" field').to.eql('Аккумуляторная дрель');", - " pm.expect(jsonData.description, '\"description\" field').to.eql('Аккумуляторная дрель + аккумулятор');", - " pm.expect(jsonData.available, '\"available\" field').to.true;", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "Item 100 get from user 4", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 404\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([404]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "100" - } - ] - } - }, - "response": [] - }, - { - "name": "Item 2 create by user 4", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has item create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"Отвертка\",\n \"description\": \"Аккумуляторная отвертка\",\n \"available\": true\n}" - }, - "url": { - "raw": "{{baseUrl}}/items", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items" - ] - } - }, - "response": [] - }, - { - "name": "Item 3 create by user 4", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has item create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 3').to.eql(3);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Клей Момент\"').to.eql('Клей Момент');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Тюбик суперклея марки Момент\"').to.eql('Тюбик суперклея марки Момент');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"Клей Момент\",\n \"description\": \"Тюбик суперклея марки Момент\",\n \"available\": true\n}" - }, - "url": { - "raw": "{{baseUrl}}/items", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items" - ] - } - }, - "response": [] - }, - { - "name": "Item get all user 1", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list item response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", - "});", - "", - "pm.test(\"Test item[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item[0] 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('name');", - " pm.expect(jsonData[0].name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", - "});", - "pm.test(\"Test item[0] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('description');", - " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", - "});", - "pm.test(\"Test item[0] 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('available');", - " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items" - ] - } - }, - "response": [] - }, - { - "name": "Item get all user 4", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list item response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", - "});", - "", - "pm.test(\"Test item[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test item[0] 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('name');", - " pm.expect(jsonData[0].name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "pm.test(\"Test item[0] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('description');", - " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", - "});", - "pm.test(\"Test item[0] 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('available');", - " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", - "});", - "", - "", - "pm.test(\"Test item[1] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('id');", - " pm.expect(jsonData[1].id, '\"id\" must be 3').to.eql(3);", - "});", - "pm.test(\"Test item[1] 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('name');", - " pm.expect(jsonData[1].name, '\"name\" must be \"Клей Момент\"').to.eql('Клей Момент');", - "});", - "pm.test(\"Test item[1] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('description');", - " pm.expect(jsonData[1].description, '\"description\" must be \"Тюбик суперклея марки Момент\"').to.eql('Тюбик суперклея марки Момент');", - "});", - "pm.test(\"Test item[1] 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('available');", - " pm.expect(jsonData[1].available, '\"available\" must be \"true\"').to.true;", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items" - ] - } - }, - "response": [] - }, - { - "name": "Item search аккумуляторная", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list item response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", - "});", - "", - "pm.test(\"Test item[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item[0] 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('name');", - " pm.expect(jsonData[0].name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", - "});", - "pm.test(\"Test item[0] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('description');", - " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", - "});", - "pm.test(\"Test item[0] 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('available');", - " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", - "});", - "", - "pm.test(\"Test item[1] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('id');", - " pm.expect(jsonData[1].id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test item[1] 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('name');", - " pm.expect(jsonData[1].name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "pm.test(\"Test item[1] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('description');", - " pm.expect(jsonData[1].description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", - "});", - "pm.test(\"Test item[1] 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('available');", - " pm.expect(jsonData[1].available, '\"available\" must be \"true\"').to.true;", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/search?text=аккУМУляторная", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - "search" - ], - "query": [ - { - "key": "text", - "value": "аккУМУляторная" - } - ] - } - }, - "response": [] - }, - { - "name": "item 2 update set unavailable", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"false\"').to.false;", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"available\": false\n}" - }, - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Item search дрель", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test search item response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", - "});", - "", - "pm.test(\"Test item[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item[0] 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('name');", - " pm.expect(jsonData[0].name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", - "});", - "pm.test(\"Test item[0] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('description');", - " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", - "});", - "pm.test(\"Test item[0] 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('available');", - " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/search?text=дРелЬ", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - "search" - ], - "query": [ - { - "key": "text", - "value": "дРелЬ" - } - ] - } - }, - "response": [] - }, - { - "name": "Item search аккумуляторная available", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test search item response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", - "});", - "", - "pm.test(\"Test item[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item[0] 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('name');", - " pm.expect(jsonData[0].name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", - "});", - "pm.test(\"Test item[0] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('description');", - " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", - "});", - "pm.test(\"Test item[0] 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('available');", - " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/search?text=аккУМУляторная", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - "search" - ], - "query": [ - { - "key": "text", - "value": "аккУМУляторная" - } - ] - } - }, - "response": [] - }, - { - "name": "item 2 update set available", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"available\": true\n}" - }, - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Item search отвертка", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test search item response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", - "});", - "pm.test(\"Test item[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test item[0] 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('name');", - " pm.expect(jsonData[0].name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "pm.test(\"Test item[0] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('description');", - " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", - "});", - "pm.test(\"Test item[0] 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('available');", - " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/search?text=оТверТ", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - "search" - ], - "query": [ - { - "key": "text", - "value": "оТверТ" - } - ] - } - }, - "response": [] - }, - { - "name": "Item search empty", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test search item response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 0').to.eql(0);", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/search?text=", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - "search" - ], - "query": [ - { - "key": "text", - "value": "" - } - ] - } - }, - "response": [] - } - ] - }, - { - "name": "bookings", - "item": [ - { - "name": "item 2 update set unavailable", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"false\"').to.false;", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"available\": false\n}" - }, - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking create from user1 to item2 unavailable", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(1, 'd');\r", - "var end = moment().add(2, 'd');\r", - "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "item 2 update set available", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"available\": true\n}" - }, - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking create failed by wrong userId", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 500\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500, 404, 403]);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(1, 'd');\r", - "var end = moment().add(2, 'd');\r", - "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "100", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking create failed by not found itemId", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 404\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([404]);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(1, 'd');\r", - "var end = moment().add(2, 'd');\r", - "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 200,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking create failed by end in past", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(1, 'd');\r", - "var end = moment().add(-1, 'd');\r", - "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking create failed by end before start", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(2, 'd');\r", - "var end = moment().add(1, 'd');\r", - "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking create failed by start equal end", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(2, 'd');\r", - "pm.environment.set('start_equal_end', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start_equal_end}}\",\n \"end\": \"{{start_equal_end}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking create failed by start equal null", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(2, 'd');\r", - "pm.environment.set('start_null', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 2,\n \"end\": \"{{start_null}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking create failed by end equal null", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(2, 'd');\r", - "pm.environment.set('end_null', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 2,\n \"start\": \"{{end_null}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking create failed by start in past", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(-1, 'd');\r", - "var end = moment().add(1, 'd');\r", - "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking 1 create from user 1 to item 2 current", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has booking create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(3, 's');\r", - "var end = moment().add(4, 's')\r", - "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking set approve by owner current", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200]);", - "});", - "pm.test(\"Has booking patch response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - ":bookingId" - ], - "query": [ - { - "key": "approved", - "value": "true" - } - ], - "variable": [ - { - "key": "bookingId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking 2 create from user 1 to item 2", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has booking create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(1, 'd');\r", - "var end = moment().add(2, 'd');\r", - "pm.environment.set('start2', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "pm.environment.set('end2', end.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start2}}\",\n \"end\": \"{{end2}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking 2 get by user 1 (booker)", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200]);", - "});", - "pm.test(\"Has booking get response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/:bookingId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - ":bookingId" - ], - "variable": [ - { - "key": "bookingId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking 2 get by user 4 (owner)", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200]);", - "});", - "pm.test(\"Has booking get response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/:bookingId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - ":bookingId" - ], - "variable": [ - { - "key": "bookingId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for wrong user 100", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 500\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500,404,403]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "100", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - "" - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for wrong owner user 100", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 500\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500,404,403]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "100", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/owner", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - "owner" - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for user 1", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list booking response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", - "});", - "", - "pm.test(\"Test booking[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test booking[0] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('start');", - " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('end');", - " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", - "});", - "pm.test(\"Test booking[0] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('status');", - " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('booker');", - " pm.expect(jsonData[0].booker).to.have.property('id');", - " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[0] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('id');", - " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking[0] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('name');", - " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "", - "pm.test(\"Test booking[1] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('id');", - " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test booking[1] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('start');", - " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", - "});", - "pm.test(\"Test booking[1] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('end');", - " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", - "});", - "pm.test(\"Test booking[1] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('status');", - " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking[1] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('booker');", - " pm.expect(jsonData[1].booker).to.have.property('id');", - " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[1] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('id');", - " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking[1] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('name');", - " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for user 1 by ALL state", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list booking response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", - "});", - "", - "pm.test(\"Test booking[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test booking[0] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('start');", - " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('end');", - " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", - "});", - "pm.test(\"Test booking[0] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('status');", - " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('booker');", - " pm.expect(jsonData[0].booker).to.have.property('id');", - " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[0] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('id');", - " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking[0] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('name');", - " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "", - "pm.test(\"Test booking[1] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('id');", - " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test booking[1] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('start');", - " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", - "});", - "pm.test(\"Test booking[1] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('end');", - " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", - "});", - "pm.test(\"Test booking[1] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('status');", - " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking[1] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('booker');", - " pm.expect(jsonData[1].booker).to.have.property('id');", - " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[1] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('id');", - " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking[1] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('name');", - " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings?state=ALL", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ], - "query": [ - { - "key": "state", - "value": "ALL" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for user 1 by FUTURE state", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list booking response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", - "});", - "", - "pm.test(\"Test booking[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test booking[0] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('start');", - " pm.expect(new Date(jsonData[0].start), '\"start\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", - "", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('end');", - " pm.expect(new Date(jsonData[0].end), '\"end\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", - "});", - "pm.test(\"Test booking[0] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('status');", - " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('booker');", - " pm.expect(jsonData[0].booker).to.have.property('id');", - " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[0] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('id');", - " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking[0] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('name');", - " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "", - "pm.test(\"Test booking[1] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('id');", - " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test booking[1] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('start');", - "});", - "pm.test(\"Test booking[1] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('end');", - "});", - "pm.test(\"Test booking[1] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('start');", - " pm.expect(new Date(jsonData[1].start), '\"start\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", - "", - "});", - "pm.test(\"Test booking[1] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('end');", - " pm.expect(new Date(jsonData[1].end), '\"end\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", - "});", - "pm.test(\"Test booking[1] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('status');", - " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking[1] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('booker');", - " pm.expect(jsonData[1].booker).to.have.property('id');", - " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[1] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('id');", - " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking[1] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('name');", - " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');", - "", - "var start = moment();", - "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings?state=FUTURE", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ], - "query": [ - { - "key": "state", - "value": "FUTURE" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for user 1 by wrong state", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 500\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500,400]);", - "});", - "pm.test(\"Test get user bookings by 'UNSUPPORTED_STATUS' state\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.error, 'Error message').to.be.eql('Unknown state: UNSUPPORTED_STATUS');", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings?state=UNSUPPORTED_STATUS", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ], - "query": [ - { - "key": "state", - "value": "UNSUPPORTED_STATUS" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for owner", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list booking response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", - "});", - "", - "pm.test(\"Test booking[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test booking[0] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('start');", - " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('end');", - " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", - "});", - "pm.test(\"Test booking[0] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('status');", - " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('booker');", - " pm.expect(jsonData[0].booker).to.have.property('id');", - " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[0] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('id');", - " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking[0] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('name');", - " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "", - "pm.test(\"Test booking[1] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('id');", - " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test booking[1] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('start');", - " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", - "});", - "pm.test(\"Test booking[1] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('end');", - " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", - "});", - "pm.test(\"Test booking[1] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('status');", - " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking[1] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('booker');", - " pm.expect(jsonData[1].booker).to.have.property('id');", - " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[1] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('id');", - " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking[1] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('name');", - " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/owner", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - "owner" - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for owner by ALL state", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list booking response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", - "});", - "", - "pm.test(\"Test booking[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test booking[0] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('start');", - " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('end');", - " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", - "});", - "pm.test(\"Test booking[0] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('status');", - " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('booker');", - " pm.expect(jsonData[0].booker).to.have.property('id');", - " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[0] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('id');", - " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking[0] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('name');", - " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "", - "pm.test(\"Test booking[1] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('id');", - " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test booking[1] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('start');", - " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", - "});", - "pm.test(\"Test booking[1] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('end');", - " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", - "});", - "pm.test(\"Test booking[1] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('status');", - " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking[1] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('booker');", - " pm.expect(jsonData[1].booker).to.have.property('id');", - " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[1] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('id');", - " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking[1] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('name');", - " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/owner?state=ALL", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - "owner" - ], - "query": [ - { - "key": "state", - "value": "ALL" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for owner by FUTURE state", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list booking response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", - "});", - "", - "pm.test(\"Test booking[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test booking[0] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('start');", - " pm.expect(new Date(jsonData[0].start), '\"start\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", - "", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('end');", - " pm.expect(new Date(jsonData[0].end), '\"end\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", - "});", - "pm.test(\"Test booking[0] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('status');", - " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('booker');", - " pm.expect(jsonData[0].booker).to.have.property('id');", - " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[0] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('id');", - " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking[0] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('name');", - " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "", - "pm.test(\"Test booking[1] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('id');", - " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test booking[1] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('start');", - "});", - "pm.test(\"Test booking[1] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('end');", - "});", - "pm.test(\"Test booking[1] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('start');", - " pm.expect(new Date(jsonData[1].start), '\"start\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", - "", - "});", - "pm.test(\"Test booking[1] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('end');", - " pm.expect(new Date(jsonData[1].end), '\"end\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", - "});", - "pm.test(\"Test booking[1] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('status');", - " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking[1] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('booker');", - " pm.expect(jsonData[1].booker).to.have.property('id');", - " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[1] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('id');", - " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking[1] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('name');", - " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');", - "", - "var start = moment();", - "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/owner?state=FUTURE", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - "owner" - ], - "query": [ - { - "key": "state", - "value": "FUTURE" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for owner by wrong state", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 500\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500,400]);", - "});", - "pm.test(\"Test get owner bookings by 'UNSUPPORTED_STATUS' state\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.error, 'Error message').to.be.eql('Unknown state: UNSUPPORTED_STATUS');", - "});" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/owner?state=UNSUPPORTED_STATUS", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - "owner" - ], - "query": [ - { - "key": "state", - "value": "UNSUPPORTED_STATUS" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking 1000 get from user 4", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 404\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([404]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/:bookingId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - ":bookingId" - ], - "variable": [ - { - "key": "bookingId", - "value": "1000" - } - ] - } - }, - "response": [] - }, - { - "name": "User 5 create", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has user create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test user 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 5').to.eql(5);", - "});", - "pm.test(\"Test user 'email' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('email');", - " pm.expect(jsonData.email, '\"email\" must be \"other@other.com\"').to.eql('other@other.com');", - "});", - "pm.test(\"Test user 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"other\"').to.eql('other');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"other\",\n \"email\": \"other@other.com\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/users", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users" - ] - } - }, - "response": [] - }, - { - "name": "Booking 1 get from user 5", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 404\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([404]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "5", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/:bookingId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - ":bookingId" - ], - "variable": [ - { - "key": "bookingId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking 2 change status from user 5 fail", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 500\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500,400]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "5", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/:bookingId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - ":bookingId" - ], - "variable": [ - { - "key": "bookingId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking 2 change status by user 1 (booker)", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 404\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([404]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - ":bookingId" - ], - "query": [ - { - "key": "approved", - "value": "true" - } - ], - "variable": [ - { - "key": "bookingId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking 2 set approve by user 4 (owner)", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200]);", - "});", - "pm.test(\"Has booking get response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - ":bookingId" - ], - "query": [ - { - "key": "approved", - "value": "true" - } - ], - "variable": [ - { - "key": "bookingId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking 2 change status by user 4 (owner) after approve", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - ":bookingId" - ], - "query": [ - { - "key": "approved", - "value": "true" - } - ], - "variable": [ - { - "key": "bookingId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "User 6 create", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has user create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test user 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 6').to.eql(6);", - "});", - "pm.test(\"Test user 'email' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('email');", - " pm.expect(jsonData.email, '\"email\" must be \"practicum@yandex.ru\"').to.eql('practicum@yandex.ru');", - "});", - "pm.test(\"Test user 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"practicum\"').to.eql('practicum');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"practicum\",\n \"email\": \"practicum@yandex.ru\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/users", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "users" - ] - } - }, - "response": [] - }, - { - "name": "Booking create from user 1 to item 1 failed", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 404\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([404]);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(2, 'd');\r", - "var end = moment().add(3, 'd');\r", - "pm.environment.set('start3', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "pm.environment.set('end3', end.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 1,\n \"start\": \"{{start3}}\",\n \"end\": \"{{end3}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking 3 create from user 4 to item 1", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has booking create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 3').to.eql(3);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start3') + '\"').to.eql(pm.environment.get('start3'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end3') + '\"').to.eql(pm.environment.get('end3'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"4\"').to.eql(4);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(1, 'd');\r", - "var end = moment().add(1, 'd').add(1, 'h');\r", - "pm.environment.set('start3', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "pm.environment.set('end3', end.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 1,\n \"start\": \"{{start3}}\",\n \"end\": \"{{end3}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking 3 set rejected by user 1 (owner)", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.expect(pm.response.code).to.be.ok;", - "});", - "pm.test(\"Has booking create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 3').to.eql(3);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start3') + '\"').to.eql(pm.environment.get('start3'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end3') + '\"').to.eql(pm.environment.get('end3'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"4\"').to.eql(4);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/:bookingId?approved=false", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - ":bookingId" - ], - "query": [ - { - "key": "approved", - "value": "false" - } - ], - "variable": [ - { - "key": "bookingId", - "value": "3" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking 4 create from user 5 to item 2", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has booking create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 4').to.eql(4);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start4') + '\"').to.eql(pm.environment.get('start4'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end4') + '\"').to.eql(pm.environment.get('end4'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"5\"').to.eql(5);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(1, 'h');\r", - "var end = moment().add(2, 'h');\r", - "pm.environment.set('start4', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "pm.environment.set('end4', end.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "5", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start4}}\",\n \"end\": \"{{end4}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking 4 set approve by user 4 (owner)", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200]);", - "});", - "pm.test(\"Has booking get response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 4').to.eql(4);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start4') + '\"').to.eql(pm.environment.get('start4'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end4') + '\"').to.eql(pm.environment.get('end4'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"5\"').to.eql(5);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - ":bookingId" - ], - "query": [ - { - "key": "approved", - "value": "true" - } - ], - "variable": [ - { - "key": "bookingId", - "value": "4" - } - ] - } - }, - "response": [] - }, - { - "name": "Item 2 get by user 4 (owner) with bookings", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});", - "", - "pm.test(\"Test item 'lastBooking.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('lastBooking');", - " pm.expect(jsonData.lastBooking).to.have.property('id');", - " pm.expect(jsonData.lastBooking.id, '\"lastBooking.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test item 'lastBooking.bookerId' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('lastBooking');", - " pm.expect(jsonData.lastBooking).to.have.property('bookerId');", - " pm.expect(jsonData.lastBooking.bookerId, '\"lastBooking.bookerId\" must be \"1\"').to.eql(1);", - "});", - "", - "pm.test(\"Test item 'nextBooking.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('nextBooking');", - " pm.expect(jsonData.nextBooking).to.have.property('id');", - " pm.expect(jsonData.nextBooking.id, '\"nextBooking.id\" must be \"1\"').to.eql(4);", - "});", - "pm.test(\"Test item 'nextBooking.bookerId' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('nextBooking');", - " pm.expect(jsonData.nextBooking).to.have.property('bookerId');", - " pm.expect(jsonData.nextBooking.bookerId, '\"nextBooking.bookerId\" must be \"1\"').to.eql(5);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var time = setTimeout(function(){}, 4000);\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Item 2 get by user 1 without bookings", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});", - "", - "pm.test(\"Test item 'lastBooking' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('lastBooking');", - " pm.expect(jsonData.lastBooking, '\"lastBooking\" must be \"null\"').null;", - "});", - "pm.test(\"Test item 'nextBooking' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('nextBooking');", - " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Item 2 get by user 5 without bookings", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});", - "", - "pm.test(\"Test item 'lastBooking' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('lastBooking');", - " pm.expect(jsonData.lastBooking, '\"lastBooking\" must be \"null\"').null;", - "});", - "pm.test(\"Test item 'nextBooking' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('nextBooking');", - " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "5", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Item get all user 4 with bookings", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list item response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", - "});", - "", - "pm.test(\"Test item[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test item[0] 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('name');", - " pm.expect(jsonData[0].name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "pm.test(\"Test item[0] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('description');", - " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", - "});", - "pm.test(\"Test item[0] 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('available');", - " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", - "});", - "pm.test(\"Test item[0] 'lastBooking.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('lastBooking');", - " pm.expect(jsonData[0].lastBooking).to.have.property('id');", - " pm.expect(jsonData[0].lastBooking.id, '\"lastBooking.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test item[0] 'lastBooking.bookerId' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('lastBooking');", - " pm.expect(jsonData[0].lastBooking).to.have.property('bookerId');", - " pm.expect(jsonData[0].lastBooking.bookerId, '\"lastBooking.bookerId\" must be \"1\"').to.eql(1);", - "});", - "", - "pm.test(\"Test item[0] 'nextBooking.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('nextBooking');", - " pm.expect(jsonData[0].nextBooking).to.have.property('id');", - " pm.expect(jsonData[0].nextBooking.id, '\"nextBooking.id\" must be \"1\"').to.eql(4);", - "});", - "pm.test(\"Test item[0] 'nextBooking.bookerId' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('nextBooking');", - " pm.expect(jsonData[0].nextBooking).to.have.property('bookerId');", - " pm.expect(jsonData[0].nextBooking.bookerId, '\"nextBooking.bookerId\" must be \"1\"').to.eql(5);", - "});", - "", - "", - "pm.test(\"Test item[1] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('id');", - " pm.expect(jsonData[1].id, '\"id\" must be 3').to.eql(3);", - "});", - "pm.test(\"Test item[1] 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('name');", - " pm.expect(jsonData[1].name, '\"name\" must be \"Клей Момент\"').to.eql('Клей Момент');", - "});", - "pm.test(\"Test item[1] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('description');", - " pm.expect(jsonData[1].description, '\"description\" must be \"Тюбик суперклея марки Момент\"').to.eql('Тюбик суперклея марки Момент');", - "});", - "pm.test(\"Test item[1] 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('available');", - " pm.expect(jsonData[1].available, '\"available\" must be \"true\"').to.true;", - "});", - "pm.test(\"Test item[1] 'lastBooking' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('lastBooking');", - " pm.expect(jsonData[1].lastBooking, '\"lastBooking\" must be \"null\"').null;", - "});", - "pm.test(\"Test item[1] 'nextBooking' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('nextBooking');", - " pm.expect(jsonData[1].nextBooking, '\"nextBooking\" must be \"null\"').null;", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items" - ] - } - }, - "response": [] - }, - { - "name": "Booking 5 create from user 1 to item 3 current", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has booking create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 5').to.eql(5);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"3\"').to.eql(3);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(3, 's');\r", - "var end = moment().add(1, 'd')\r", - "pm.environment.set('start5', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "pm.environment.set('end5', end.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 3,\n \"start\": \"{{start5}}\",\n \"end\": \"{{end5}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for user 1 by WAITING state", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list booking response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", - "});", - "", - "pm.test(\"Test booking[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", - "});", - "pm.test(\"Test booking[0] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('start');", - " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('end');", - " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", - "});", - "pm.test(\"Test booking[0] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('status');", - " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('booker');", - " pm.expect(jsonData[0].booker).to.have.property('id');", - " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[0] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('id');", - " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", - "});", - "pm.test(\"Test booking[0] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('name');", - " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');", - "", - "var start = moment();", - "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings?state=WAITING", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ], - "query": [ - { - "key": "state", - "value": "WAITING" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for user 4 (owner) by WAITING state", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list booking response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", - "});", - "", - "pm.test(\"Test booking[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", - "});", - "pm.test(\"Test booking[0] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('start');", - " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('end');", - " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", - "});", - "pm.test(\"Test booking[0] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('status');", - " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('booker');", - " pm.expect(jsonData[0].booker).to.have.property('id');", - " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[0] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('id');", - " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", - "});", - "pm.test(\"Test booking[0] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('name');", - " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');", - "", - "var start = moment();", - "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/owner?state=WAITING", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - "owner" - ], - "query": [ - { - "key": "state", - "value": "WAITING" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking 6 create from user 1 to item 2 current", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has booking create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 6').to.eql(6);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start6') + '\"').to.eql(pm.environment.get('start6'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end6') + '\"').to.eql(pm.environment.get('end6'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(3, 's');\r", - "var end = moment().add(4, 's')\r", - "pm.environment.set('start6', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "pm.environment.set('end6', end.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start6}}\",\n \"end\": \"{{end6}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking 5 set rejected by user 4 (owner)", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has booking create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 5').to.eql(5);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"3\"').to.eql(3);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/:bookingId?approved=false", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - ":bookingId" - ], - "query": [ - { - "key": "approved", - "value": "false" - } - ], - "variable": [ - { - "key": "bookingId", - "value": "5" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for user 1 by REJECTED state", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list booking response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", - "});", - "", - "pm.test(\"Test booking[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", - "});", - "pm.test(\"Test booking[0] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('start');", - " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('end');", - " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", - "});", - "pm.test(\"Test booking[0] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('status');", - " pm.expect(jsonData[0].status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('booker');", - " pm.expect(jsonData[0].booker).to.have.property('id');", - " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[0] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('id');", - " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", - "});", - "pm.test(\"Test booking[0] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('name');", - " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');", - "", - "var start = moment();", - "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings?state=REJECTED", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ], - "query": [ - { - "key": "state", - "value": "REJECTED" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for user 4 (owner) by REJECTED state", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list booking response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", - "});", - "", - "pm.test(\"Test booking[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", - "});", - "pm.test(\"Test booking[0] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('start');", - " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('end');", - " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", - "});", - "pm.test(\"Test booking[0] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('status');", - " pm.expect(jsonData[0].status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('booker');", - " pm.expect(jsonData[0].booker).to.have.property('id');", - " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[0] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('id');", - " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", - "});", - "pm.test(\"Test booking[0] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('name');", - " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');", - "", - "var start = moment();", - "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/owner?state=REJECTED", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - "owner" - ], - "query": [ - { - "key": "state", - "value": "REJECTED" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking 6 set approve by owner 4 current", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200]);", - "});", - "pm.test(\"Has booking patch response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 6').to.eql(6);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start6') + '\"').to.eql(pm.environment.get('start6'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end6') + '\"').to.eql(pm.environment.get('end6'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - ":bookingId" - ], - "query": [ - { - "key": "approved", - "value": "true" - } - ], - "variable": [ - { - "key": "bookingId", - "value": "6" - } - ] - } - }, - "response": [] - } - ] - }, - { - "name": "comments", - "item": [ - { - "name": "Item 4 create by user 6", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has item create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 4').to.eql(4);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Кухонный стол\"').to.eql('Кухонный стол');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Стол для празднования\"').to.eql('Стол для празднования');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "6", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"Кухонный стол\",\n \"description\": \"Стол для празднования\",\n \"available\": true\n}" - }, - "url": { - "raw": "{{baseUrl}}/items", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items" - ] - } - }, - "response": [] - }, - { - "name": "Item 1 get from user 1 (owner) without comments", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "", - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});", - "pm.test(\"Test item 'lastBooking' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('lastBooking');", - " pm.expect(jsonData.lastBooking, '\"lastBooking\" must be \"null\"').null;", - "});", - "pm.test(\"Test item 'nextBooking' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('nextBooking');", - " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", - "});", - "pm.test(\"Test item 'comments' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('comments');", - " pm.expect(jsonData.comments.length, 'length of \"comments\" must be \"0\"').to.eql(0);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking 7 future create from user 5 to item 1", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has booking create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 7').to.eql(7);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start7') + '\"').to.eql(pm.environment.get('start7'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end7') + '\"').to.eql(pm.environment.get('end7'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"5\"').to.eql(5);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(10, 'd');\r", - "var end = moment().add(11, 'd')\r", - "pm.environment.set('start7', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "pm.environment.set('end7', end.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "5", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 1,\n \"start\": \"{{start7}}\",\n \"end\": \"{{end7}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking 8 create from user 1 to item 4 start past and end future", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has booking create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 8').to.eql(8);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start8') + '\"').to.eql(pm.environment.get('start8'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end8') + '\"').to.eql(pm.environment.get('end8'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"4\"').to.eql(4);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Кухонный стол\"').to.eql('Кухонный стол');", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment().add(2, 's');\r", - "var end = moment().add(1, 'h');\r", - "pm.environment.set('start8', start.format('YYYY-MM-DDTHH:mm:ss'));\r", - "pm.environment.set('end8', end.format('YYYY-MM-DDTHH:mm:ss'));\r", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"itemId\": 4,\n \"start\": \"{{start8}}\",\n \"end\": \"{{end8}}\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/bookings", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ] - } - }, - "response": [] - }, - { - "name": "Booking 8 set approve by user 6 (owner)", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200]);", - "});", - "pm.test(\"Has booking get response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 8').to.eql(8);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start8') + '\"').to.eql(pm.environment.get('start8'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end8') + '\"').to.eql(pm.environment.get('end8'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"4\"').to.eql(4);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Кухонный стол\"').to.eql('Кухонный стол');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "6", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - ":bookingId" - ], - "query": [ - { - "key": "approved", - "value": "true" - } - ], - "variable": [ - { - "key": "bookingId", - "value": "8" - } - ] - } - }, - "response": [] - }, - { - "name": "Item 2 get from user 1 without comments", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});", - "pm.test(\"Test item 'lastBooking' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('lastBooking');", - " pm.expect(jsonData.lastBooking, '\"lastBooking\" must be \"null\"').null;", - "});", - "pm.test(\"Test item 'nextBooking' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('nextBooking');", - " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", - "});", - "", - "pm.test(\"Test item 'comments' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('comments');", - " pm.expect(jsonData.comments.length, 'length of \"comments\" must be \"0\"').to.eql(0);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var time = setTimeout(function(){}, 3000);" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Item 2 get from user 4 (owner) without comments", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});", - "", - "pm.test(\"Test item 'lastBooking.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('lastBooking');", - " pm.expect(jsonData.lastBooking).to.have.property('id');", - " pm.expect(jsonData.lastBooking.id, '\"lastBooking.id\" must be \"6\"').to.eql(6);", - "});", - "pm.test(\"Test item 'lastBooking.bookerId' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('lastBooking');", - " pm.expect(jsonData.lastBooking).to.have.property('bookerId');", - " pm.expect(jsonData.lastBooking.bookerId, '\"lastBooking.bookerId\" must be \"1\"').to.eql(1);", - "});", - "", - "pm.test(\"Test item 'nextBooking.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('nextBooking');", - " pm.expect(jsonData.nextBooking).to.have.property('id');", - " pm.expect(jsonData.nextBooking.id, '\"nextBooking.id\" must be \"1\"').to.eql(4);", - "});", - "pm.test(\"Test item 'nextBooking.bookerId' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('nextBooking');", - " pm.expect(jsonData.nextBooking).to.have.property('bookerId');", - " pm.expect(jsonData.nextBooking.bookerId, '\"nextBooking.bookerId\" must be \"1\"').to.eql(5);", - "});", - "", - "pm.test(\"Test item 'comments' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('comments');", - " pm.expect(jsonData.comments.length, 'length of \"comments\" must be \"0\"').to.eql(0);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var time = setTimeout(function(){}, 3000);" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Comment from user 4 to item 1 without booking failed", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - }, - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"text\": \"Comment for item 1\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/items/:itemId/comment", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId", - "comment" - ], - "variable": [ - { - "key": "itemId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "Comment from user 1 to item 2 empty failed", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - }, - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"text\": \"\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/items/:itemId/comment", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId", - "comment" - ], - "variable": [ - { - "key": "itemId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Comment 1 from user 1 to item 2", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200]);", - "});", - "pm.test(\"Test add comment to item 2 from user1\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.id, '\"id\" field').to.eql(1);", - " pm.expect(jsonData.text, '\"text\" field').to.eql(\"Add comment from user1\");", - " pm.expect(jsonData.authorName, '\"authorName\" field').to.eql(\"updateName\");", - " pm.expect(jsonData.created, '\"created\" field').not.null;", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment();\r", - "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - }, - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"text\": \"Add comment from user1\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/items/:itemId/comment", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId", - "comment" - ], - "variable": [ - { - "key": "itemId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Item 2 get by user 1 with comments", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});", - "pm.test(\"Test item 'lastBooking' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('lastBooking');", - " pm.expect(jsonData.lastBooking, '\"lastBooking\" must be \"null\"').null;", - "});", - "pm.test(\"Test item 'nextBooking' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('nextBooking');", - " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", - "});", - "", - "pm.test(\"Test item 'comments' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('comments');", - " pm.expect(jsonData.comments.length, 'length of \"comments\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test item 'comments[0].id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.comments[0]).to.have.property('id');", - " pm.expect(jsonData.comments[0].id, '\"id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test item 'comments[0].text' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.comments[0]).to.have.property('text');", - " pm.expect(jsonData.comments[0].text, '\"text\" must be \"Add comment from user1\"').to.eql('Add comment from user1');", - "});", - "pm.test(\"Test item 'comments[0].authorName' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.comments[0]).to.have.property('authorName');", - " pm.expect(jsonData.comments[0].authorName, '\"authorName\" must be \"updateName\"').to.eql(\"updateName\");", - "});", - "pm.test(\"Test item 'comments[0].created' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.comments[0]).to.have.property('created');", - " pm.expect(new Date(jsonData.comments[0].created), '\"created\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Item 2 get by user 4 (owner) with comments", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});", - "", - "pm.test(\"Test item 'lastBooking.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('lastBooking');", - " pm.expect(jsonData.lastBooking).to.have.property('id');", - " pm.expect(jsonData.lastBooking.id, '\"lastBooking.id\" must be \"6\"').to.eql(6);", - "});", - "pm.test(\"Test item 'lastBooking.bookerId' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('lastBooking');", - " pm.expect(jsonData.lastBooking).to.have.property('bookerId');", - " pm.expect(jsonData.lastBooking.bookerId, '\"lastBooking.bookerId\" must be \"1\"').to.eql(1);", - "});", - "", - "pm.test(\"Test item 'nextBooking.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('nextBooking');", - " pm.expect(jsonData.nextBooking).to.have.property('id');", - " pm.expect(jsonData.nextBooking.id, '\"nextBooking.id\" must be \"1\"').to.eql(4);", - "});", - "pm.test(\"Test item 'nextBooking.bookerId' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('nextBooking');", - " pm.expect(jsonData.nextBooking).to.have.property('bookerId');", - " pm.expect(jsonData.nextBooking.bookerId, '\"nextBooking.bookerId\" must be \"1\"').to.eql(5);", - "});", - "", - "pm.test(\"Test item 'comments' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('comments');", - " pm.expect(jsonData.comments.length, 'length of \"comments\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test item 'comments[0].id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.comments[0]).to.have.property('id');", - " pm.expect(jsonData.comments[0].id, '\"id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test item 'comments[0].text' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.comments[0]).to.have.property('text');", - " pm.expect(jsonData.comments[0].text, '\"text\" must be \"Add comment from user1\"').to.eql('Add comment from user1');", - "});", - "pm.test(\"Test item 'comments[0].authorName' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.comments[0]).to.have.property('authorName');", - " pm.expect(jsonData.comments[0].authorName, '\"authorName\" must be \"updateName\"').to.eql(\"updateName\");", - "});", - "pm.test(\"Test item 'comments[0].created' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.comments[0]).to.have.property('created');", - " pm.expect(new Date(jsonData.comments[0].created), '\"created\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking 7 set approve by owner future", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has booking create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test booking 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 7').to.eql(7);", - "});", - "pm.test(\"Test booking 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('start');", - " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start7') + '\"').to.eql(pm.environment.get('start7'));", - "});", - "pm.test(\"Test booking 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('end');", - " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end7') + '\"').to.eql(pm.environment.get('end7'));", - "});", - "pm.test(\"Test booking 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('status');", - " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('booker');", - " pm.expect(jsonData.booker).to.have.property('id');", - " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"5\"').to.eql(5);", - "});", - "pm.test(\"Test booking 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('id');", - " pm.expect(jsonData.item.id, '\"item.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('item');", - " pm.expect(jsonData.item).to.have.property('name');", - " pm.expect(jsonData.item.name, '\"item.name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "PATCH", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - ":bookingId" - ], - "query": [ - { - "key": "approved", - "value": "true" - } - ], - "variable": [ - { - "key": "bookingId", - "value": "7" - } - ] - } - }, - "response": [] - }, - { - "name": "Add comment to item 1 from user5 failed by future booking", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - }, - { - "key": "X-Sharer-User-Id", - "value": "5", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"text\": \"Add comment from user5\"\n}" - }, - "url": { - "raw": "{{baseUrl}}/items/:itemId/comment", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId", - "comment" - ], - "variable": [ - { - "key": "itemId", - "value": "1" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for user 1 by CURRENT state", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list booking response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", - "});", - "", - "pm.test(\"Test booking[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", - "});", - "pm.test(\"Test booking[0] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('start');", - " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('end');", - " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", - "});", - "pm.test(\"Test booking[0] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('status');", - " pm.expect(jsonData[0].status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('booker');", - " pm.expect(jsonData[0].booker).to.have.property('id');", - " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[0] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('id');", - " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", - "});", - "pm.test(\"Test booking[0] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('name');", - " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", - "});", - "", - "pm.test(\"Test booking[1] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('id');", - " pm.expect(jsonData[1].id, '\"id\" must be 8').to.eql(8);", - "});", - "pm.test(\"Test booking[1] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('start');", - " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start8') + '\"').to.eql(pm.environment.get('start8'));", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('end');", - " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end8') + '\"').to.eql(pm.environment.get('end8'));", - "});", - "pm.test(\"Test booking[1] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('status');", - " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('booker');", - " pm.expect(jsonData[1].booker).to.have.property('id');", - " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[1] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('id');", - " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"4\"').to.eql(4);", - "});", - "pm.test(\"Test booking[1] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('name');", - " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Кухонный стол\"').to.eql('Кухонный стол');", - "});", - "", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings?state=CURRENT", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ], - "query": [ - { - "key": "state", - "value": "CURRENT" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for user 4 (owner) by CURRENT state", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list booking response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", - "});", - "", - "pm.test(\"Test booking[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", - "});", - "pm.test(\"Test booking[0] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('start');", - " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('end');", - " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", - "});", - "pm.test(\"Test booking[0] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('status');", - " pm.expect(jsonData[0].status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('booker');", - " pm.expect(jsonData[0].booker).to.have.property('id');", - " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[0] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('id');", - " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", - "});", - "pm.test(\"Test booking[0] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('name');", - " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/owner?state=CURRENT", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - "owner" - ], - "query": [ - { - "key": "state", - "value": "CURRENT" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for user 1 by PAST state", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list booking response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", - "});", - "", - "pm.test(\"Test booking[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 6').to.eql(6);", - "});", - "pm.test(\"Test booking[0] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('start');", - " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start6') + '\"').to.eql(pm.environment.get('start6'));", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('end');", - " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end6') + '\"').to.eql(pm.environment.get('end6'));", - "});", - "pm.test(\"Test booking[0] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('status');", - " pm.expect(jsonData[0].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('booker');", - " pm.expect(jsonData[0].booker).to.have.property('id');", - " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[0] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('id');", - " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking[0] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('name');", - " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "", - "pm.test(\"Test booking[1] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('id');", - " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test booking[1] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('start');", - " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('end');", - " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", - "});", - "pm.test(\"Test booking[0] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('status');", - " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('booker');", - " pm.expect(jsonData[1].booker).to.have.property('id');", - " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[0] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('id');", - " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking[0] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('name');", - " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings?state=PAST", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ], - "query": [ - { - "key": "state", - "value": "PAST" - } - ] - } - }, - "response": [] - }, - { - "name": "Booking get all for user 4 (owner) by PAST state", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list booking response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", - "});", - "", - "pm.test(\"Test booking[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 6').to.eql(6);", - "});", - "pm.test(\"Test booking[0] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('start');", - " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start6') + '\"').to.eql(pm.environment.get('start6'));", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('end');", - " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end6') + '\"').to.eql(pm.environment.get('end6'));", - "});", - "pm.test(\"Test booking[0] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('status');", - " pm.expect(jsonData[0].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('booker');", - " pm.expect(jsonData[0].booker).to.have.property('id');", - " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[0] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('id');", - " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking[0] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('item');", - " pm.expect(jsonData[0].item).to.have.property('name');", - " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});", - "", - "pm.test(\"Test booking[1] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('id');", - " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test booking[1] 'start' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('start');", - " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", - "});", - "pm.test(\"Test booking[0] 'end' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('end');", - " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", - "});", - "pm.test(\"Test booking[0] 'status' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('status');", - " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", - "});", - "pm.test(\"Test booking[0] 'booker.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('booker');", - " pm.expect(jsonData[1].booker).to.have.property('id');", - " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", - "});", - "pm.test(\"Test booking[0] 'item.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('id');", - " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", - "});", - "pm.test(\"Test booking[0] 'item.name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[1]).to.have.property('item');", - " pm.expect(jsonData[1].item).to.have.property('name');", - " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/owner?state=PAST", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - "owner" - ], - "query": [ - { - "key": "state", - "value": "PAST" - } - ] - } - }, - "response": [] - }, - { - "name": "Item 4 get by user 6 (owner) without comments", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Has item update response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 4').to.eql(4);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Кухонный стол\"').to.eql('Кухонный стол');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Стол для празднования\"').to.eql('Стол для празднования');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});", - "", - "pm.test(\"Test item 'lastBooking.id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('lastBooking');", - " pm.expect(jsonData.lastBooking).to.have.property('id');", - " pm.expect(jsonData.lastBooking.id, '\"lastBooking.id\" must be \"8\"').to.eql(8);", - "});", - "pm.test(\"Test item 'lastBooking.bookerId' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('lastBooking');", - " pm.expect(jsonData.lastBooking).to.have.property('bookerId');", - " pm.expect(jsonData.lastBooking.bookerId, '\"lastBooking.bookerId\" must be \"1\"').to.eql(1);", - "});", - "", - "pm.test(\"Test item 'nextBooking'\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('nextBooking');", - " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "6", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/items/:itemId", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items", - ":itemId" - ], - "variable": [ - { - "key": "itemId", - "value": "4" - } - ] - } - }, - "response": [] - } - ] - }, - { - "name": "item requests", - "item": [ - { - "name": "Add item request with wrong user", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 500\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500,404,403]);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "99", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"description\": \"Хотел бы воспользоваться щёткой для обуви\"\n}", - "options": { - "raw": { - "language": "json" - } - } - }, - "url": { - "raw": "{{baseUrl}}/requests", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests" - ] - } - }, - "response": [] - }, - { - "name": "Add item request with empty description", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([400]);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"description\": null\n}", - "options": { - "raw": { - "language": "json" - } - } - }, - "url": { - "raw": "{{baseUrl}}/requests", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests" - ] - } - }, - "response": [] - }, - { - "name": "Requests get own by wrong user id", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 404\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500,404,403]);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "99", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/requests", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests" - ] - } - }, - "response": [] - }, - { - "name": "Requests get own by user id without requests", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list item requests response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 0').to.eql(0);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/requests", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests" - ] - } - }, - "response": [] - }, - { - "name": "Requests get all without pagination params", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list item requests response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 0').to.eql(0);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/requests/all", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests", - "all" - ] - } - }, - "response": [] - }, - { - "name": "Requests get all with from = 0 & size = 0", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500,400]);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/requests/all?from=0&size=0", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests", - "all" - ], - "query": [ - { - "key": "from", - "value": "0" - }, - { - "key": "size", - "value": "0" - } - ] - } - }, - "response": [] - }, - { - "name": "Requests get all with from = -1 & size = 20", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500,400]);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/requests/all?from=-1&size=20", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests", - "all" - ], - "query": [ - { - "key": "from", - "value": "-1" - }, - { - "key": "size", - "value": "20" - } - ] - } - }, - "response": [] - }, - { - "name": "Requests get all with from = 0 & size = -1", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500,400]);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/requests/all?from=0&size=-1", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests", - "all" - ], - "query": [ - { - "key": "from", - "value": "0" - }, - { - "key": "size", - "value": "-1" - } - ] - } - }, - "response": [] - }, - { - "name": "Requests get all with from = 0 & size = 20 when empty", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list item requests response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 0').to.eql(0);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/requests/all?from=0&size=20", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests", - "all" - ], - "query": [ - { - "key": "from", - "value": "0" - }, - { - "key": "size", - "value": "20" - } - ] - } - }, - "response": [] - }, - { - "name": "Add item request 1", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has item request create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item request 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item request 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", - "});", - "pm.test(\"Test item request 'created' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('created');", - " pm.expect(jsonData.created, '\"created\" must be not null').is.not.null;", - "", - " var current = pm.environment.get('currentDateTime');", - " var created = new Date(jsonData.created);", - " var future = new Date(current);", - " future.setSeconds(future.getSeconds() + 2);", - " pm.expect(created, '\"created\" must be > ' + pm.environment.get('currentDateTime')).to.gte(new Date(current));", - " pm.expect(created, '\"created\" must be < ' + future).to.lte(future);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');", - "", - "var start = moment();", - "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"description\": \"Хотел бы воспользоваться щёткой для обуви\"\n}", - "options": { - "raw": { - "language": "json" - } - } - }, - "url": { - "raw": "{{baseUrl}}/requests", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests" - ] - } - }, - "response": [] - }, - { - "name": "Requests get own by user id with requests empty items", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list item requests response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", - "});", - "", - "pm.test(\"Test item request[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item request[0] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('description');", - " pm.expect(jsonData[0].description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", - "});", - "pm.test(\"Test item request[0] 'created' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('created');", - " pm.expect(jsonData[0].created, '\"created\" must be not null').is.not.null;", - "});", - "pm.test(\"Test item request[0] 'items' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('items');", - " pm.expect(jsonData[0].items, '\"items\" must be not null').is.not.null;", - " pm.expect(jsonData[0].items.length, 'items count in total').to.eql(0);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var time = setTimeout(function(){}, 1000);" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/requests", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests" - ] - } - }, - "response": [] - }, - { - "name": "Add item 5 to request 1 from user 4", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200 or 201\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200,201]);", - "});", - "pm.test(\"Has item create response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "pm.test(\"Test item 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 5').to.eql(5);", - "});", - "pm.test(\"Test item 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('name');", - " pm.expect(jsonData.name, '\"name\" must be \"Щётка для обуви\"').to.eql('Щётка для обуви');", - "});", - "pm.test(\"Test item 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Стандартная щётка для обуви\"').to.eql('Стандартная щётка для обуви');", - "});", - "pm.test(\"Test item 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('available');", - " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", - "});", - "pm.test(\"Test item 'requestId' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('requestId');", - " pm.expect(jsonData.requestId, '\"requestId\" must be \"1\"').to.eq(1);", - "});", - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "POST", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Content-Type", - "value": "application/json", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "body": { - "mode": "raw", - "raw": "{\n \"name\": \"Щётка для обуви\",\n \"description\": \"Стандартная щётка для обуви\",\n \"available\": true,\n \"requestId\": 1\n}" - }, - "url": { - "raw": "{{baseUrl}}/items", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "items" - ] - } - }, - "response": [] - }, - { - "name": "Requests get own by user id with requests", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list item requests response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", - "});", - "", - "pm.test(\"Test item request[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item request[0] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('description');", - " pm.expect(jsonData[0].description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", - "});", - "pm.test(\"Test item request[0] 'created' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('created');", - " pm.expect(jsonData[0].created, '\"created\" must be not null').is.not.null;", - " ", - " var created = new Date(jsonData[0].created);", - " var future = new Date(pm.environment.get('currentDateTime'));", - " pm.expect(created, '\"created\" must be < ' + pm.environment.get('currentDateTime')).to.lte(future);", - "});", - "pm.test(\"Test item request[0] 'items' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('items');", - " pm.expect(jsonData[0].items, '\"items\" must be not null').is.not.null;", - " pm.expect(jsonData[0].items.length, 'items count must be 1').to.eql(1);", - "});", - "pm.test(\"Test request[0].items[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0].items[0]).to.have.property('id');", - " pm.expect(jsonData[0].items[0].id, '\"id\" must be 5').to.eql(5);", - "});", - "pm.test(\"Test request[0].items[0] 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0].items[0]).to.have.property('name');", - " pm.expect(jsonData[0].items[0].name, '\"name\" must be \"Щётка для обуви\"').to.eql('Щётка для обуви');", - "});", - "pm.test(\"Test request[0].items[0] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0].items[0]).to.have.property('description');", - " pm.expect(jsonData[0].items[0].description, '\"description\" must be \"Стандартная щётка для обуви\"').to.eql('Стандартная щётка для обуви');", - "});", - "pm.test(\"Test request[0].items[0] 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0].items[0]).to.have.property('available');", - " pm.expect(jsonData[0].items[0].available, '\"available\" must be \"true\"').to.true;", - "});", - "pm.test(\"Test request[0].items[0] 'requestId' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0].items[0]).to.have.property('requestId');", - " pm.expect(jsonData[0].items[0].requestId, '\"requestId\" must be \"1\"').to.eq(1);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');", - "", - "var start = moment();", - "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss.sss'));" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/requests", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests" - ] - } - }, - "response": [] - }, - { - "name": "Requests get all with from = 0 & size = 20 for request owner", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list item requests response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 0').to.eql(0);", - "});", - "" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/requests/all?from=0&size=20", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests", - "all" - ], - "query": [ - { - "key": "from", - "value": "0" - }, - { - "key": "size", - "value": "20" - } - ] - } - }, - "response": [] - }, - { - "name": "Requests get all with from = 0 & size = 20 for other user", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test list item requests response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", - "});", - "", - "pm.test(\"Test item request[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('id');", - " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item request[0] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('description');", - " pm.expect(jsonData[0].description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", - "});", - "pm.test(\"Test item request[0] 'created' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('created');", - " pm.expect(jsonData[0].created, '\"created\" must be not null').is.not.null;", - " ", - " var created = new Date(jsonData[0].created);", - " var future = new Date(pm.environment.get('currentDateTime'));", - " pm.expect(created, '\"created\" must be < ' + pm.environment.get('currentDateTime')).to.lte(future);", - "});", - "pm.test(\"Test item request[0] 'items' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0]).to.have.property('items');", - " pm.expect(jsonData[0].items, '\"items\" must be not null').is.not.null;", - " pm.expect(jsonData[0].items.length, 'items count must be 1').to.eql(1);", - "});", - "pm.test(\"Test request[0].items[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0].items[0]).to.have.property('id');", - " pm.expect(jsonData[0].items[0].id, '\"id\" must be 5').to.eql(5);", - "});", - "pm.test(\"Test request[0].items[0] 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0].items[0]).to.have.property('name');", - " pm.expect(jsonData[0].items[0].name, '\"name\" must be \"Щётка для обуви\"').to.eql('Щётка для обуви');", - "});", - "pm.test(\"Test request[0].items[0] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0].items[0]).to.have.property('description');", - " pm.expect(jsonData[0].items[0].description, '\"description\" must be \"Стандартная щётка для обуви\"').to.eql('Стандартная щётка для обуви');", - "});", - "pm.test(\"Test request[0].items[0] 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0].items[0]).to.have.property('available');", - " pm.expect(jsonData[0].items[0].available, '\"available\" must be \"true\"').to.true;", - "});", - "pm.test(\"Test request[0].items[0] 'requestId' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData[0].items[0]).to.have.property('requestId');", - " pm.expect(jsonData[0].items[0].requestId, '\"requestId\" must be \"1\"').to.eq(1);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');", - "", - "var start = moment();", - "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss.sss'));" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/requests/all?from=0&size=20", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests", - "all" - ], - "query": [ - { - "key": "from", - "value": "0" - }, - { - "key": "size", - "value": "20" - } - ] - } - }, - "response": [] - }, - { - "name": "Requests get by id for wrong user", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 500\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500, 404, 403]);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "99", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/requests/1", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests", - "1" - ] - } - }, - "response": [] - }, - { - "name": "Requests get by wrong id", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 404\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([404]);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/requests/99", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests", - "99" - ] - } - }, - "response": [] - }, - { - "name": "Requests get by id for other user", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test item request response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "", - "pm.test(\"Test item request 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item request 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", - "});", - "pm.test(\"Test item request 'created' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('created');", - " pm.expect(jsonData.created, '\"created\" must be not null').is.not.null;", - "", - " var created = new Date(jsonData.created);", - " var future = new Date(pm.environment.get('currentDateTime'));", - " pm.expect(created, '\"created\" must be < ' + pm.environment.get('currentDateTime')).to.lte(future);", - "});", - "pm.test(\"Test item request 'items' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('items');", - " pm.expect(jsonData.items, '\"items\" must be not null').is.not.null;", - " pm.expect(jsonData.items.length, 'items count must be 1').to.eql(1);", - "});", - "pm.test(\"Test request.items[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.items[0]).to.have.property('id');", - " pm.expect(jsonData.items[0].id, '\"id\" must be 5').to.eql(5);", - "});", - "pm.test(\"Test request.items[0] 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.items[0]).to.have.property('name');", - " pm.expect(jsonData.items[0].name, '\"name\" must be \"Щётка для обуви\"').to.eql('Щётка для обуви');", - "});", - "pm.test(\"Test request.items[0] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.items[0]).to.have.property('description');", - " pm.expect(jsonData.items[0].description, '\"description\" must be \"Стандартная щётка для обуви\"').to.eql('Стандартная щётка для обуви');", - "});", - "pm.test(\"Test request.items[0] 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.items[0]).to.have.property('available');", - " pm.expect(jsonData.items[0].available, '\"available\" must be \"true\"').to.true;", - "});", - "pm.test(\"Test request.items[0] 'requestId' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.items[0]).to.have.property('requestId');", - " pm.expect(jsonData.items[0].requestId, '\"requestId\" must be \"1\"').to.eq(1);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');\r", - "\r", - "var start = moment();\r", - "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss.sss'));" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "4", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/requests/1", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests", - "1" - ] - } - }, - "response": [] - }, - { - "name": "Requests get by id", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.response.to.be.ok;", - "});", - "pm.test(\"Test item request response\", function () {", - " pm.response.to.be.withBody;", - " pm.response.to.be.json;", - "});", - "", - "pm.test(\"Test item request 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('id');", - " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", - "});", - "pm.test(\"Test item request 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('description');", - " pm.expect(jsonData.description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", - "});", - "pm.test(\"Test item request 'created' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('created');", - " pm.expect(jsonData.created, '\"created\" must be not null').is.not.null;", - "", - " var created = new Date(jsonData.created);", - " var future = new Date(pm.environment.get('currentDateTime'));", - " pm.expect(created, '\"created\" must be < ' + pm.environment.get('currentDateTime')).to.lte(future);", - "});", - "pm.test(\"Test item request 'items' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData).to.have.property('items');", - " pm.expect(jsonData.items, '\"items\" must be not null').is.not.null;", - " pm.expect(jsonData.items.length, 'items count must be 1').to.eql(1);", - "});", - "pm.test(\"Test request.items[0] 'id' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.items[0]).to.have.property('id');", - " pm.expect(jsonData.items[0].id, '\"id\" must be 5').to.eql(5);", - "});", - "pm.test(\"Test request.items[0] 'name' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.items[0]).to.have.property('name');", - " pm.expect(jsonData.items[0].name, '\"name\" must be \"Щётка для обуви\"').to.eql('Щётка для обуви');", - "});", - "pm.test(\"Test request.items[0] 'description' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.items[0]).to.have.property('description');", - " pm.expect(jsonData.items[0].description, '\"description\" must be \"Стандартная щётка для обуви\"').to.eql('Стандартная щётка для обуви');", - "});", - "pm.test(\"Test request.items[0] 'available' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.items[0]).to.have.property('available');", - " pm.expect(jsonData.items[0].available, '\"available\" must be \"true\"').to.true;", - "});", - "pm.test(\"Test request.items[0] 'requestId' field\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.items[0]).to.have.property('requestId');", - " pm.expect(jsonData.items[0].requestId, '\"requestId\" must be \"1\"').to.eq(1);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "var moment = require('moment');", - "", - "var start = moment();", - "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss.sss'));" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/requests/1", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "requests", - "1" - ] - } - }, - "response": [] - } - ] - }, - { - "name": "Pagination", - "item": [ - { - "name": "Bookings get all with from = 0 & size = 0", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500,400]);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings?from=0&size=0", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ], - "query": [ - { - "key": "from", - "value": "0" - }, - { - "key": "size", - "value": "0" - } - ] - } - }, - "response": [] - }, - { - "name": "Bookings owner get all with from = 0 & size = 0", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500,400]);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/owner?from=0&size=0", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - "owner" - ], - "query": [ - { - "key": "from", - "value": "0" - }, - { - "key": "size", - "value": "0" - } - ] - } - }, - "response": [] - }, - { - "name": "Bookings get all with from = -1 & size = 20", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500,400]);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings?from=-1&size=20", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ], - "query": [ - { - "key": "from", - "value": "-1" - }, - { - "key": "size", - "value": "20" - } - ] - } - }, - "response": [] - }, - { - "name": "Bookings owner get all with from = -1 & size = 20", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500,400]);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/owner?from=-1&size=20", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - "owner" - ], - "query": [ - { - "key": "from", - "value": "-1" - }, - { - "key": "size", - "value": "20" - } - ] - } - }, - "response": [] - }, - { - "name": "Bookings get all with from = 0 & size = -1", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500,400]);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings?from=0&size=-1", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ], - "query": [ - { - "key": "from", - "value": "0" - }, - { - "key": "size", - "value": "-1" - } - ] - } - }, - "response": [] - }, - { - "name": "Bookings owner get all with from = 0 & size = -1", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 400\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([500,400]);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/owner?from=0&size=-1", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - "owner" - ], - "query": [ - { - "key": "from", - "value": "0" - }, - { - "key": "size", - "value": "-1" - } - ] - } - }, - "response": [] - }, - { - "name": "Bookings get all with from = 4 & size = 2 when all=5", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200]);", - "});", - "pm.test(\"Test get all bookings\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'bookings count in total').to.eql(1);", - " pm.expect(jsonData[0].id, 'result[0]: \"id\" field').to.eql(1);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings?from=4&size=2", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings" - ], - "query": [ - { - "key": "from", - "value": "4" - }, - { - "key": "size", - "value": "2" - } - ] - } - }, - "response": [] - }, - { - "name": "Bookings owner get all with from = 1 & size = 1 when all=2", - "event": [ - { - "listen": "test", - "script": { - "exec": [ - "pm.test(\"Status code is 200\", function () {", - " pm.expect(pm.response.code).to.be.oneOf([200]);", - "});", - "pm.test(\"Test get all owner bookings\", function () {", - " var jsonData = pm.response.json();", - " pm.expect(jsonData.length, 'owner bookings count in total').to.eql(1);", - " pm.expect(jsonData[0].id, 'result[0]: \"id\" field').to.eql(3);", - "});" - ], - "type": "text/javascript" - } - }, - { - "listen": "prerequest", - "script": { - "exec": [ - "" - ], - "type": "text/javascript" - } - } - ], - "request": { - "method": "GET", - "header": [ - { - "key": "X-Sharer-User-Id", - "value": "1", - "type": "text" - }, - { - "key": "Accept", - "value": "*/*", - "type": "text" - } - ], - "url": { - "raw": "{{baseUrl}}/bookings/owner?from=1&size=1", - "host": [ - "{{baseUrl}}" - ], - "path": [ - "bookings", - "owner" - ], - "query": [ - { - "key": "from", - "value": "1" - }, - { - "key": "size", - "value": "1" - } - ] - } - }, - "response": [] - } - ] - } - ], - "variable": [ - { - "key": "baseUrl", - "value": "http://localhost:8080" - } - ] -} \ No newline at end of file From 6d362cbc1ded6f65aeb533057c51b5303f8f28bc Mon Sep 17 00:00:00 2001 From: boltaevt Date: Sat, 24 Jun 2023 23:23:13 +0500 Subject: [PATCH 3/7] changed gitIgnore file --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 549e00a..a9ce9d4 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ build/ ### VS Code ### .vscode/ + +.DS_Store From 6028f312e4a8ed8c47ab00dfdd4df36db8b4f189 Mon Sep 17 00:00:00 2001 From: boltaevt Date: Sat, 24 Jun 2023 23:25:20 +0500 Subject: [PATCH 4/7] changes to gitIgnore file --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a9ce9d4..1b251de 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,8 @@ build/ ### VS Code ### .vscode/ -.DS_Store +*.DS_Store + +*.class +*.jar + From da0fc148cb080215698d490a89a7e53898c985c9 Mon Sep 17 00:00:00 2001 From: boltaevt Date: Sat, 24 Jun 2023 23:35:16 +0500 Subject: [PATCH 5/7] again --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 1b251de..bc69d4b 100644 --- a/.gitignore +++ b/.gitignore @@ -36,4 +36,4 @@ build/ *.class *.jar - +.DS_Store From fb4253b443d4606faf1cd9725b0cbd866ab66f4e Mon Sep 17 00:00:00 2001 From: boltaevt Date: Sat, 24 Jun 2023 23:54:32 +0500 Subject: [PATCH 6/7] again --- .DS_Store | Bin 6148 -> 0 bytes gateway/.DS_Store | Bin 6148 -> 6148 bytes 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index 3ca1e8e15cc500f598f093707b48a20b666ca46b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKOKQVF43!c?4cTPbsj*Tp)oKZ%PWGY01v3oU2Fc(}z;ybW_NtJc0CP zG`!?eRn#(yw0j`Cye_b19)%p z{F8qi;?~sQ?wA0^bVQ_o2WIYvLH_pAG~c0e}tC zZdm&)0W6jP*2FOo8JGqY7*x#>LxYZd$-0_21_oU;hY!ssYfdQYPsjbm%SCG-BNdU0eU(!hf0nrzGyE02TOG3TV^s`VOy@y><3-)@uuV54W06xEa Date: Sun, 25 Jun 2023 00:01:03 +0500 Subject: [PATCH 7/7] Remove all .DS_Store files --- gateway/.DS_Store | Bin 6148 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 gateway/.DS_Store diff --git a/gateway/.DS_Store b/gateway/.DS_Store deleted file mode 100644 index 2eb9f42e30ad5e60b8ea7341014d48d75d1992f7..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKOKQU~5S>XvFm#hmAxl9|kQ+F`Ie{&idH3y0M) zzYF2SX+-Od0b`)gz&H+Pa{sUK%M2Fz{S+G+1IECWF~E~7&sNx!-mPcble^ZT-J^*} qTq_C$dhZc{ft(}r;EaAJI^t5rHloZT_K*&=hd?02I%D7u82AR|R5xn?