From 96be2954a767707f2978c0097eaaeaf6ffbdab90 Mon Sep 17 00:00:00 2001 From: kpetrosyan1 Date: Sat, 6 Apr 2024 19:52:31 +0400 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=A2=D0=97=2016=20-=20=D0=B4=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=B8=D1=82=D1=8C=20=D0=B4=D0=BE=D0=BA=D0=B5?= =?UTF-8?q?=D1=80=20=D0=B8=20=D0=BC=D0=BD=D0=BE=D0=B3=D0=BE=D0=BC=D0=BE?= =?UTF-8?q?=D0=B4=D1=83=D0=BB=D1=8C=D0=BD=D0=BE=D1=81=D1=82=D1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .run/ShareItGateway.run.xml | 15 + .run/ShareItServer.run.xml | 15 + checkstyle.xml | 16 +- docker-compose.yml | 36 + gateway/.gitignore | 38 + gateway/Dockerfile | 3 + gateway/pom.xml | 65 + .../java/ru/practicum/shareit/Constant.java | 0 .../ru/practicum/shareit/ShareItGateway.java | 12 + .../shareit/booking/BookingClient.java | 60 + .../shareit/booking/BookingController.java | 70 + .../booking/dto/BookItemRequestDto.java | 24 + .../shareit/booking/dto/BookingState.java | 27 + .../practicum/shareit/client/BaseClient.java | 121 + .../shareit/exception/ErrorHandler.java | 26 + .../shareit/exception/ErrorResponse.java | 12 + .../ru/practicum/shareit/item/ItemClient.java | 66 + .../shareit/item/ItemController.java | 79 + .../shareit/item/dto/CommentRequestDto.java | 17 + .../shareit/item/dto/ItemRequestDto.java | 21 + .../shareit/request/ItemRequestClient.java | 48 + .../request/ItemRequestController.java | 52 + .../request/dto/ItemRequestRequestDto.java | 8 +- .../ru/practicum/shareit/user/UserClient.java | 47 + .../shareit/user/UserController.java | 53 + .../shareit/user/dto/UserCreationDto.java | 8 +- .../shareit/user/dto/UserRequestDto.java | 10 +- .../src/main/resources/application.properties | 7 + pom.xml | 102 +- postman/sprint.json | 11050 ++++++++++++++++ server/.gitignore | 38 + server/Dockerfile | 3 + server/pom.xml | 86 + .../java/ru/practicum/shareit/Constant.java | 5 + .../ru/practicum/shareit/ShareItServer.java | 4 +- .../booking/controller/BookingController.java | 15 +- .../dto/BookingDtoWithItemAndUser.java | 0 .../shareit/booking/dto/BookingMapper.java | 0 .../booking/dto/BookingRequestDto.java | 8 - .../booking/dto/BookingResponseDto.java | 0 .../shareit/booking/model/Booking.java | 0 .../shareit/booking/model/BookingStatus.java | 0 .../shareit/booking/model/State.java | 2 +- .../booking/repository/BookingStorage.java | 0 .../booking/service/BookingService.java | 0 .../service/impl/BookingServiceImpl.java | 4 +- .../exception/controller/ErrorHandler.java | 15 +- .../exceptions/BadRequestException.java | 0 .../exceptions/NotEnoughRightsException.java | 0 .../exceptions/NotFoundException.java | 0 .../exception/model/ErrorResponse.java | 0 .../shareit/item/comment/Comment.java | 0 .../shareit/item/comment/CommentMapper.java | 0 .../item/comment/CommentRequestDto.java | 5 - .../item/comment/CommentResponseDto.java | 0 .../shareit/item/comment/CommentStorage.java | 0 .../item/controller/ItemController.java | 17 +- .../shareit/item/dto/ItemMapper.java | 0 .../shareit/item/dto/ItemRequestDto.java | 6 - .../shareit/item/dto/ItemResponseDto.java | 0 .../item/dto/ItemResponseDtoWithBookings.java | 0 .../ru/practicum/shareit/item/model/Item.java | 0 .../shareit/item/repository/ItemStorage.java | 0 .../shareit/item/service/ItemService.java | 0 .../item/service/impl/ItemServiceImpl.java | 0 .../controller/ItemRequestController.java | 12 +- .../request/dto/ItemRequestMapper.java | 0 .../request/dto/ItemRequestRequestDto.java | 8 + .../request/dto/ItemRequestResponseDto.java | 0 .../shareit/request/model/ItemRequest.java | 0 .../repository/ItemRequestStorage.java | 0 .../request/service/ItemRequestService.java | 0 .../service/impl/ItemRequestServiceImpl.java | 0 .../user/controller/UserController.java | 13 +- .../shareit/user/dto/UserMapper.java | 7 - .../shareit/user/dto/UserRequestDto.java | 9 + .../shareit/user/dto/UserResponseDto.java | 0 .../ru/practicum/shareit/user/model/User.java | 0 .../shareit/user/repository/UserStorage.java | 0 .../shareit/user/service/UserService.java | 3 +- .../user/service/impl/UserServiceImpl.java | 5 +- .../src/main/resources/application.properties | 18 + {src => server/src}/main/resources/schema.sql | 0 .../ru/practicum/shareit/ShareItTests.java | 0 .../booking/BookingControllerTest.java | 48 - .../shareit/booking/BookingServiceTest.java | 0 .../shareit/booking/BookingStorageTest.java | 0 .../shareit/item/ItemControllerTest.java | 48 - .../shareit/item/ItemIntegrationTest.java | 0 .../shareit/item/ItemServiceTest.java | 0 .../shareit/item/ItemStorageTest.java | 0 .../request/ItemRequestControllerTest.java | 14 - .../request/ItemRequestIntegrationTest.java | 0 .../request/ItemRequestServiceTest.java | 0 .../request/ItemRequestStorageTest.java | 0 .../shareit/user/UserControllerTest.java | 36 +- .../shareit/user/UserIntegrateTest.java | 36 +- .../shareit/user/UserServiceTest.java | 5 +- src/main/resources/application.properties | 20 - 99 files changed, 12246 insertions(+), 352 deletions(-) create mode 100644 .run/ShareItGateway.run.xml create mode 100644 .run/ShareItServer.run.xml create mode 100644 docker-compose.yml create mode 100644 gateway/.gitignore create mode 100644 gateway/Dockerfile create mode 100644 gateway/pom.xml rename {src => gateway/src}/main/java/ru/practicum/shareit/Constant.java (100%) 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 create mode 100644 gateway/src/main/java/ru/practicum/shareit/booking/dto/BookItemRequestDto.java 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/exception/ErrorHandler.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/exception/ErrorResponse.java 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 create mode 100644 gateway/src/main/java/ru/practicum/shareit/item/dto/CommentRequestDto.java create mode 100644 gateway/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java 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/ItemRequestRequestDto.java (76%) 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/UserCreationDto.java (77%) rename {src => gateway/src}/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java (64%) create mode 100644 gateway/src/main/resources/application.properties create mode 100644 postman/sprint.json create mode 100644 server/.gitignore create mode 100644 server/Dockerfile create mode 100644 server/pom.xml create mode 100644 server/src/main/java/ru/practicum/shareit/Constant.java rename src/main/java/ru/practicum/shareit/ShareItApp.java => server/src/main/java/ru/practicum/shareit/ShareItServer.java (72%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/controller/BookingController.java (85%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/dto/BookingDtoWithItemAndUser.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/dto/BookingMapper.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/dto/BookingRequestDto.java (53%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/dto/BookingResponseDto.java (100%) 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/BookingStatus.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/model/State.java (90%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/repository/BookingStorage.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/service/BookingService.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/booking/service/impl/BookingServiceImpl.java (98%) rename {src => server/src}/main/java/ru/practicum/shareit/exception/controller/ErrorHandler.java (80%) rename {src => server/src}/main/java/ru/practicum/shareit/exception/exceptions/BadRequestException.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/exception/exceptions/NotEnoughRightsException.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/exception/exceptions/NotFoundException.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/exception/model/ErrorResponse.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/comment/Comment.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/comment/CommentMapper.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/comment/CommentRequestDto.java (51%) rename {src => server/src}/main/java/ru/practicum/shareit/item/comment/CommentResponseDto.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/comment/CommentStorage.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/controller/ItemController.java (86%) rename {src => server/src}/main/java/ru/practicum/shareit/item/dto/ItemMapper.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java (61%) rename {src => server/src}/main/java/ru/practicum/shareit/item/dto/ItemResponseDto.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/dto/ItemResponseDtoWithBookings.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/model/Item.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/repository/ItemStorage.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/service/ItemService.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/item/service/impl/ItemServiceImpl.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java (84%) rename {src => server/src}/main/java/ru/practicum/shareit/request/dto/ItemRequestMapper.java (100%) create mode 100644 server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java rename {src => server/src}/main/java/ru/practicum/shareit/request/dto/ItemRequestResponseDto.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/ItemRequestStorage.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 (76%) rename {src => server/src}/main/java/ru/practicum/shareit/user/dto/UserMapper.java (74%) create mode 100644 server/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java rename {src => server/src}/main/java/ru/practicum/shareit/user/dto/UserResponseDto.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/user/model/User.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/user/repository/UserStorage.java (100%) rename {src => server/src}/main/java/ru/practicum/shareit/user/service/UserService.java (77%) rename {src => server/src}/main/java/ru/practicum/shareit/user/service/impl/UserServiceImpl.java (94%) create mode 100644 server/src/main/resources/application.properties rename {src => server/src}/main/resources/schema.sql (100%) rename {src => server/src}/test/java/ru/practicum/shareit/ShareItTests.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/booking/BookingControllerTest.java (72%) rename {src => server/src}/test/java/ru/practicum/shareit/booking/BookingServiceTest.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/booking/BookingStorageTest.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/item/ItemControllerTest.java (78%) rename {src => server/src}/test/java/ru/practicum/shareit/item/ItemIntegrationTest.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/item/ItemServiceTest.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/item/ItemStorageTest.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/request/ItemRequestControllerTest.java (87%) rename {src => server/src}/test/java/ru/practicum/shareit/request/ItemRequestIntegrationTest.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/request/ItemRequestServiceTest.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/request/ItemRequestStorageTest.java (100%) rename {src => server/src}/test/java/ru/practicum/shareit/user/UserControllerTest.java (76%) rename {src => server/src}/test/java/ru/practicum/shareit/user/UserIntegrateTest.java (70%) rename {src => server/src}/test/java/ru/practicum/shareit/user/UserServiceTest.java (96%) delete mode 100644 src/main/resources/application.properties diff --git a/.run/ShareItGateway.run.xml b/.run/ShareItGateway.run.xml new file mode 100644 index 0000000..32c8129 --- /dev/null +++ b/.run/ShareItGateway.run.xml @@ -0,0 +1,15 @@ + + + + \ No newline at end of file diff --git a/.run/ShareItServer.run.xml b/.run/ShareItServer.run.xml new file mode 100644 index 0000000..f4806d2 --- /dev/null +++ b/.run/ShareItServer.run.xml @@ -0,0 +1,15 @@ + + + + \ No newline at end of file diff --git a/checkstyle.xml b/checkstyle.xml index 74f37d8..41b0212 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -158,14 +158,14 @@ - - - - - - - - + + + + + + + + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..3f13126 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,36 @@ +version: '3.8' +services: + gateway: + build: gateway + image: gateway-image + container_name: gateway-container + ports: + - "8080:8080" + depends_on: + - server + environment: + - SHAREIT_SERVER_URL=http://server:9090 + + server: + build: server + image: server-image + container_name: server-container + ports: + - "9090:9090" + depends_on: + - db + environment: + - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/shareIt + - SPRING_DATASOURCE_USERNAME=root + - SPRING_DATASOURCE_PASSWORD=root + - SPRING_DRIVER_CLASS_NAME=org.postgresql.Driver + + db: + image: postgres:14-alpine + container_name: db-container + ports: + - "6541:5432" + environment: + - POSTGRES_PASSWORD=root + - POSTGRES_USER=root + - POSTGRES_DB=shareIt \ No newline at end of file diff --git a/gateway/.gitignore b/gateway/.gitignore new file mode 100644 index 0000000..5ff6309 --- /dev/null +++ b/gateway/.gitignore @@ -0,0 +1,38 @@ +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/gateway/Dockerfile b/gateway/Dockerfile new file mode 100644 index 0000000..2118327 --- /dev/null +++ b/gateway/Dockerfile @@ -0,0 +1,3 @@ +FROM amazoncorretto:11-alpine-jdk +COPY 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..ce8b4aa --- /dev/null +++ b/gateway/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + ru.practicum + shareit + 0.0.1-SNAPSHOT + + + shareit-gateway + 0.0.1-SNAPSHOT + + ShareIt Gateway + + + + 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 + + + + + diff --git a/src/main/java/ru/practicum/shareit/Constant.java b/gateway/src/main/java/ru/practicum/shareit/Constant.java similarity index 100% rename from src/main/java/ru/practicum/shareit/Constant.java rename to gateway/src/main/java/ru/practicum/shareit/Constant.java 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..0aa75c3 --- /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); + } + +} 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..ec87dab --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/booking/BookingClient.java @@ -0,0 +1,60 @@ +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.util.DefaultUriBuilderFactory; +import ru.practicum.shareit.booking.dto.BookItemRequestDto; +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 getBookings(long userId, BookingState state, Integer from, Integer size) { + Map parameters = Map.of( + "state", state.name(), + "from", from, + "size", size + ); + return get("?state={state}&from={from}&size={size}", userId, parameters); + } + + + public ResponseEntity bookItem(long userId, BookItemRequestDto requestDto) { + return post("", userId, requestDto); + } + + public ResponseEntity getBooking(long userId, Long bookingId) { + return get("/" + bookingId, userId); + } + + public ResponseEntity updateBooking(long userId, Long bookingId, Boolean approved) { + return patch("/" + bookingId + "?approved=" + approved, userId); + } + + public ResponseEntity getOwnerBookings(long userId, BookingState state, Integer from, Integer size) { + Map parameters = Map.of( + "state", state.name(), + "from", from, + "size", size + ); + return get("/owner?state={state}&from={from}&size={size}", userId, parameters); + } +} 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..cf28497 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/booking/BookingController.java @@ -0,0 +1,70 @@ +package ru.practicum.shareit.booking; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import ru.practicum.shareit.booking.dto.BookItemRequestDto; +import ru.practicum.shareit.booking.dto.BookingState; + +import javax.validation.Valid; +import javax.validation.constraints.Positive; +import javax.validation.constraints.PositiveOrZero; + +import static ru.practicum.shareit.Constant.USER_HEADER; + +@Controller +@RequestMapping(path = "/bookings") +@RequiredArgsConstructor +@Slf4j +@Validated +public class BookingController { + private final BookingClient bookingClient; + + @GetMapping + public ResponseEntity getBookings(@RequestHeader(USER_HEADER) long userId, + @RequestParam(name = "state", defaultValue = "all") String stateParam, + @PositiveOrZero @RequestParam (name = "from", defaultValue = "0") Integer from, + @Positive @RequestParam (name = "size", defaultValue = "10") Integer size) { + BookingState state = BookingState.from(stateParam) + .orElseThrow(() -> new IllegalArgumentException("Unknown state: " + stateParam)); + log.info("BOOKING_GATEWAY: Get booking with state {}, userId={}, from={}, size={}", stateParam, userId, from, size); + return bookingClient.getBookings(userId, state, from, size); + } + + @PostMapping + public ResponseEntity bookItem(@RequestHeader(USER_HEADER) long userId, + @RequestBody @Valid BookItemRequestDto requestDto) { + log.info("BOOKING_GATEWAY: Creating booking {}, userId={}", requestDto, userId); + return bookingClient.bookItem(userId, requestDto); + } + + @GetMapping("/{bookingId}") + public ResponseEntity getBooking(@RequestHeader(USER_HEADER) long userId, + @PathVariable Long bookingId) { + log.info("BOOKING_GATEWAY: Get booking {}, userId={}", bookingId, userId); + return bookingClient.getBooking(userId, bookingId); + } + + @PatchMapping("/{bookingId}") + public ResponseEntity updateBooking(@RequestHeader(USER_HEADER) @Positive long userId, + @PathVariable @Positive Long bookingId, + @RequestParam Boolean approved) { + log.info("BOOKING_GATEWAY: Update booking {}, userId={}", bookingId, userId); + return bookingClient.updateBooking(userId, bookingId, approved); + } + + @GetMapping("/owner") + public ResponseEntity getOwnerBookings(@RequestHeader(USER_HEADER) long userId, + @RequestParam(name = "state", defaultValue = "all") String stateParam, + @PositiveOrZero @RequestParam(name = "from", defaultValue = "0") Integer from, + @Positive @RequestParam(name = "size", defaultValue = "10") Integer size) { + log.info("BOOKING_GATEWAY: Get booking with state {}, ownerId={}, from={}, size={}", stateParam, userId, from, size); + BookingState state = BookingState.from(stateParam) + .orElseThrow(() -> new IllegalArgumentException("Unknown state: " + stateParam)); + return bookingClient.getOwnerBookings(userId, state, from, size); + } +} \ No newline at end of file diff --git a/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookItemRequestDto.java b/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookItemRequestDto.java new file mode 100644 index 0000000..3b09d62 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookItemRequestDto.java @@ -0,0 +1,24 @@ +package ru.practicum.shareit.booking.dto; + +import java.time.LocalDateTime; + +import javax.validation.constraints.Future; +import javax.validation.constraints.FutureOrPresent; +import javax.validation.constraints.NotNull; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class BookItemRequestDto { + private long itemId; + @NotNull(message = "Дата начала брони не может быть null") + @FutureOrPresent(message = "Дата начала брони не может быть в прошлом") + private LocalDateTime start; + @NotNull(message = "Дата завершения брони не может быть null") + @Future(message = "Дата завершения брони должна быть в будущем") + private LocalDateTime end; +} 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..7bfa164 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookingState.java @@ -0,0 +1,27 @@ +package ru.practicum.shareit.booking.dto; + +import java.util.Optional; + +public enum BookingState { + // Все + ALL, + // Текущие + CURRENT, + // Будущие + FUTURE, + // Завершенные + PAST, + // Отклоненные + REJECTED, + // Ожидающие подтверждения + WAITING; + + public static Optional from(String stringState) { + for (BookingState state : values()) { + if (state.name().equalsIgnoreCase(stringState)) { + return Optional.of(state); + } + } + return Optional.empty(); + } +} 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..1a2d33a --- /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(); + } +} diff --git a/gateway/src/main/java/ru/practicum/shareit/exception/ErrorHandler.java b/gateway/src/main/java/ru/practicum/shareit/exception/ErrorHandler.java new file mode 100644 index 0000000..9f48762 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/exception/ErrorHandler.java @@ -0,0 +1,26 @@ +package ru.practicum.shareit.exception; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; +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; + +@RestControllerAdvice +@Slf4j +public class ErrorHandler { + @ExceptionHandler + @ResponseStatus(HttpStatus.BAD_REQUEST) + public ErrorResponse handleMethodArgumentNotValidException(final MethodArgumentNotValidException e) { + e.printStackTrace(); + return new ErrorResponse(e.getMessage()); + } + + @ExceptionHandler + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + public ErrorResponse handleException(final Exception e) { + e.printStackTrace(); + return new ErrorResponse(e.getMessage()); + } +} diff --git a/gateway/src/main/java/ru/practicum/shareit/exception/ErrorResponse.java b/gateway/src/main/java/ru/practicum/shareit/exception/ErrorResponse.java new file mode 100644 index 0000000..34057b2 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/exception/ErrorResponse.java @@ -0,0 +1,12 @@ +package ru.practicum.shareit.exception; + +import lombok.Getter; + +@Getter +public class ErrorResponse { + private final String error; + + public ErrorResponse(String error) { + this.error = error; + } +} 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..a816fc2 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/item/ItemClient.java @@ -0,0 +1,66 @@ +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.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.item.dto.CommentRequestDto; +import ru.practicum.shareit.item.dto.ItemRequestDto; + +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 addItem(long userId, ItemRequestDto itemRequestDto) { + return post("", userId, itemRequestDto); + } + + public ResponseEntity commentItem(long userId, Long itemId, CommentRequestDto commentRequestDto) { + return post(String.format("/%d/comment", itemId), userId, commentRequestDto); + } + + public ResponseEntity updateItem(long userId, Long itemId, ItemRequestDto itemRequestDto) { + return patch(String.format("/%d", itemId), userId, itemRequestDto); + } + + public ResponseEntity getItem(long userId, Long itemId) { + return get(String.format("/%d", itemId), userId); + } + + public ResponseEntity getOwnerItems(long userId, int from, int size) { + Map parameters = Map.of( + "from", from, + "size", size + ); + return get("?from={from}&size={size}", userId, parameters); + } + + public ResponseEntity search(long userId, String text, int from, int size) { + Map parameters = Map.of( + "text", text, + "from", from, + "size", size + ); + return get("/search?text={text}&from={from}&size={size}", userId, parameters); + } + + public ResponseEntity deleteItem(long userId, Long itemId) { + return delete(String.format("/%d", itemId), userId); + } +} 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..0058839 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/item/ItemController.java @@ -0,0 +1,79 @@ +package ru.practicum.shareit.item; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import ru.practicum.shareit.item.dto.CommentRequestDto; +import ru.practicum.shareit.item.dto.ItemRequestDto; + +import javax.validation.Valid; +import javax.validation.constraints.Positive; +import javax.validation.constraints.PositiveOrZero; + +import static ru.practicum.shareit.Constant.USER_HEADER; + +@Controller +@RequestMapping(path = "/items") +@RequiredArgsConstructor +@Slf4j +@Validated +public class ItemController { + private final ItemClient itemClient; + + @PostMapping + public ResponseEntity addItem(@RequestHeader(USER_HEADER) @Positive long userId, + @RequestBody @Valid ItemRequestDto itemRequestDto) { + log.info("ITEM_GATEWAY: add item {} from user userId={}", itemRequestDto, userId); + return itemClient.addItem(userId, itemRequestDto); + } + + @PostMapping("/{itemId}/comment") + public ResponseEntity commentItem(@RequestHeader(USER_HEADER) @Positive long userId, + @PathVariable @Positive Long itemId, + @RequestBody @Valid CommentRequestDto commentRequestDto) { + log.info("ITEM_GATEWAY: add comment {} to item itemId={} from user userId={}", commentRequestDto, itemId, userId); + return itemClient.commentItem(userId, itemId, commentRequestDto); + } + + @PatchMapping("/{itemId}") + public ResponseEntity updateItem(@RequestHeader(USER_HEADER) @Positive long userId, + @PathVariable @Positive Long itemId, + @RequestBody ItemRequestDto itemRequestDto) { + log.info("ITEM_GATEWAY: update item itemId={} from user userId={} by dto {}", itemId, userId, itemRequestDto); + return itemClient.updateItem(userId, itemId, itemRequestDto); + } + + @GetMapping("/{itemId}") + public ResponseEntity getItem(@RequestHeader(USER_HEADER) @Positive long userId, + @PathVariable @Positive Long itemId) { + log.info("ITEM_GATEWAY: get item itemId={} request from user userId={}", itemId, userId); + return itemClient.getItem(userId, itemId); + } + + @GetMapping + public ResponseEntity getOwnerItems(@RequestHeader(USER_HEADER) @Positive long userId, + @RequestParam(defaultValue = "0") @PositiveOrZero int from, + @RequestParam(defaultValue = "10") @PositiveOrZero int size) { + log.info("ITEM_GATEWAY: find owner ownerId={} items, page from={} size={}", userId, from, size); + return itemClient.getOwnerItems(userId, from, size); + } + + @GetMapping("/search") + public ResponseEntity search(@RequestHeader(USER_HEADER) @Positive long userId, + @RequestParam String text, + @RequestParam(defaultValue = "0") @PositiveOrZero int from, + @RequestParam(defaultValue = "10") @PositiveOrZero int size) { + log.info("ITEM_GATEWAY: search items by string {}, page from={} size={}", text, from, size); + return itemClient.search(userId, text, from, size); + } + + @DeleteMapping("/{itemId}") + public ResponseEntity deleteItem(@RequestHeader(USER_HEADER) @Positive long userId, + @PathVariable @Positive Long itemId) { + log.info("ITEM_GATEWAY: delete item itemId={} request from user userId={}", itemId, userId); + return itemClient.deleteItem(userId, itemId); + } +} \ No newline at end of file diff --git a/gateway/src/main/java/ru/practicum/shareit/item/dto/CommentRequestDto.java b/gateway/src/main/java/ru/practicum/shareit/item/dto/CommentRequestDto.java new file mode 100644 index 0000000..f2b64a2 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/item/dto/CommentRequestDto.java @@ -0,0 +1,17 @@ +package ru.practicum.shareit.item.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.Size; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class CommentRequestDto { + @NotBlank(message = "текст комментария не может быть пустым") + @Size(max = 512, message = "размер комментария не может превышать 512 символов") + private String text; +} diff --git a/gateway/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java b/gateway/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java new file mode 100644 index 0000000..167afe2 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java @@ -0,0 +1,21 @@ +package ru.practicum.shareit.item.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class ItemRequestDto { + @NotBlank(message = "Название вещи не может быть пустым") + private String name; + @NotBlank(message = "Описание вещи не может быть пустым") + private String description; + @NotNull(message = "Необходимо указать доступность вещи для аренды") + private Boolean available; + private Long requestId; +} 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..5e4ad03 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestClient.java @@ -0,0 +1,48 @@ +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.ItemRequestRequestDto; + +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(long userId, ItemRequestRequestDto itemRequestRequestDto) { + return post("", userId, itemRequestRequestDto); + } + + public ResponseEntity getRequestsByAuthor(long userId) { + return get("", userId); + } + + public ResponseEntity getItemRequests(long userId, int from, int size) { + Map parameters = Map.of( + "from", from, + "size", size + ); + return get("/all?from={from}&size={size}", userId, parameters); + } + + public ResponseEntity getItemRequest(long userId, Long requestId) { + return get(String.format("/%d", requestId), userId); + } +} \ 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..4992ca1 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/request/ItemRequestController.java @@ -0,0 +1,52 @@ +package ru.practicum.shareit.request; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import ru.practicum.shareit.request.dto.ItemRequestRequestDto; + +import javax.validation.Valid; +import javax.validation.constraints.Positive; +import javax.validation.constraints.PositiveOrZero; + +import static ru.practicum.shareit.Constant.USER_HEADER; + +@Controller +@RequestMapping(path = "/requests") +@RequiredArgsConstructor +@Slf4j +@Validated +public class ItemRequestController { + private final ItemRequestClient itemRequestClient; + + @PostMapping + public ResponseEntity addItemRequest(@RequestHeader(USER_HEADER) @Positive long userId, + @RequestBody @Valid ItemRequestRequestDto itemRequestRequestDto) { + log.info("ITEM_REQUEST_GATEWAY: add itemRequest {} from user userId={}", itemRequestRequestDto, userId); + return itemRequestClient.addItemRequest(userId, itemRequestRequestDto); + } + + @GetMapping + public ResponseEntity getRequestsByAuthor(@RequestHeader(USER_HEADER) @Positive long userId) { + log.info("ITEM_REQUEST_GATEWAY: get requests by authorId={}", userId); + return itemRequestClient.getRequestsByAuthor(userId); + } + + @GetMapping("/all") + public ResponseEntity getItemRequests(@RequestHeader(USER_HEADER) @Positive long userId, + @RequestParam(defaultValue = "0") @PositiveOrZero int from, + @RequestParam(defaultValue = "10") @Positive int size) { + log.info("ITEM_REQUEST_GATEWAY: get all requests from user userId={}, page from={}, size={}", userId, from, size); + return itemRequestClient.getItemRequests(userId, from, size); + } + + @GetMapping("/{requestId}") + public ResponseEntity getItemRequest(@RequestHeader(USER_HEADER) @Positive long userId, + @PathVariable @Positive Long requestId) { + log.info("ITEM_REQUEST_GATEWAY: get itemRequest by id={} from user userId={}", requestId, userId); + return itemRequestClient.getItemRequest(userId, requestId); + } +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java b/gateway/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java similarity index 76% rename from src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java rename to gateway/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java index 1e4a85d..84e5c25 100644 --- a/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java +++ b/gateway/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java @@ -1,11 +1,15 @@ package ru.practicum.shareit.request.dto; -import lombok.Data; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; import javax.validation.constraints.NotBlank; import javax.validation.constraints.Size; -@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor public class ItemRequestRequestDto { @NotBlank(message = "описание запроса не может быть пустым") @Size(max = 512, message = "Длина описания запроса не может превышать 512 символов") 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..ed40677 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/user/UserClient.java @@ -0,0 +1,47 @@ +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.util.DefaultUriBuilderFactory; +import ru.practicum.shareit.client.BaseClient; +import ru.practicum.shareit.user.dto.UserCreationDto; +import ru.practicum.shareit.user.dto.UserRequestDto; + +@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 getUsers() { + return get(""); + } + + public ResponseEntity getUser(long userId) { + return get("/" + userId); + } + + public ResponseEntity addUser(UserCreationDto userCreationDto) { + return post("", userCreationDto); + } + + public ResponseEntity updateUser(UserRequestDto userRequestDto, long userId) { + return patch("/" + userId, userRequestDto); + } + + public ResponseEntity deleteUser(long userId) { + return delete("/" + userId); + } +} 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..5075013 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/user/UserController.java @@ -0,0 +1,53 @@ +package ru.practicum.shareit.user; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; +import ru.practicum.shareit.user.dto.UserCreationDto; +import ru.practicum.shareit.user.dto.UserRequestDto; + +import javax.validation.Valid; +import javax.validation.constraints.Positive; + +@Controller +@RequestMapping(path = "/users") +@RequiredArgsConstructor +@Slf4j +@Validated +public class UserController { + private final UserClient userClient; + + @GetMapping + public ResponseEntity getUsers() { + log.info("USER_GATEWAY: Get all users"); + return userClient.getUsers(); + } + + @GetMapping("/{userId}") + public ResponseEntity getUser(@PathVariable @Positive long userId) { + log.info("USER_GATEWAY: Get user by userId={}", userId); + return userClient.getUser(userId); + } + + @PostMapping + public ResponseEntity addUser(@RequestBody @Valid UserCreationDto userCreationDto) { + log.info("USER_GATEWAY: Create new user {}", userCreationDto); + return userClient.addUser(userCreationDto); + } + + @PatchMapping("/{userId}") + public ResponseEntity updateUser(@RequestBody @Valid UserRequestDto userRequestDto, + @PathVariable @Positive long userId) { + log.info("USER_GATEWAY: Update user userId={} by data {}", userId, userRequestDto); + return userClient.updateUser(userRequestDto, userId); + } + + @DeleteMapping("/{userId}") + public ResponseEntity deleteUser(@PathVariable @Positive long userId) { + log.info("USER_GATEWAY: delete user userId={}", userId); + return userClient.deleteUser(userId); + } +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/user/dto/UserCreationDto.java b/gateway/src/main/java/ru/practicum/shareit/user/dto/UserCreationDto.java similarity index 77% rename from src/main/java/ru/practicum/shareit/user/dto/UserCreationDto.java rename to gateway/src/main/java/ru/practicum/shareit/user/dto/UserCreationDto.java index c48d19a..f8f9feb 100644 --- a/src/main/java/ru/practicum/shareit/user/dto/UserCreationDto.java +++ b/gateway/src/main/java/ru/practicum/shareit/user/dto/UserCreationDto.java @@ -1,11 +1,15 @@ package ru.practicum.shareit.user.dto; -import lombok.Data; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; import javax.validation.constraints.Email; import javax.validation.constraints.NotBlank; -@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor public class UserCreationDto { @NotBlank(message = "имя пользователя не может быть пустым") private String name; diff --git a/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java b/gateway/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java similarity index 64% rename from src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java rename to gateway/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java index c7dacb7..cf313f1 100644 --- a/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java +++ b/gateway/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java @@ -1,12 +1,16 @@ package ru.practicum.shareit.user.dto; -import lombok.Data; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; import javax.validation.constraints.Email; -@Data +@Getter +@NoArgsConstructor +@AllArgsConstructor public class UserRequestDto { private String name; @Email(message = "передан некорректный формат email") private String email; -} \ No newline at end of file +} 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 3092af6..b2796d9 100644 --- a/pom.xml +++ b/pom.xml @@ -5,89 +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 - - - org.jeasy - easy-random-core - 5.0.0 - - + + 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 @@ -234,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/.gitignore b/server/.gitignore new file mode 100644 index 0000000..79f99ea --- /dev/null +++ b/server/.gitignore @@ -0,0 +1,38 @@ +../server1/target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### IntelliJ IDEA ### +.idea/modules.xml +.idea/jarRepositories.xml +.idea/compiler.xml +.idea/libraries/ +*.iws +*.iml +*.ipr + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..2118327 --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,3 @@ +FROM amazoncorretto:11-alpine-jdk +COPY target/*.jar app.jar +ENTRYPOINT ["java","-jar","/app.jar"] \ No newline at end of file diff --git a/server/pom.xml b/server/pom.xml new file mode 100644 index 0000000..584f63d --- /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 + + + + + + + diff --git a/server/src/main/java/ru/practicum/shareit/Constant.java b/server/src/main/java/ru/practicum/shareit/Constant.java new file mode 100644 index 0000000..4486521 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/Constant.java @@ -0,0 +1,5 @@ +package ru.practicum.shareit; + +public class Constant { + public static final String USER_HEADER = "X-Sharer-User-Id"; +} diff --git a/src/main/java/ru/practicum/shareit/ShareItApp.java b/server/src/main/java/ru/practicum/shareit/ShareItServer.java similarity index 72% rename from src/main/java/ru/practicum/shareit/ShareItApp.java rename to server/src/main/java/ru/practicum/shareit/ShareItServer.java index 0151768..b872e4f 100644 --- a/src/main/java/ru/practicum/shareit/ShareItApp.java +++ b/server/src/main/java/ru/practicum/shareit/ShareItServer.java @@ -4,9 +4,9 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class ShareItApp { +public class ShareItServer { public static void main(String[] args) { - SpringApplication.run(ShareItApp.class, args); + SpringApplication.run(ShareItServer.class, args); } } \ No newline at end of file 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 85% 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 6ffb7a9..a7378cb 100644 --- a/src/main/java/ru/practicum/shareit/booking/controller/BookingController.java +++ b/server/src/main/java/ru/practicum/shareit/booking/controller/BookingController.java @@ -2,29 +2,24 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import ru.practicum.shareit.booking.dto.BookingRequestDto; import ru.practicum.shareit.booking.dto.BookingDtoWithItemAndUser; import ru.practicum.shareit.booking.service.BookingService; -import javax.validation.Valid; -import javax.validation.constraints.Positive; -import javax.validation.constraints.PositiveOrZero; import java.util.List; import static ru.practicum.shareit.Constant.USER_HEADER; @RestController @RequiredArgsConstructor -@Validated @Slf4j @RequestMapping(path = "/bookings") public class BookingController { private final BookingService service; @PostMapping - public BookingDtoWithItemAndUser addRequest(@RequestBody @Valid BookingRequestDto bookingRequestDto, + public BookingDtoWithItemAndUser addRequest(@RequestBody BookingRequestDto bookingRequestDto, @RequestHeader(USER_HEADER) Long userId) { log.info("BookingController: обработка запроса на добавление бронирования"); return service.addRequest(bookingRequestDto, userId); @@ -47,8 +42,8 @@ public BookingDtoWithItemAndUser findById(@RequestHeader(USER_HEADER) Long reque @GetMapping public List findAllByUserAndState(@RequestHeader(USER_HEADER) Long requesterId, @RequestParam(defaultValue = "ALL") String state, - @RequestParam(defaultValue = "0") @PositiveOrZero int from, - @RequestParam(defaultValue = "20") @Positive int size) { + @RequestParam(defaultValue = "0") int from, + @RequestParam(defaultValue = "10") int size) { log.info("BookingController: обработка запроса от пользователя {} на поиск бронирований по состоянию {}", requesterId, state); return service.findAllByUserAndState(requesterId, state, from, size); @@ -57,8 +52,8 @@ public List findAllByUserAndState(@RequestHeader(USER @GetMapping("/owner") public List findAllByOwnerAndState(@RequestHeader(USER_HEADER) Long ownerId, @RequestParam(defaultValue = "ALL") String state, - @RequestParam(defaultValue = "0") @PositiveOrZero int from, - @RequestParam(defaultValue = "20") @Positive int size) { + @RequestParam(defaultValue = "0") int from, + @RequestParam(defaultValue = "10") int size) { log.info("BookingController: обработка запроса от пользователя {} на поиск всех бронирований его вещей с " + "состоянием {}", ownerId, state); return service.findAllByOwnerAndState(ownerId, state, from, size); diff --git a/src/main/java/ru/practicum/shareit/booking/dto/BookingDtoWithItemAndUser.java b/server/src/main/java/ru/practicum/shareit/booking/dto/BookingDtoWithItemAndUser.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/dto/BookingDtoWithItemAndUser.java rename to server/src/main/java/ru/practicum/shareit/booking/dto/BookingDtoWithItemAndUser.java 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/src/main/java/ru/practicum/shareit/booking/dto/BookingRequestDto.java b/server/src/main/java/ru/practicum/shareit/booking/dto/BookingRequestDto.java similarity index 53% rename from src/main/java/ru/practicum/shareit/booking/dto/BookingRequestDto.java rename to server/src/main/java/ru/practicum/shareit/booking/dto/BookingRequestDto.java index 8140e2d..67c31cf 100644 --- a/src/main/java/ru/practicum/shareit/booking/dto/BookingRequestDto.java +++ b/server/src/main/java/ru/practicum/shareit/booking/dto/BookingRequestDto.java @@ -2,19 +2,11 @@ import lombok.Data; -import javax.validation.constraints.Future; -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Positive; import java.time.LocalDateTime; @Data public class BookingRequestDto { - @Positive private Long itemId; - @Future - @NotNull private LocalDateTime start; - @Future - @NotNull private LocalDateTime end; } \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/booking/dto/BookingResponseDto.java b/server/src/main/java/ru/practicum/shareit/booking/dto/BookingResponseDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/dto/BookingResponseDto.java rename to server/src/main/java/ru/practicum/shareit/booking/dto/BookingResponseDto.java 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/BookingStatus.java b/server/src/main/java/ru/practicum/shareit/booking/model/BookingStatus.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/model/BookingStatus.java rename to server/src/main/java/ru/practicum/shareit/booking/model/BookingStatus.java diff --git a/src/main/java/ru/practicum/shareit/booking/model/State.java b/server/src/main/java/ru/practicum/shareit/booking/model/State.java similarity index 90% rename from src/main/java/ru/practicum/shareit/booking/model/State.java rename to server/src/main/java/ru/practicum/shareit/booking/model/State.java index d97041a..9c41d9f 100644 --- a/src/main/java/ru/practicum/shareit/booking/model/State.java +++ b/server/src/main/java/ru/practicum/shareit/booking/model/State.java @@ -12,7 +12,7 @@ public enum State { WAITING, REJECTED; - public State stringToState(String state) { + public static State stringToState(String state) { log.info("StateEnum: Конвертация строки {} в Enum State", state); try { return valueOf(state); diff --git a/src/main/java/ru/practicum/shareit/booking/repository/BookingStorage.java b/server/src/main/java/ru/practicum/shareit/booking/repository/BookingStorage.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/repository/BookingStorage.java rename to server/src/main/java/ru/practicum/shareit/booking/repository/BookingStorage.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/impl/BookingServiceImpl.java b/server/src/main/java/ru/practicum/shareit/booking/service/impl/BookingServiceImpl.java similarity index 98% rename from src/main/java/ru/practicum/shareit/booking/service/impl/BookingServiceImpl.java rename to server/src/main/java/ru/practicum/shareit/booking/service/impl/BookingServiceImpl.java index 6c7258d..a47bc4e 100644 --- a/src/main/java/ru/practicum/shareit/booking/service/impl/BookingServiceImpl.java +++ b/server/src/main/java/ru/practicum/shareit/booking/service/impl/BookingServiceImpl.java @@ -101,7 +101,7 @@ public List findAllByUserAndState(Long userId, String stateString, userId); userStorage.findById(userId).orElseThrow(() -> new NotFoundException( String.format("Пользователь с id %d не найден", userId))); - State state = State.ALL.stringToState(stateString); + State state = State.stringToState(stateString); PageRequest pageRequest = PageRequest.of((from / size), size, sortStartDesc); List bookings = new ArrayList<>(); switch (state) { @@ -137,7 +137,7 @@ public List findAllByOwnerAndState(Long ownerId, Stri throw new NotFoundException(String.format("У пользователя с id %d нет вещей в собственности", ownerId)); } List bookings = new ArrayList<>(); - State state = State.ALL.stringToState(stateString); + State state = State.stringToState(stateString); PageRequest pageRequest = PageRequest.of((from / size), size, sortStartDesc); switch (state) { case ALL: diff --git a/src/main/java/ru/practicum/shareit/exception/controller/ErrorHandler.java b/server/src/main/java/ru/practicum/shareit/exception/controller/ErrorHandler.java similarity index 80% rename from src/main/java/ru/practicum/shareit/exception/controller/ErrorHandler.java rename to server/src/main/java/ru/practicum/shareit/exception/controller/ErrorHandler.java index 020ba2b..516fe03 100644 --- a/src/main/java/ru/practicum/shareit/exception/controller/ErrorHandler.java +++ b/server/src/main/java/ru/practicum/shareit/exception/controller/ErrorHandler.java @@ -10,29 +10,34 @@ import ru.practicum.shareit.exception.exceptions.NotFoundException; import ru.practicum.shareit.exception.model.ErrorResponse; -import java.util.Arrays; - @RestControllerAdvice @Slf4j public class ErrorHandler { @ExceptionHandler @ResponseStatus(HttpStatus.NOT_FOUND) public ErrorResponse handleNotFoundException(final NotFoundException e) { - log.info(Arrays.toString(e.getStackTrace())); + e.printStackTrace(); return new ErrorResponse(e.getMessage()); } @ExceptionHandler @ResponseStatus(HttpStatus.BAD_REQUEST) public ErrorResponse handleMethodArgumentNotValidException(final MethodArgumentNotValidException e) { - log.info(Arrays.toString(e.getStackTrace())); + e.printStackTrace(); return new ErrorResponse(e.getMessage()); } @ExceptionHandler @ResponseStatus(HttpStatus.BAD_REQUEST) public ErrorResponse handleBadRequestException(final BadRequestException e) { - log.info(Arrays.toString(e.getStackTrace())); + e.printStackTrace(); + return new ErrorResponse(e.getMessage()); + } + + @ExceptionHandler + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + public ErrorResponse handleException(final Exception e) { + e.printStackTrace(); return new ErrorResponse(e.getMessage()); } } \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/exception/exceptions/BadRequestException.java b/server/src/main/java/ru/practicum/shareit/exception/exceptions/BadRequestException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/exceptions/BadRequestException.java rename to server/src/main/java/ru/practicum/shareit/exception/exceptions/BadRequestException.java diff --git a/src/main/java/ru/practicum/shareit/exception/exceptions/NotEnoughRightsException.java b/server/src/main/java/ru/practicum/shareit/exception/exceptions/NotEnoughRightsException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/exceptions/NotEnoughRightsException.java rename to server/src/main/java/ru/practicum/shareit/exception/exceptions/NotEnoughRightsException.java diff --git a/src/main/java/ru/practicum/shareit/exception/exceptions/NotFoundException.java b/server/src/main/java/ru/practicum/shareit/exception/exceptions/NotFoundException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/exceptions/NotFoundException.java rename to server/src/main/java/ru/practicum/shareit/exception/exceptions/NotFoundException.java diff --git a/src/main/java/ru/practicum/shareit/exception/model/ErrorResponse.java b/server/src/main/java/ru/practicum/shareit/exception/model/ErrorResponse.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/model/ErrorResponse.java rename to server/src/main/java/ru/practicum/shareit/exception/model/ErrorResponse.java diff --git a/src/main/java/ru/practicum/shareit/item/comment/Comment.java b/server/src/main/java/ru/practicum/shareit/item/comment/Comment.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/comment/Comment.java rename to server/src/main/java/ru/practicum/shareit/item/comment/Comment.java diff --git a/src/main/java/ru/practicum/shareit/item/comment/CommentMapper.java b/server/src/main/java/ru/practicum/shareit/item/comment/CommentMapper.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/comment/CommentMapper.java rename to server/src/main/java/ru/practicum/shareit/item/comment/CommentMapper.java diff --git a/src/main/java/ru/practicum/shareit/item/comment/CommentRequestDto.java b/server/src/main/java/ru/practicum/shareit/item/comment/CommentRequestDto.java similarity index 51% rename from src/main/java/ru/practicum/shareit/item/comment/CommentRequestDto.java rename to server/src/main/java/ru/practicum/shareit/item/comment/CommentRequestDto.java index 407e340..817ac1c 100644 --- a/src/main/java/ru/practicum/shareit/item/comment/CommentRequestDto.java +++ b/server/src/main/java/ru/practicum/shareit/item/comment/CommentRequestDto.java @@ -2,12 +2,7 @@ import lombok.Data; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.Size; - @Data public class CommentRequestDto { - @NotBlank - @Size(max = 512) private String text; } diff --git a/src/main/java/ru/practicum/shareit/item/comment/CommentResponseDto.java b/server/src/main/java/ru/practicum/shareit/item/comment/CommentResponseDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/comment/CommentResponseDto.java rename to server/src/main/java/ru/practicum/shareit/item/comment/CommentResponseDto.java diff --git a/src/main/java/ru/practicum/shareit/item/comment/CommentStorage.java b/server/src/main/java/ru/practicum/shareit/item/comment/CommentStorage.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/comment/CommentStorage.java rename to server/src/main/java/ru/practicum/shareit/item/comment/CommentStorage.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 86% 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 fba73fa..7b3065b 100644 --- a/src/main/java/ru/practicum/shareit/item/controller/ItemController.java +++ b/server/src/main/java/ru/practicum/shareit/item/controller/ItemController.java @@ -2,7 +2,6 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import ru.practicum.shareit.item.comment.CommentRequestDto; import ru.practicum.shareit.item.comment.CommentResponseDto; @@ -11,9 +10,6 @@ import ru.practicum.shareit.item.dto.ItemResponseDtoWithBookings; import ru.practicum.shareit.item.service.ItemService; -import javax.validation.Valid; -import javax.validation.constraints.Positive; -import javax.validation.constraints.PositiveOrZero; import java.util.List; import static ru.practicum.shareit.Constant.USER_HEADER; @@ -21,21 +17,20 @@ @RestController @Slf4j @RequiredArgsConstructor -@Validated @RequestMapping("/items") public class ItemController { private final ItemService service; @PostMapping public ItemResponseDto create(@RequestHeader(USER_HEADER) Long userId, - @RequestBody @Valid ItemRequestDto itemRequestDto) { + @RequestBody ItemRequestDto itemRequestDto) { log.info("ItemController: обработка запроса от пользователя " + userId + " на добавление вещи + itemDto.toString()"); return service.create(userId, itemRequestDto); } @PostMapping("/{itemId}/comment") public CommentResponseDto addComment(@RequestHeader(USER_HEADER) Long userId, @PathVariable Long itemId, - @RequestBody @Valid CommentRequestDto commentRequestDto) { + @RequestBody CommentRequestDto commentRequestDto) { log.info("ItemController: обработка запроса от пользователя " + userId + " на добавление комментария " + commentRequestDto.toString() + " к вещи " + itemId); return service.addComment(userId, itemId, commentRequestDto); @@ -57,16 +52,16 @@ public ItemResponseDtoWithBookings findById(@PathVariable Long itemId, @RequestH @GetMapping public List findOwnersItems(@RequestHeader(USER_HEADER) Long userId, - @RequestParam(defaultValue = "0") @PositiveOrZero int from, - @RequestParam(defaultValue = "20") @Positive int size) { + @RequestParam(defaultValue = "0") int from, + @RequestParam(defaultValue = "10") int size) { log.info("ItemController: обработка запроса на поиск вещей пользователя с id {}", userId); return service.findOwnersItems(userId, from, size); } @GetMapping("/search") public List searchItems(@RequestParam String text, - @RequestParam(defaultValue = "0") @PositiveOrZero int from, - @RequestParam(defaultValue = "20") @Positive int size) { + @RequestParam(defaultValue = "0") int from, + @RequestParam(defaultValue = "10") int size) { log.info("ItemController: обработка запроса на поиск вещей, содержащих в названии или описании фрагмент {}", text); return service.searchItems(text, from, size); } 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/dto/ItemRequestDto.java b/server/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java similarity index 61% rename from src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java rename to server/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java index feb748d..e3d70d5 100644 --- a/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java +++ b/server/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java @@ -2,16 +2,10 @@ import lombok.Data; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotNull; - @Data public class ItemRequestDto { - @NotBlank private String name; - @NotBlank private String description; - @NotNull private Boolean available; private Long requestId; } \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/item/dto/ItemResponseDto.java b/server/src/main/java/ru/practicum/shareit/item/dto/ItemResponseDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/dto/ItemResponseDto.java rename to server/src/main/java/ru/practicum/shareit/item/dto/ItemResponseDto.java diff --git a/src/main/java/ru/practicum/shareit/item/dto/ItemResponseDtoWithBookings.java b/server/src/main/java/ru/practicum/shareit/item/dto/ItemResponseDtoWithBookings.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/dto/ItemResponseDtoWithBookings.java rename to server/src/main/java/ru/practicum/shareit/item/dto/ItemResponseDtoWithBookings.java 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 100% 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 diff --git a/src/main/java/ru/practicum/shareit/item/repository/ItemStorage.java b/server/src/main/java/ru/practicum/shareit/item/repository/ItemStorage.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/repository/ItemStorage.java rename to server/src/main/java/ru/practicum/shareit/item/repository/ItemStorage.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/impl/ItemServiceImpl.java b/server/src/main/java/ru/practicum/shareit/item/service/impl/ItemServiceImpl.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/service/impl/ItemServiceImpl.java rename to server/src/main/java/ru/practicum/shareit/item/service/impl/ItemServiceImpl.java 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 84% 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 718239b..e8afd23 100644 --- a/src/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java +++ b/server/src/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java @@ -2,30 +2,24 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import ru.practicum.shareit.request.dto.ItemRequestRequestDto; import ru.practicum.shareit.request.dto.ItemRequestResponseDto; import ru.practicum.shareit.request.service.ItemRequestService; -import javax.validation.Valid; -import javax.validation.constraints.Positive; -import javax.validation.constraints.PositiveOrZero; - import java.util.List; import static ru.practicum.shareit.Constant.USER_HEADER; @RestController @RequiredArgsConstructor -@Validated @RequestMapping(path = "/requests") @Slf4j public class ItemRequestController { private final ItemRequestService service; @PostMapping - public ItemRequestResponseDto create(@RequestBody @Valid ItemRequestRequestDto itemRequestRequestDto, + public ItemRequestResponseDto create(@RequestBody ItemRequestRequestDto itemRequestRequestDto, @RequestHeader(USER_HEADER) Long userId) { log.info("ItemRequestController: обработка запроса на добавление ItemRequest от пользователя {}", userId); return service.create(itemRequestRequestDto, userId); @@ -38,8 +32,8 @@ public List findByAuthor(@RequestHeader(USER_HEADER) Lon } @GetMapping("/all") - public List findAll(@RequestParam(defaultValue = "0") @PositiveOrZero int from, - @RequestParam(defaultValue = "20") @Positive int size, + public List findAll(@RequestParam(defaultValue = "0") int from, + @RequestParam(defaultValue = "10") int size, @RequestHeader(USER_HEADER) Long userId) { log.info("ItemRequestController: обработка запроса на поиск всех ItemRequest от пользователя {}", userId); return service.findAllRequests(userId, from, size); 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/server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java b/server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java new file mode 100644 index 0000000..f835c89 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestRequestDto.java @@ -0,0 +1,8 @@ +package ru.practicum.shareit.request.dto; + +import lombok.Data; + +@Data +public class ItemRequestRequestDto { + private String description; +} diff --git a/src/main/java/ru/practicum/shareit/request/dto/ItemRequestResponseDto.java b/server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestResponseDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/dto/ItemRequestResponseDto.java rename to server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestResponseDto.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/ItemRequestStorage.java b/server/src/main/java/ru/practicum/shareit/request/repository/ItemRequestStorage.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/repository/ItemRequestStorage.java rename to server/src/main/java/ru/practicum/shareit/request/repository/ItemRequestStorage.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 76% 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 f053e1c..6b25b6c 100644 --- a/src/main/java/ru/practicum/shareit/user/controller/UserController.java +++ b/server/src/main/java/ru/practicum/shareit/user/controller/UserController.java @@ -3,12 +3,10 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.web.bind.annotation.*; -import ru.practicum.shareit.user.dto.UserCreationDto; import ru.practicum.shareit.user.dto.UserRequestDto; import ru.practicum.shareit.user.dto.UserResponseDto; import ru.practicum.shareit.user.service.UserService; -import javax.validation.Valid; import java.util.List; @RestController @@ -32,19 +30,18 @@ public UserResponseDto findById(@PathVariable Long userId) { } @PostMapping - public UserResponseDto create(@Valid @RequestBody UserCreationDto userCreationDto) { - log.info("UserController: обработка запроса на создание пользователя {}}", userCreationDto.toString()); - return service.create(userCreationDto); + public UserResponseDto create(@RequestBody UserRequestDto userRequestDto) { + log.info("UserController: обработка запроса на создание пользователя {}}", userRequestDto.toString()); + return service.create(userRequestDto); } @PatchMapping("/{userId}") - public UserResponseDto update(@Valid @RequestBody UserRequestDto userRequestDto, - @PathVariable Long userId) { + public UserResponseDto update(@RequestBody UserRequestDto userRequestDto, @PathVariable Long userId) { log.info("UserController: обработка запроса на обновление пользователя с id {}", userId); return service.update(userRequestDto, userId); } - @DeleteMapping("{userId}") + @DeleteMapping("/{userId}") public void delete(@PathVariable Long userId) { log.info("UserController: обработка запроса на удаление пользователя с id {}", userId); service.delete(userId); 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 74% 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 index 0657d62..9937baf 100644 --- a/src/main/java/ru/practicum/shareit/user/dto/UserMapper.java +++ b/server/src/main/java/ru/practicum/shareit/user/dto/UserMapper.java @@ -20,11 +20,4 @@ public UserResponseDto toUserResponseDto(User user) { userResponseDto.setEmail(user.getEmail()); return userResponseDto; } - - public User fromUserCreationDto(UserCreationDto userCreationDto) { - User user = new User(); - user.setName(userCreationDto.getName()); - user.setEmail(userCreationDto.getEmail()); - return user; - } } \ No newline at end of file diff --git a/server/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java b/server/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java new file mode 100644 index 0000000..97986e3 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/user/dto/UserRequestDto.java @@ -0,0 +1,9 @@ +package ru.practicum.shareit.user.dto; + +import lombok.Data; + +@Data +public class UserRequestDto { + private String name; + private String email; +} \ No newline at end of file diff --git a/src/main/java/ru/practicum/shareit/user/dto/UserResponseDto.java b/server/src/main/java/ru/practicum/shareit/user/dto/UserResponseDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/user/dto/UserResponseDto.java rename to server/src/main/java/ru/practicum/shareit/user/dto/UserResponseDto.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 100% 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 diff --git a/src/main/java/ru/practicum/shareit/user/repository/UserStorage.java b/server/src/main/java/ru/practicum/shareit/user/repository/UserStorage.java similarity index 100% rename from src/main/java/ru/practicum/shareit/user/repository/UserStorage.java rename to server/src/main/java/ru/practicum/shareit/user/repository/UserStorage.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 77% 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 index 2da54f0..539198e 100644 --- a/src/main/java/ru/practicum/shareit/user/service/UserService.java +++ b/server/src/main/java/ru/practicum/shareit/user/service/UserService.java @@ -1,6 +1,5 @@ package ru.practicum.shareit.user.service; -import ru.practicum.shareit.user.dto.UserCreationDto; import ru.practicum.shareit.user.dto.UserRequestDto; import ru.practicum.shareit.user.dto.UserResponseDto; @@ -11,7 +10,7 @@ public interface UserService { UserResponseDto findById(Long userId); - UserResponseDto create(UserCreationDto userCreationDto); + UserResponseDto create(UserRequestDto userCreationDto); UserResponseDto update(UserRequestDto userRequestDto, Long userId); 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 94% 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 index c429309..51b6a77 100644 --- 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 @@ -5,7 +5,6 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import ru.practicum.shareit.exception.exceptions.NotFoundException; -import ru.practicum.shareit.user.dto.UserCreationDto; import ru.practicum.shareit.user.dto.UserResponseDto; import ru.practicum.shareit.user.model.User; import ru.practicum.shareit.user.repository.UserStorage; @@ -40,9 +39,9 @@ public UserResponseDto findById(Long userId) { @Override @Transactional - public UserResponseDto create(UserCreationDto userCreationDto) { + public UserResponseDto create(UserRequestDto userCreationDto) { log.info("UserService: Происходит обработка запроса на создание пользователя с email {}", userCreationDto.getEmail()); - return UserMapper.toUserResponseDto(storage.save(UserMapper.fromUserCreationDto(userCreationDto))); + return UserMapper.toUserResponseDto(storage.save(UserMapper.toUser(userCreationDto))); } @Override diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties new file mode 100644 index 0000000..32b2744 --- /dev/null +++ b/server/src/main/resources/application.properties @@ -0,0 +1,18 @@ +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=jdbc:postgresql://localhost:5432/shareIt +spring.datasource.username=root +spring.datasource.password=root +#--- +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/test/java/ru/practicum/shareit/ShareItTests.java b/server/src/test/java/ru/practicum/shareit/ShareItTests.java similarity index 100% rename from src/test/java/ru/practicum/shareit/ShareItTests.java rename to server/src/test/java/ru/practicum/shareit/ShareItTests.java diff --git a/src/test/java/ru/practicum/shareit/booking/BookingControllerTest.java b/server/src/test/java/ru/practicum/shareit/booking/BookingControllerTest.java similarity index 72% rename from src/test/java/ru/practicum/shareit/booking/BookingControllerTest.java rename to server/src/test/java/ru/practicum/shareit/booking/BookingControllerTest.java index c871cbf..7a7a852 100644 --- a/src/test/java/ru/practicum/shareit/booking/BookingControllerTest.java +++ b/server/src/test/java/ru/practicum/shareit/booking/BookingControllerTest.java @@ -55,54 +55,6 @@ void testCreateBooking() throws Exception { .andExpect(jsonPath("$.id", is(responseDto.getId()), Long.class)); } - @Test - void testCreateBookingFailItemId() throws Exception { - BookingRequestDto requestDto = new BookingRequestDto(); - requestDto.setItemId(0L); - requestDto.setStart(LocalDateTime.now().plusDays(2)); - requestDto.setEnd(LocalDateTime.now().plusDays(3)); - - mvc.perform(post("/bookings") - .header(USER_HEADER, "1") - .content(mapper.writeValueAsString(requestDto)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - - @Test - void testCreateBookingFailStartDate() throws Exception { - BookingRequestDto requestDto = new BookingRequestDto(); - requestDto.setItemId(1L); - requestDto.setStart(LocalDateTime.now().minusDays(2)); - requestDto.setEnd(LocalDateTime.now().plusDays(3)); - - mvc.perform(post("/bookings") - .header(USER_HEADER, "1") - .content(mapper.writeValueAsString(requestDto)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - - @Test - void testCreateBookingFailEndDate() throws Exception { - BookingRequestDto requestDto = new BookingRequestDto(); - requestDto.setItemId(1L); - requestDto.setStart(LocalDateTime.now().plusDays(2)); - requestDto.setEnd(null); - - mvc.perform(post("/bookings") - .header(USER_HEADER, "1") - .content(mapper.writeValueAsString(requestDto)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - @Test void testUpdateBooking() throws Exception { BookingDtoWithItemAndUser responseDto = new BookingDtoWithItemAndUser(); diff --git a/src/test/java/ru/practicum/shareit/booking/BookingServiceTest.java b/server/src/test/java/ru/practicum/shareit/booking/BookingServiceTest.java similarity index 100% rename from src/test/java/ru/practicum/shareit/booking/BookingServiceTest.java rename to server/src/test/java/ru/practicum/shareit/booking/BookingServiceTest.java diff --git a/src/test/java/ru/practicum/shareit/booking/BookingStorageTest.java b/server/src/test/java/ru/practicum/shareit/booking/BookingStorageTest.java similarity index 100% rename from src/test/java/ru/practicum/shareit/booking/BookingStorageTest.java rename to server/src/test/java/ru/practicum/shareit/booking/BookingStorageTest.java diff --git a/src/test/java/ru/practicum/shareit/item/ItemControllerTest.java b/server/src/test/java/ru/practicum/shareit/item/ItemControllerTest.java similarity index 78% rename from src/test/java/ru/practicum/shareit/item/ItemControllerTest.java rename to server/src/test/java/ru/practicum/shareit/item/ItemControllerTest.java index 337bfc8..bbbe275 100644 --- a/src/test/java/ru/practicum/shareit/item/ItemControllerTest.java +++ b/server/src/test/java/ru/practicum/shareit/item/ItemControllerTest.java @@ -84,54 +84,6 @@ void testSaveItem() throws Exception { .andExpect(jsonPath("$.available", is(responseDto.getAvailable()))); } - @Test - void testCreateItemFailName() throws Exception { - ItemRequestDto itemRequestDto = new ItemRequestDto(); - itemRequestDto.setName(""); - itemRequestDto.setDescription("item description"); - itemRequestDto.setAvailable(true); - - mvc.perform(post("/items") - .header(USER_HEADER, 1) - .content(mapper.writeValueAsString(itemRequestDto)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - - @Test - void testCreateItemFailDescription() throws Exception { - ItemRequestDto itemRequestDto = new ItemRequestDto(); - itemRequestDto.setName("name"); - itemRequestDto.setDescription(""); - itemRequestDto.setAvailable(true); - - mvc.perform(post("/items") - .header(USER_HEADER, 1) - .content(mapper.writeValueAsString(itemRequestDto)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - - @Test - void testCreateItemFailAvailable() throws Exception { - ItemRequestDto itemRequestDto = new ItemRequestDto(); - itemRequestDto.setName("name"); - itemRequestDto.setDescription("description"); - itemRequestDto.setAvailable(null); - - mvc.perform(post("/items") - .header(USER_HEADER, 1) - .content(mapper.writeValueAsString(itemRequestDto)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - @Test void testUpdateItem() throws Exception { when(itemService.update(anyLong(), anyLong(), any(ItemRequestDto.class))).thenReturn(responseDto); diff --git a/src/test/java/ru/practicum/shareit/item/ItemIntegrationTest.java b/server/src/test/java/ru/practicum/shareit/item/ItemIntegrationTest.java similarity index 100% rename from src/test/java/ru/practicum/shareit/item/ItemIntegrationTest.java rename to server/src/test/java/ru/practicum/shareit/item/ItemIntegrationTest.java diff --git a/src/test/java/ru/practicum/shareit/item/ItemServiceTest.java b/server/src/test/java/ru/practicum/shareit/item/ItemServiceTest.java similarity index 100% rename from src/test/java/ru/practicum/shareit/item/ItemServiceTest.java rename to server/src/test/java/ru/practicum/shareit/item/ItemServiceTest.java diff --git a/src/test/java/ru/practicum/shareit/item/ItemStorageTest.java b/server/src/test/java/ru/practicum/shareit/item/ItemStorageTest.java similarity index 100% rename from src/test/java/ru/practicum/shareit/item/ItemStorageTest.java rename to server/src/test/java/ru/practicum/shareit/item/ItemStorageTest.java diff --git a/src/test/java/ru/practicum/shareit/request/ItemRequestControllerTest.java b/server/src/test/java/ru/practicum/shareit/request/ItemRequestControllerTest.java similarity index 87% rename from src/test/java/ru/practicum/shareit/request/ItemRequestControllerTest.java rename to server/src/test/java/ru/practicum/shareit/request/ItemRequestControllerTest.java index 5412622..ba29b54 100644 --- a/src/test/java/ru/practicum/shareit/request/ItemRequestControllerTest.java +++ b/server/src/test/java/ru/practicum/shareit/request/ItemRequestControllerTest.java @@ -54,20 +54,6 @@ void testCreateItemRequest() throws Exception { .andExpect(jsonPath("$.id", is(responseDto.getId()), Long.class)); } - @Test - void testCreateItemFailDescription() throws Exception { - ItemRequestRequestDto requestDto = new ItemRequestRequestDto(); - requestDto.setDescription(""); - mvc.perform(post("/requests") - .header(USER_HEADER, "1") - .content(mapper.writeValueAsString(requestDto)) - .header("X-Sharer-User-Id", "1") - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - @Test void testFindByAuthor() throws Exception { ItemRequestResponseDto responseDto = new ItemRequestResponseDto(); diff --git a/src/test/java/ru/practicum/shareit/request/ItemRequestIntegrationTest.java b/server/src/test/java/ru/practicum/shareit/request/ItemRequestIntegrationTest.java similarity index 100% rename from src/test/java/ru/practicum/shareit/request/ItemRequestIntegrationTest.java rename to server/src/test/java/ru/practicum/shareit/request/ItemRequestIntegrationTest.java diff --git a/src/test/java/ru/practicum/shareit/request/ItemRequestServiceTest.java b/server/src/test/java/ru/practicum/shareit/request/ItemRequestServiceTest.java similarity index 100% rename from src/test/java/ru/practicum/shareit/request/ItemRequestServiceTest.java rename to server/src/test/java/ru/practicum/shareit/request/ItemRequestServiceTest.java diff --git a/src/test/java/ru/practicum/shareit/request/ItemRequestStorageTest.java b/server/src/test/java/ru/practicum/shareit/request/ItemRequestStorageTest.java similarity index 100% rename from src/test/java/ru/practicum/shareit/request/ItemRequestStorageTest.java rename to server/src/test/java/ru/practicum/shareit/request/ItemRequestStorageTest.java diff --git a/src/test/java/ru/practicum/shareit/user/UserControllerTest.java b/server/src/test/java/ru/practicum/shareit/user/UserControllerTest.java similarity index 76% rename from src/test/java/ru/practicum/shareit/user/UserControllerTest.java rename to server/src/test/java/ru/practicum/shareit/user/UserControllerTest.java index e45c527..6c59193 100644 --- a/src/test/java/ru/practicum/shareit/user/UserControllerTest.java +++ b/server/src/test/java/ru/practicum/shareit/user/UserControllerTest.java @@ -9,7 +9,6 @@ import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; import ru.practicum.shareit.user.controller.UserController; -import ru.practicum.shareit.user.dto.UserCreationDto; import ru.practicum.shareit.user.dto.UserRequestDto; import ru.practicum.shareit.user.dto.UserResponseDto; import ru.practicum.shareit.user.service.UserService; @@ -34,16 +33,11 @@ public class UserControllerTest { @MockBean UserService userService; - private static UserCreationDto userCreationDto; private static UserRequestDto userRequestDto; private static UserResponseDto userResponseDto; @BeforeAll public static void setUp() { - userCreationDto = new UserCreationDto(); - userCreationDto.setName("user"); - userCreationDto.setEmail("user@user.com"); - userRequestDto = new UserRequestDto(); userRequestDto.setName("user"); userRequestDto.setEmail("user@user.com"); @@ -56,11 +50,11 @@ public static void setUp() { @Test void testSaveUser() throws Exception { - when(userService.create(any(UserCreationDto.class))) + when(userService.create(any(UserRequestDto.class))) .thenReturn(userResponseDto); mvc.perform(post("/users") - .content(mapper.writeValueAsString(userCreationDto)) + .content(mapper.writeValueAsString(userRequestDto)) .characterEncoding(StandardCharsets.UTF_8) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) @@ -70,32 +64,6 @@ void testSaveUser() throws Exception { .andExpect(jsonPath("$.email", is(userResponseDto.getEmail()))); } - @Test - void testSaveUserFailEmail() throws Exception { - UserCreationDto userCreationDto1 = new UserCreationDto(); - userCreationDto1.setName("name"); - userCreationDto1.setEmail("email"); - mvc.perform(post("/users") - .content(mapper.writeValueAsString(userCreationDto1)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - - @Test - void testSaveUserFailName() throws Exception { - UserCreationDto userCreationDto1 = new UserCreationDto(); - userCreationDto1.setName(""); - userCreationDto1.setEmail("email"); - mvc.perform(post("/users") - .content(mapper.writeValueAsString(userCreationDto1)) - .characterEncoding(StandardCharsets.UTF_8) - .contentType(MediaType.APPLICATION_JSON) - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()); - } - @Test void testUpdateUser() throws Exception { when(userService.update(any(UserRequestDto.class), anyLong())).thenReturn(userResponseDto); diff --git a/src/test/java/ru/practicum/shareit/user/UserIntegrateTest.java b/server/src/test/java/ru/practicum/shareit/user/UserIntegrateTest.java similarity index 70% rename from src/test/java/ru/practicum/shareit/user/UserIntegrateTest.java rename to server/src/test/java/ru/practicum/shareit/user/UserIntegrateTest.java index ac7a936..efa56ab 100644 --- a/src/test/java/ru/practicum/shareit/user/UserIntegrateTest.java +++ b/server/src/test/java/ru/practicum/shareit/user/UserIntegrateTest.java @@ -1,13 +1,11 @@ package ru.practicum.shareit.user; -import org.jeasy.random.EasyRandom; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.dao.DataIntegrityViolationException; import org.springframework.test.annotation.DirtiesContext; import ru.practicum.shareit.exception.exceptions.NotFoundException; -import ru.practicum.shareit.user.dto.UserCreationDto; import ru.practicum.shareit.user.dto.UserRequestDto; import ru.practicum.shareit.user.dto.UserResponseDto; import ru.practicum.shareit.user.service.impl.UserServiceImpl; @@ -22,12 +20,10 @@ public class UserIntegrateTest { @Autowired private UserServiceImpl userService; - private final EasyRandom easyRandom = new EasyRandom(); - @Test @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) public void addUser() { - UserCreationDto creationDto = new UserCreationDto(); + UserRequestDto creationDto = new UserRequestDto(); creationDto.setName("user"); creationDto.setEmail("user@user.com"); @@ -44,10 +40,15 @@ public void addUser() { @Test @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) public void findAll() { - UserCreationDto creationDto = easyRandom.nextObject(UserCreationDto.class); + UserRequestDto creationDto = new UserRequestDto(); + creationDto.setName("user"); + creationDto.setEmail("user@user.com"); UserResponseDto user = userService.create(creationDto); assertEquals(1, userService.findAll().size()); - UserResponseDto newUser = userService.create(easyRandom.nextObject(UserCreationDto.class)); + UserRequestDto newCreationDto = new UserRequestDto(); + newCreationDto.setName("newUser"); + newCreationDto.setEmail("newUser@user.com"); + UserResponseDto newUser = userService.create(newCreationDto); List userList = userService.findAll(); assertEquals(2, userList.size()); @@ -60,11 +61,16 @@ public void findAll() { public void testFindById() { assertThrows(NotFoundException.class, () -> userService.findById(1L)); - UserCreationDto creationDto = easyRandom.nextObject(UserCreationDto.class); + UserRequestDto creationDto = new UserRequestDto(); + creationDto.setName("user"); + creationDto.setEmail("user@user.com"); userService.create(creationDto); - UserResponseDto newUser = userService.create(easyRandom.nextObject(UserCreationDto.class)); + UserRequestDto newCreationDto = new UserRequestDto(); + newCreationDto.setName("newUser"); + newCreationDto.setEmail("newUser@user.com"); + UserResponseDto newUser = userService.create(newCreationDto); assertEquals(newUser, userService.findById(newUser.getId())); } @@ -77,7 +83,11 @@ void testUpdate() { assertThrows(NotFoundException.class, () -> userService.update(requestDto, 1L)); - UserResponseDto user = userService.create(easyRandom.nextObject(UserCreationDto.class)); + UserRequestDto creationDto = new UserRequestDto(); + creationDto.setName("user"); + creationDto.setEmail("user@user.com"); + + UserResponseDto user = userService.create(creationDto); UserResponseDto responseDto = userService.update(requestDto, user.getId()); @@ -87,7 +97,11 @@ void testUpdate() { @Test @DirtiesContext(methodMode = DirtiesContext.MethodMode.AFTER_METHOD) void testDelete() { - UserResponseDto responseDto = userService.create(easyRandom.nextObject(UserCreationDto.class)); + UserRequestDto creationDto = new UserRequestDto(); + creationDto.setName("user"); + creationDto.setEmail("user@user.com"); + + UserResponseDto responseDto = userService.create(creationDto); assertEquals(1, userService.findAll().size()); diff --git a/src/test/java/ru/practicum/shareit/user/UserServiceTest.java b/server/src/test/java/ru/practicum/shareit/user/UserServiceTest.java similarity index 96% rename from src/test/java/ru/practicum/shareit/user/UserServiceTest.java rename to server/src/test/java/ru/practicum/shareit/user/UserServiceTest.java index 8e949bd..3d44419 100644 --- a/src/test/java/ru/practicum/shareit/user/UserServiceTest.java +++ b/server/src/test/java/ru/practicum/shareit/user/UserServiceTest.java @@ -8,7 +8,6 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.dao.DataIntegrityViolationException; import ru.practicum.shareit.exception.exceptions.NotFoundException; -import ru.practicum.shareit.user.dto.UserCreationDto; import ru.practicum.shareit.user.dto.UserMapper; import ru.practicum.shareit.user.dto.UserRequestDto; import ru.practicum.shareit.user.dto.UserResponseDto; @@ -41,7 +40,7 @@ public void setUp() { @Test void testCreateUser() { - UserCreationDto userDto = new UserCreationDto(); + UserRequestDto userDto = new UserRequestDto(); userDto.setName("user"); userDto.setEmail("user@user.com"); @@ -55,7 +54,7 @@ void testCreateUser() { @Test void testCreateFailDuplicateEmail() { - UserCreationDto userDto = new UserCreationDto(); + UserRequestDto userDto = new UserRequestDto(); userDto.setName("user"); userDto.setEmail("user@user.com"); diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 86b493a..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,20 +0,0 @@ -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 - -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.datasource.url=jdbc:postgresql://localhost:5432/shareIt -#spring.datasource.driverClassName=org.postgresql.Driver -#spring.datasource.username=root -#spring.datasource.password=root - -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