diff --git a/.github/workflows/build.sh b/.github/workflows/build.sh new file mode 100644 index 0000000..95efef0 --- /dev/null +++ b/.github/workflows/build.sh @@ -0,0 +1,5 @@ +cp -rf ./tests/checkstyle.xml ./checkstyle.xml +cp -rf ./tests/suppressions.xml ./suppressions.xml +mvn enforcer:enforce -Drules=requireProfileIdsExist -P check --no-transfer-progress +mvn verify -P check,coverage --no-transfer-progress +docker-compose build \ No newline at end of file diff --git a/.github/workflows/dashboard-template.hbs b/.github/workflows/dashboard-template.hbs new file mode 100644 index 0000000..56aa163 --- /dev/null +++ b/.github/workflows/dashboard-template.hbs @@ -0,0 +1,1672 @@ + + + + + {{browserTitle}} + + + + + + + + + +
+
+ + + +
+ {{#with summary}} +
+
+ + {{/with}} +
+
+
+
+

{{title}}

+
{{timestamp}}
+{{#with summary}} +
+
+
+
+
+ +
+
Итого итераций
+

{{stats.iterations.total}}

+
+
+
+
+
+
+
+ +
+
Всего проверенных утверждений
+

{{totalTests stats.assertions.total skippedTests.length}}

+
+
+
+
+
+
+
+ +
+
Всего проваленных тестов
+

{{failures.length}}

+
+
+
+
+
+
+
+ +
+
Всего пропущено тестов
+

{{#gt skippedTests.length 0}}{{skippedTests.length}}{{else}}0{{/gt}}

+
+
+
+
+
+
+
+
+
+
+
+
File Information
+ Коллекция: {{collection.name}}
+ {{/with}} + {{#if folders}} Указанные папки: {{folders}}
{{/if}} + {{#with summary}} + {{#if environment.name}} Окружение: {{environment.name}}
{{/if}} +
+
+
+
+ {{#if @root.showGlobalData}} + {{#if globals.values.members.length}} +
+
+
+
+
+ +
+
+
+ +
+ + + + {{#each globals.values.members}} + {{#isNotIn key @root.skipGlobalVars}} + + + + + {{/isNotIn}} + {{/each}} + +
Название переменнойЗначение переменной
{{key}}{{value}}
+
+
+
+
+
+
+
+ {{/if}} + {{/if}} + {{#if @root.showEnvironmentData}} + {{#if environment.values.members.length}} +
+
+
+
+
+ +
+
+
+ +
+ + + + {{#each environment.values.members}} + {{#isNotIn key @root.skipEnvironmentVars}} + + + + + {{/isNotIn}} + {{/each}} + +
Название переменнойЗначение переменной
{{key}}{{value}}
+
+
+
+
+
+
+
+ {{/if}} + {{/if}} + {{#if collection.description}} +
+
+
+
+
Описание Коллекции
+
+ {{collection.description}} +
+
+
+
+
+ {{/if}} +
+
+
+
+
Временные рамки и данные
+ Общая длительность выполнения: {{duration}}
+ Всего данных получено: {{responseTotal}}
+ Среднее время отклика: {{responseAverage}}
+
+
+
+
+ {{/with}} +
+
+
+ + + + + + + + + + {{#with summary.stats}} + + + + + + + + + + + + + + + + {{/with}} + {{#with summary}} + + + + + + + + + + + {{/with}} + +
Элемент сводных данныхВсегоПровалено
Requests{{requests.total}}{{requests.failed}}
Prerequest Scripts{{prerequestScripts.total}}{{prerequestScripts.failed}}
Test Scripts{{testScripts.total}}{{testScripts.failed}}
Assertions{{totalTests stats.assertions.total skippedTests.length}}{{stats.assertions.failed}}
Skipped Tests{{#gt skippedTests.length 0}}{{skippedTests.length}}{{else}}0{{/gt}}-
+
+
+
+
+
+
+
+
+
+
+ + + {{#if summary.failures.length}} +
+ +
+
+
+ + {{#with summary}} +
+

Showing {{failures.length}} {{#gt failures.length 1}}Failures{{else}}Failure{{/gt}}

+
+ {{/with}} + {{#each summary.failures}} +
+
+
+ +
+
+
Failed Test: {{error.test}}
+
+
Assertion Error Message
+
+
{{error.message}}
+
+
+
+
+
+
+ {{/each}} + {{else}} +
+

There are no failed tests



+
+ {{/if}} +
+ +
+ + + {{#if summary.skippedTests.length}} +
+ +
+
+
+ + {{#with summary}} +
+

Showing {{skippedTests.length}} Skipped {{#gt skippedTests.length 1}}Tests{{else}}Test{{/gt}}

+
+ {{/with}} + {{#each summary.skippedTests}} +
+
+
+ +
+
+
Request Name: {{item.name}}
+
+
+
+
+
+ {{/each}} + {{else}} +
+

There are no skipped tests



+
+ {{/if}} +
+
+ + + +
+ {{#if summary.failures.length}} + + {{/if}} + + +
+ +
+ {{#with summary}} +
{{stats.iterations.total}} {{#gt stats.iterations.total 1}}Iterations{{else}}Iteration{{/gt}} available to view
+ {{#gt stats.iterations.total 18}}{{/gt}} + {{/with}} + +
+
+
+{{#each aggregations}} + {{#isNotIn parent.name @root.skipFolders}} + {{#if parent.name }} + +
+ {{> aggregations}} +
+ {{else}} + {{> aggregations}} + {{/if}} + {{/isNotIn}} +{{/each}} +
+
+
+
+
+
+ +{{#*inline "aggregations"}} +{{#isNotIn parent.name @root.skipFolders}} +{{#if @root.showFolderDescription}} +{{#if parent.description.content}} + +
+
+
+
+
+
Описание папки
+
+ {{parent.description.content}} +
+
+
+
+
+
+{{/if}} +{{/if}} +{{#each executions}} +{{#isNotIn item.name @root.skipRequests}} +
+
+
+
+
+ + {{#if cumulativeTests.skipped}} + {{cumulativeTests.skipped}} Пропущено {{#gt cumulativeTests.skipped 1}}Тестов{{else}}Тест{{/gt}} + {{/if}} +
+
+
+ {{#with request}} + {{#if description.content}} +
+
+
+
+
+
Описание запроса
+
+ {{description.content}} +
+
+
+
+
+
+ {{/if}} + {{/with}} +
+
+
+
+
+
Информация о запросе
+ HTTP-метод запроса: {{request.method}}
+ URL запроса: {{request.url}}
+
+
+
+
+
Информация об ответе
+ Код статуса ответа: {{response.code}} - {{response.status}}
+ Среднее время на запрос: {{mean.time}}
+ Средний размер одного запроса: {{mean.size}}
+
+
Процент прохождения тестов
+
+ {{#if assertions.length}} +
+
+
{{#gte cumulativeTests.passed 1}}{{percent cumulativeTests.passed cumulativeTests.failed}} %{{else}}0 %{{/gte}}
+
+
+ {{else}} +
+
+
Для данного запроса нет тестов
+
+
+ {{/if}} +
+
+
+
+
+
+ {{#with request}} + {{#unless @root.omitHeaders}} + {{#unless @root.skipSensitiveData}} +
+
+
+
+
+
Заголовки запроса
+ {{#if headers}} +
+ + + + {{#each headers.members}} + {{#isNotIn key @root.skipHeaders}} + + + + + {{/isNotIn}} + {{/each}} + +
Название заголовкаЗначение заголовка
{{key}}{{value}}
+
+ {{/if}} +
+
+
+
+
+ {{/unless}} + {{/unless}} + {{/with}} + {{#unless @root.skipSensitiveData}} + {{#unless @root.omitRequestBodies}} + {{#isNotIn item.name @root.hideRequestBody}} + {{#with request}} + {{#if body.raw}} +
+
+
+
+
+
Тело запроса
+
+
{{body.raw}}
+
+ +
+
+
+
+
+ {{/if}} + {{/with}} + {{/isNotIn}} + {{/unless}} + {{/unless}} + {{#unless @root.skipSensitiveData}} + {{#unless @root.omitRequestBodies}} + {{#isNotIn item.name @root.hideRequestBody}} + {{#with request}} + {{#if body.formdata.members}} +
+
+
+
+
+
Тело Запроса
+
+
{{formdata body.formdata.members}}
+
+ +
+
+
+
+
+ {{/if}} + {{/with}} + {{/isNotIn}} + {{/unless}} + {{/unless}} + {{#unless @root.skipSensitiveData}} + {{#unless @root.omitRequestBodies}} + {{#isNotIn item.name @root.hideRequestBody}} + {{#with request}} + {{#if body.urlencoded.members}} +
+
+
+
+
+
Тело Запроса
+
+
{{formdata body.urlencoded.members}}
+
+ +
+
+
+
+
+ {{/if}} + {{/with}} + {{/isNotIn}} + {{/unless}} + {{/unless}} + {{#unless @root.skipSensitiveData}} + {{#unless @root.omitRequestBodies}} + {{#isNotIn item.name @root.hideRequestBody}} + {{#with request}} + {{#if body.graphql}} +
+
+
+
+
+
Тело Запроса
+
+
{{body.graphql.query}}
+
+ + {{#if body.graphql.variables }} +
Graphql Variables
+
+
{{body.graphql.variables}}
+
+ {{/if}} +
+
+
+
+
+ {{/if}} + {{/with}} + {{/isNotIn}} + {{/unless}} + {{/unless}} + {{#unless @root.omitHeaders}} + {{#unless @root.skipSensitiveData}} +
+
+
+
+
+
Заголовки Ответа
+ {{#if response.header}} +
+ + + + {{#each response.header}} + {{#isNotIn key @root.skipHeaders}} + + + + + {{/isNotIn}} + {{/each}} + +
Название заголовкаЗначение заголовка
{{key}}{{value}}
+
+ {{/if}} +
+
+
+
+
+ {{/unless}} + {{/unless}} + {{#unless @root.skipSensitiveData}} + {{#unless @root.omitResponseBodies}} + {{#isNotIn item.name @root.hideResponseBody}} +
+
+
+
+
+
Тело Ответа
+ {{#if response.body}} +
+
{{response.body}}
+
+ + {{else}} +
У ответа на этот запрос нет тела
+ {{/if}} +
+
+
+
+
+ {{/isNotIn}} + {{/unless}} + {{/unless}} + {{#if consoleLogs.length}} +
+
+
+
+
+
Логи консоли
+
+
+ + + + {{#each consoleLogs}} + + + + {{/each}} + +
Залогированные сообщения
{{#each messages}}{{this}}{{/each}}
+
+
+
+
+
+
+
+ {{/if}} +
+
+
+
Информация о тесте
+ {{#if assertions.length}} +
+ + + + {{#each assertions}} + + + + + + + {{/each}} + + + + + + + + + +
НазваниеПройденоПроваленоПропущено
{{this.name}}{{this.passed}}{{this.failed}}{{this.skipped}}
Всего{{cumulativeTests.passed}}{{cumulativeTests.failed}}{{cumulativeTests.skipped}}
+
+
+
+
+
+
+
{{#lte cumulativeTests.failed 1}}Проваленный тест{{else}}Проваленные тесты{{/lte}}
+
+ + + + {{#each assertions}} + {{#isTheSame testFailure.test this.name}} + + + + + {{/isTheSame}} + {{/each}} + +
Название тестаОшибка проверки
{{testFailure.test}}
{{testFailure.message}}
+
+
+
+
+
+
+ {{else}} +
No Tests for this request
+ {{/if}} +
+
+
+
+
+
+
+
+
+{{/isNotIn}} +{{/each}} +{{/isNotIn}} +{{/inline}} + + + + + + +{{#eq noSyntaxHighlighting false}} + + +{{/eq}} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.github/workflows/run.sh b/.github/workflows/run.sh new file mode 100644 index 0000000..ff67969 --- /dev/null +++ b/.github/workflows/run.sh @@ -0,0 +1,5 @@ +docker-compose up --detach +chmod a+x ./tests/.github/workflows/wait-for-it.sh +./tests/.github/workflows/wait-for-it.sh -t 60 localhost:8080 +./tests/.github/workflows/wait-for-it.sh -t 60 localhost:9090 +docker-compose logs diff --git a/.github/workflows/wait-for-it.sh b/.github/workflows/wait-for-it.sh new file mode 100644 index 0000000..859de3f --- /dev/null +++ b/.github/workflows/wait-for-it.sh @@ -0,0 +1,183 @@ +#!/usr/bin/env bash +# Use this script to test if a given TCP host/port are available + +WAITFORIT_cmdname=${0##*/} + +echoerr() { if [[ $WAITFORIT_QUIET -ne 1 ]]; then echo "$@" 1>&2; fi } + +usage() +{ + cat << USAGE >&2 +Usage: + $WAITFORIT_cmdname host:port [-s] [-t timeout] [-- command args] + -h HOST | --host=HOST Host or IP under test + -p PORT | --port=PORT TCP port under test + Alternatively, you specify the host and port as host:port + -s | --strict Only execute subcommand if the test succeeds + -q | --quiet Don't output any status messages + -t TIMEOUT | --timeout=TIMEOUT + Timeout in seconds, zero for no timeout + -- COMMAND ARGS Execute command with args after the test finishes +USAGE + exit 1 +} + +wait_for() +{ + if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then + echoerr "$WAITFORIT_cmdname: waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT" + else + echoerr "$WAITFORIT_cmdname: waiting for $WAITFORIT_HOST:$WAITFORIT_PORT without a timeout" + fi + WAITFORIT_start_ts=$(date +%s) + while : + do + if [[ $WAITFORIT_ISBUSY -eq 1 ]]; then + nc -z $WAITFORIT_HOST $WAITFORIT_PORT + WAITFORIT_result=$? + else +# (echo -n > /dev/tcp/$WAITFORIT_HOST/$WAITFORIT_PORT) >/dev/null 2>&1 + (curl --fail --silent $WAITFORIT_HOST:$WAITFORIT_PORT/actuator/health | grep UP) >/dev/null 2>&1 + WAITFORIT_result=$? + fi + if [[ $WAITFORIT_result -eq 0 ]]; then + WAITFORIT_end_ts=$(date +%s) + echoerr "$WAITFORIT_cmdname: $WAITFORIT_HOST:$WAITFORIT_PORT is available after $((WAITFORIT_end_ts - WAITFORIT_start_ts)) seconds" + break + fi + sleep 1 + done + return $WAITFORIT_result +} + +wait_for_wrapper() +{ + # In order to support SIGINT during timeout: http://unix.stackexchange.com/a/57692 + if [[ $WAITFORIT_QUIET -eq 1 ]]; then + timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --quiet --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT & + else + timeout $WAITFORIT_BUSYTIMEFLAG $WAITFORIT_TIMEOUT $0 --child --host=$WAITFORIT_HOST --port=$WAITFORIT_PORT --timeout=$WAITFORIT_TIMEOUT & + fi + WAITFORIT_PID=$! + trap "kill -INT -$WAITFORIT_PID" INT + wait $WAITFORIT_PID + WAITFORIT_RESULT=$? + if [[ $WAITFORIT_RESULT -ne 0 ]]; then + echoerr "$WAITFORIT_cmdname: timeout occurred after waiting $WAITFORIT_TIMEOUT seconds for $WAITFORIT_HOST:$WAITFORIT_PORT" + fi + return $WAITFORIT_RESULT +} + +# process arguments +while [[ $# -gt 0 ]] +do + case "$1" in + *:* ) + WAITFORIT_hostport=(${1//:/ }) + WAITFORIT_HOST=${WAITFORIT_hostport[0]} + WAITFORIT_PORT=${WAITFORIT_hostport[1]} + shift 1 + ;; + --child) + WAITFORIT_CHILD=1 + shift 1 + ;; + -q | --quiet) + WAITFORIT_QUIET=1 + shift 1 + ;; + -s | --strict) + WAITFORIT_STRICT=1 + shift 1 + ;; + -h) + WAITFORIT_HOST="$2" + if [[ $WAITFORIT_HOST == "" ]]; then break; fi + shift 2 + ;; + --host=*) + WAITFORIT_HOST="${1#*=}" + shift 1 + ;; + -p) + WAITFORIT_PORT="$2" + if [[ $WAITFORIT_PORT == "" ]]; then break; fi + shift 2 + ;; + --port=*) + WAITFORIT_PORT="${1#*=}" + shift 1 + ;; + -t) + WAITFORIT_TIMEOUT="$2" + if [[ $WAITFORIT_TIMEOUT == "" ]]; then break; fi + shift 2 + ;; + --timeout=*) + WAITFORIT_TIMEOUT="${1#*=}" + shift 1 + ;; + --) + shift + WAITFORIT_CLI=("$@") + break + ;; + --help) + usage + ;; + *) + echoerr "Unknown argument: $1" + usage + ;; + esac +done + +if [[ "$WAITFORIT_HOST" == "" || "$WAITFORIT_PORT" == "" ]]; then + echoerr "Error: you need to provide a host and port to test." + usage +fi + +WAITFORIT_TIMEOUT=${WAITFORIT_TIMEOUT:-15} +WAITFORIT_STRICT=${WAITFORIT_STRICT:-0} +WAITFORIT_CHILD=${WAITFORIT_CHILD:-0} +WAITFORIT_QUIET=${WAITFORIT_QUIET:-0} + +# Check to see if timeout is from busybox? +WAITFORIT_TIMEOUT_PATH=$(type -p timeout) +WAITFORIT_TIMEOUT_PATH=$(realpath $WAITFORIT_TIMEOUT_PATH 2>/dev/null || readlink -f $WAITFORIT_TIMEOUT_PATH) + +WAITFORIT_BUSYTIMEFLAG="" +if [[ $WAITFORIT_TIMEOUT_PATH =~ "busybox" ]]; then + WAITFORIT_ISBUSY=1 + # Check if busybox timeout uses -t flag + # (recent Alpine versions don't support -t anymore) + if timeout &>/dev/stdout | grep -q -e '-t '; then + WAITFORIT_BUSYTIMEFLAG="-t" + fi +else + WAITFORIT_ISBUSY=0 +fi + +if [[ $WAITFORIT_CHILD -gt 0 ]]; then + wait_for + WAITFORIT_RESULT=$? + exit $WAITFORIT_RESULT +else + if [[ $WAITFORIT_TIMEOUT -gt 0 ]]; then + wait_for_wrapper + WAITFORIT_RESULT=$? + else + wait_for + WAITFORIT_RESULT=$? + fi +fi + +if [[ $WAITFORIT_CLI != "" ]]; then + if [[ $WAITFORIT_RESULT -ne 0 && $WAITFORIT_STRICT -eq 1 ]]; then + echoerr "$WAITFORIT_cmdname: strict mode, refusing to execute subprocess" + exit $WAITFORIT_RESULT + fi + exec "${WAITFORIT_CLI[@]}" +else + exit $WAITFORIT_RESULT +fi \ No newline at end of file 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..a8ed9e5 --- /dev/null +++ b/.run/ShareItServer.run.xml @@ -0,0 +1,15 @@ + + + + \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..7fd547b --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,37 @@ +version: '3.8' +services: + gateway: + build: gateway + image: gateway + container_name: gateway_container + ports: + - "8080:8080" + depends_on: + - server + environment: + - SHAREIT_SERVER_URL=http://server:9090 + + server: + build: server + image: server + container_name: server_container + ports: + - "9090:9090" + depends_on: + - db + environment: + - SPRING_DATASOURCE_URL=jdbc:postgresql://db:5432/postgres + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + + db: + image: postgres:14.6-alpine + container_name: postgres_db + ports: + - "6541:5432" + environment: + - POSTGRES_DB=postgres + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres +volumes: + myapp: \ No newline at end of file diff --git a/gateway/Dockerfile b/gateway/Dockerfile new file mode 100644 index 0000000..ecbe381 --- /dev/null +++ b/gateway/Dockerfile @@ -0,0 +1,4 @@ +FROM amazoncorretto:11 +COPY target/*.jar shareit-gateway.jar +ENV JAVA_OPTS='-Xmx3g -Xms3g' +ENTRYPOINT ["java","-jar","/shareit-gateway.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/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..e2384e3 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/booking/BookingClient.java @@ -0,0 +1,67 @@ +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 update(Long bookingId, BookItemRequestDto bookingDto, long userId, Boolean approved) { + if (approved == null) { + return patch("/" + bookingId, userId, bookingDto); + } else { + Map parameters = Map.of("approved", approved); + return patch("/" + bookingId + "?approved={approved}", userId, parameters, bookingDto); + } + } + + public ResponseEntity getItemsForUser(long userId, String state, Integer from, Integer size) { + Map parameters = Map.of( + "state", state, + "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..8ef5143 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/booking/BookingController.java @@ -0,0 +1,82 @@ +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 ru.practicum.shareit.exception.ValidationException; + +import javax.validation.Valid; +import javax.validation.constraints.Min; +import javax.validation.constraints.Positive; +import javax.validation.constraints.PositiveOrZero; +import java.time.LocalDateTime; + +@Controller +@RequestMapping(path = "/bookings") +@RequiredArgsConstructor +@Slf4j +@Validated +public class BookingController { + private final BookingClient bookingClient; + + @GetMapping + public ResponseEntity getBookings(@RequestHeader("X-Sharer-User-Id") 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("Get booking with state {}, userId={}, from={}, size={}", stateParam, userId, from, size); + return bookingClient.getBookings(userId, state, from, size); + } + + @PostMapping + public ResponseEntity bookItem(@RequestHeader("X-Sharer-User-Id") long userId, + @RequestBody @Valid BookItemRequestDto requestDto) throws ValidationException { + log.info("Creating booking {}, userId={}", requestDto, userId); + checkBookingDates(requestDto); + return bookingClient.bookItem(userId, requestDto); + } + + @GetMapping("/{bookingId}") + public ResponseEntity getBooking(@RequestHeader("X-Sharer-User-Id") long userId, + @PathVariable Long bookingId) { + log.info("Get booking {}, userId={}", bookingId, userId); + return bookingClient.getBooking(userId, bookingId); + } + + @PatchMapping("/{bookingId}") + public ResponseEntity updateBooking(@PathVariable Long bookingId, BookItemRequestDto bookingDto, + @RequestHeader("X-Sharer-User-Id") long userId, + @RequestParam(name = "approved", required = false) Boolean approved) throws Exception { + return bookingClient.update(bookingId, bookingDto, userId, approved); + } + + @GetMapping("/owner") + public ResponseEntity getItemsByAll(@RequestHeader("X-Sharer-User-Id") long userId, + @RequestParam(name = "state", required = false, defaultValue = "ALL") String state, + @PositiveOrZero @Min(0) @RequestParam(value = "from", defaultValue = "0") Integer from, + @Min(1) @RequestParam(value = "size", defaultValue = "20") Integer size) throws Exception { + return bookingClient.getItemsForUser(userId, state, from, size); + } + + private void checkBookingDates(BookItemRequestDto bookingDto) throws ValidationException { + + if (bookingDto.getStart() == null || bookingDto.getEnd() == null) { + throw new ValidationException("Start or End is null"); + } + LocalDateTime now = LocalDateTime.now(); + if (bookingDto.getStart().isBefore(now) || bookingDto.getEnd().isBefore(now) + || bookingDto.getStart().equals(bookingDto.getEnd()) + || bookingDto.getStart().isAfter(bookingDto.getEnd())) { + throw new ValidationException("Start or End is wrong"); + } + } + + +} 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..a220213 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/booking/dto/BookItemRequestDto.java @@ -0,0 +1,20 @@ +package ru.practicum.shareit.booking.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.Future; +import javax.validation.constraints.FutureOrPresent; +import java.time.LocalDateTime; + +@Getter +@NoArgsConstructor +@AllArgsConstructor +public class BookItemRequestDto { + private long itemId; + @FutureOrPresent + private LocalDateTime start; + @Future + 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..9d9982f --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/client/BaseClient.java @@ -0,0 +1,117 @@ +package ru.practicum.shareit.client; + +import org.springframework.http.*; +import org.springframework.lang.Nullable; +import org.springframework.web.client.HttpStatusCodeException; +import org.springframework.web.client.RestTemplate; + +import java.util.List; +import java.util.Map; + +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/src/main/java/ru/practicum/shareit/exception/ApiSubError.java b/gateway/src/main/java/ru/practicum/shareit/exception/ApiSubError.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/ApiSubError.java rename to gateway/src/main/java/ru/practicum/shareit/exception/ApiSubError.java diff --git a/src/main/java/ru/practicum/shareit/exception/ApplicationError.java b/gateway/src/main/java/ru/practicum/shareit/exception/ApplicationError.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/ApplicationError.java rename to gateway/src/main/java/ru/practicum/shareit/exception/ApplicationError.java diff --git a/src/main/java/ru/practicum/shareit/exception/BookingNotFoundException.java b/gateway/src/main/java/ru/practicum/shareit/exception/BookingNotFoundException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/BookingNotFoundException.java rename to gateway/src/main/java/ru/practicum/shareit/exception/BookingNotFoundException.java diff --git a/gateway/src/main/java/ru/practicum/shareit/exception/ControllerExceptionHandler.java b/gateway/src/main/java/ru/practicum/shareit/exception/ControllerExceptionHandler.java new file mode 100644 index 0000000..cebb03a --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/exception/ControllerExceptionHandler.java @@ -0,0 +1,82 @@ +package ru.practicum.shareit.exception; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.core.MethodParameter; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.validation.FieldError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; + +import java.util.List; + +@ControllerAdvice +@Slf4j +public class ControllerExceptionHandler { + @ExceptionHandler(ValidationException.class) + public ResponseEntity handleValidationException(ValidationException e) { + ApplicationError applicationError = new ApplicationError(HttpStatus.BAD_REQUEST, e); + applicationError.setError(e.getMessage()); + log.error("Validation Exception Thrown"); + return new ResponseEntity<>(applicationError, HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler(ItemNotAvailableException.class) + public ResponseEntity handleItemNotAvailableException(ItemNotAvailableException e) { + ApplicationError applicationError = new ApplicationError(HttpStatus.BAD_REQUEST, e); + log.error("ItemNotAvailableException Exception Thrown"); + return new ResponseEntity<>(applicationError, HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler({ItemNotFoundException.class, UserNotFoundException.class, BookingNotFoundException.class, ItemRequestNotFoundException.class}) + public ResponseEntity handleNotFoundException(Exception e) { + ApplicationError applicationError = new ApplicationError(HttpStatus.NOT_FOUND, "Объект не найден", e); + log.error("Not found exception thrown"); + return new ResponseEntity<>(applicationError, HttpStatus.NOT_FOUND); + } + + @ExceptionHandler() + public ResponseEntity handleException(Exception e) { + log.error("Unexpected exception thrown"); + return new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); + } + + @ExceptionHandler(MethodArgumentNotValidException.class) + public ResponseEntity methodArgumentNotValidException(MethodArgumentNotValidException e) { + StringBuilder errorMessage = new StringBuilder(); + List allErrors = e.getBindingResult().getFieldErrors(); + for (FieldError error : allErrors) { + errorMessage.append("Field: ").append(error.getField()); + errorMessage.append(", rejected value: ").append(error.getRejectedValue()); + errorMessage.append(" error: ").append(error.getDefaultMessage()); + } + ApplicationError applicationError = new ApplicationError(HttpStatus.BAD_REQUEST, "Ошибка валидации. " + errorMessage, e); + MethodParameter parameter = e.getParameter(); + parameter.getAnnotatedElement(); + log.error("Method Argument Not Valid Exception"); + return new ResponseEntity<>(applicationError, HttpStatus.BAD_REQUEST); + } + + @ExceptionHandler(UnauthorizedException.class) + public ResponseEntity handleUnauthorizedException(UnauthorizedException e) { + ApplicationError applicationError = new ApplicationError(HttpStatus.FORBIDDEN, "Нет доступа", e); + log.error("Unauthorized exception thrown"); + return new ResponseEntity<>(applicationError, HttpStatus.FORBIDDEN); + } + + @ExceptionHandler(DuplicateValueException.class) + public ResponseEntity handleDuplicateValueException(DuplicateValueException e) { + ApplicationError applicationError = new ApplicationError(HttpStatus.CONFLICT, "Конфликт", e); + log.error("Duplicate Value exception thrown"); + return new ResponseEntity<>(applicationError, HttpStatus.CONFLICT); + } + + @ExceptionHandler(IllegalArgumentException.class) + public ResponseEntity handleIllegalArgumentException(IllegalArgumentException e) { + ApplicationError applicationError = new ApplicationError(HttpStatus.BAD_REQUEST, e); + applicationError.setError(e.getMessage()); + log.error("IllegalArgumentException Thrown"); + return new ResponseEntity<>(applicationError, HttpStatus.BAD_REQUEST); + } +} diff --git a/src/main/java/ru/practicum/shareit/exception/DuplicateValueException.java b/gateway/src/main/java/ru/practicum/shareit/exception/DuplicateValueException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/DuplicateValueException.java rename to gateway/src/main/java/ru/practicum/shareit/exception/DuplicateValueException.java diff --git a/src/main/java/ru/practicum/shareit/exception/ItemNotAvailableException.java b/gateway/src/main/java/ru/practicum/shareit/exception/ItemNotAvailableException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/ItemNotAvailableException.java rename to gateway/src/main/java/ru/practicum/shareit/exception/ItemNotAvailableException.java diff --git a/src/main/java/ru/practicum/shareit/exception/ItemNotFoundException.java b/gateway/src/main/java/ru/practicum/shareit/exception/ItemNotFoundException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/ItemNotFoundException.java rename to gateway/src/main/java/ru/practicum/shareit/exception/ItemNotFoundException.java diff --git a/src/main/java/ru/practicum/shareit/exception/ItemRequestNotFoundException.java b/gateway/src/main/java/ru/practicum/shareit/exception/ItemRequestNotFoundException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/ItemRequestNotFoundException.java rename to gateway/src/main/java/ru/practicum/shareit/exception/ItemRequestNotFoundException.java diff --git a/src/main/java/ru/practicum/shareit/exception/UnauthorizedException.java b/gateway/src/main/java/ru/practicum/shareit/exception/UnauthorizedException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/UnauthorizedException.java rename to gateway/src/main/java/ru/practicum/shareit/exception/UnauthorizedException.java diff --git a/src/main/java/ru/practicum/shareit/exception/UserNotFoundException.java b/gateway/src/main/java/ru/practicum/shareit/exception/UserNotFoundException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/UserNotFoundException.java rename to gateway/src/main/java/ru/practicum/shareit/exception/UserNotFoundException.java diff --git a/src/main/java/ru/practicum/shareit/exception/ValidationException.java b/gateway/src/main/java/ru/practicum/shareit/exception/ValidationException.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/ValidationException.java rename to gateway/src/main/java/ru/practicum/shareit/exception/ValidationException.java diff --git a/gateway/src/main/java/ru/practicum/shareit/item/ItemClient.java b/gateway/src/main/java/ru/practicum/shareit/item/ItemClient.java new file mode 100644 index 0000000..2e567cb --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/item/ItemClient.java @@ -0,0 +1,71 @@ +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 ru.practicum.shareit.item.dto.ItemRequestUpdateDto; + +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 create(ItemRequestDto itemDto, Long userId) { + return post("", userId, null, itemDto); + } + + public ResponseEntity update(long id, ItemRequestUpdateDto itemDto, long userId) { + return patch("/" + id, userId, itemDto); + + } + + public ResponseEntity getById(long id, long userId) { + + return get("/" + id, userId); + } + + public ResponseEntity getAll(long userId, Integer from, Integer size) { + Map parameters = Map.of( + "from", from, + "size", size + ); + return get("", userId, parameters); + } + + public ResponseEntity search(String text, Integer from, Integer size) { + Map parameters = Map.of( + "text", text, + "from", from, + "size", size + ); + return get("/search?text={text}", null, parameters); + + } + + public ResponseEntity addComment(long userId, long itemId, CommentRequestDto commentDto) { + return post("/" + itemId + "/comment", userId, commentDto); + } + + public ResponseEntity delete(long id, long userId) { + + return delete("/" + id, 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..9f13be1 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/item/ItemController.java @@ -0,0 +1,69 @@ +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 ru.practicum.shareit.item.dto.ItemRequestUpdateDto; + +import javax.validation.Valid; +import javax.validation.constraints.Min; +import javax.validation.constraints.PositiveOrZero; + +@RequestMapping("/items") +@Controller +@RequiredArgsConstructor +@Slf4j +@Validated +public class ItemController { + + private final ItemClient itemClient; + + @PostMapping + public ResponseEntity create(@RequestHeader("X-Sharer-User-Id") Long userId, + @RequestBody @Valid ItemRequestDto itemDto) throws Exception { + return itemClient.create(itemDto, userId); + } + + @PatchMapping("/{id}") + public ResponseEntity update(@RequestHeader("X-Sharer-User-Id") long userId, + @RequestBody @Valid ItemRequestUpdateDto itemDto, @PathVariable long id) throws Exception { + return itemClient.update(id, itemDto, userId); + } + + @DeleteMapping("/{id}") + public ResponseEntity delete(@RequestHeader("X-Sharer-User-Id") long userId, + @PathVariable long id) throws Exception { + return itemClient.delete(id, userId); + } + + @GetMapping("/{id}") + public ResponseEntity getById(@PathVariable long id, + @RequestHeader("X-Sharer-User-Id") long userId) throws Exception { + return itemClient.getById(id, userId); + } + + @GetMapping + public ResponseEntity getAll(@RequestHeader("X-Sharer-User-Id") long userId, + @PositiveOrZero @Min(0) @RequestParam(value = "from", defaultValue = "0") Integer from, + @Min(1) @RequestParam(value = "size", defaultValue = "10") Integer size) { + return itemClient.getAll(userId, from, size); + } + + @GetMapping("/search") + public ResponseEntity search(@RequestParam(name = "text") String text, + @PositiveOrZero @Min(0) @RequestParam(value = "from", defaultValue = "0") Integer from, + @Min(1) @RequestParam(value = "size", defaultValue = "10") Integer size) { + return itemClient.search(text, from, size); + } + + @PostMapping("{itemId}/comment") + public ResponseEntity addComment(@RequestHeader("X-Sharer-User-Id") long userId, @PathVariable long itemId, + @RequestBody@Valid CommentRequestDto commentDto) throws Exception { + return itemClient.addComment(userId, itemId, commentDto); + } +} 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..21b2a1e --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/item/dto/CommentRequestDto.java @@ -0,0 +1,14 @@ +package ru.practicum.shareit.item.dto; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Data +public class CommentRequestDto { + @NotNull + @NotBlank + 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..3e4e8d2 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/item/dto/ItemRequestDto.java @@ -0,0 +1,19 @@ +package ru.practicum.shareit.item.dto; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Data +public class ItemRequestDto { + @NotNull + @NotBlank + private String name; + @NotNull + @NotBlank + private String description; + @NotNull + private Boolean available; + private Long requestId; +} diff --git a/gateway/src/main/java/ru/practicum/shareit/item/dto/ItemRequestUpdateDto.java b/gateway/src/main/java/ru/practicum/shareit/item/dto/ItemRequestUpdateDto.java new file mode 100644 index 0000000..ee08e3a --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/item/dto/ItemRequestUpdateDto.java @@ -0,0 +1,11 @@ +package ru.practicum.shareit.item.dto; + +import lombok.Data; + +@Data +public class ItemRequestUpdateDto { + private String name; + private String description; + private Boolean available; + private Long requestId; +} diff --git a/gateway/src/main/java/ru/practicum/shareit/request/RequestController.java b/gateway/src/main/java/ru/practicum/shareit/request/RequestController.java new file mode 100644 index 0000000..ab973a9 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/request/RequestController.java @@ -0,0 +1,48 @@ +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.RequestClient; +import ru.practicum.shareit.request.dto.RequestDto; + +import javax.validation.Valid; +import javax.validation.constraints.PositiveOrZero; + + + @RequestMapping(path = "/requests") + @Controller + @RequiredArgsConstructor + @Slf4j + @Validated + public class RequestController { + + private final RequestClient requestClient; + + @PostMapping + public ResponseEntity create(@RequestHeader("X-Sharer-User-Id") Long userId, @RequestBody @Valid RequestDto itemRequestDto) throws Exception { + return requestClient.create(itemRequestDto, userId); + } + + @GetMapping + public ResponseEntity getItemRequests(@RequestHeader("X-Sharer-User-Id") Long userId) throws Exception { + return requestClient.getAllOwnRequests(userId); + } + + @GetMapping("/all") + public ResponseEntity getAllItemRequests(@RequestHeader("X-Sharer-User-Id") Long userId, + @PositiveOrZero @RequestParam(value = "from", required = false) Integer from, + @RequestParam(value = "size", required = false) Integer size) throws Exception { + return requestClient.getAllUserRequests(userId, from, size); + } + + @GetMapping("/{requestId}") + public ResponseEntity getItemRequest(@RequestHeader("X-Sharer-User-Id") Long userId, + @PathVariable Long requestId) throws Exception { + return requestClient.getById(userId, requestId); + } + } + diff --git a/gateway/src/main/java/ru/practicum/shareit/request/dto/RequestClient.java b/gateway/src/main/java/ru/practicum/shareit/request/dto/RequestClient.java new file mode 100644 index 0000000..aef928c --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/request/dto/RequestClient.java @@ -0,0 +1,52 @@ +package ru.practicum.shareit.request.dto; + +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 java.util.Map; + +@Service +public class RequestClient extends BaseClient { + private static final String API_PREFIX = "/requests"; + + @Autowired + public RequestClient(@Value("${shareit-server.url}") String serverUrl, RestTemplateBuilder builder) { + super( + builder + .uriTemplateHandler(new DefaultUriBuilderFactory(serverUrl + API_PREFIX)) + .requestFactory(HttpComponentsClientHttpRequestFactory::new) + .build() + ); + } + + public ResponseEntity create(RequestDto itemRequestDto, Long userId) { + + return post("", userId,itemRequestDto); + } + + public ResponseEntity getAllOwnRequests(Long userId) { + return get("",userId); + + } + + public ResponseEntity getAllUserRequests(Long userId, Integer from, Integer size) { + if (from == null && size == null) { + return get("/all", userId); + } else { + Map parameters = Map.of("from", from, "size", size); + return get("/all?from={from}&size={size}", userId, parameters); + } + + } + + public ResponseEntity getById(Long userId, Long requestId) { + +return get("/" + requestId, userId); + } +} diff --git a/gateway/src/main/java/ru/practicum/shareit/request/dto/RequestDto.java b/gateway/src/main/java/ru/practicum/shareit/request/dto/RequestDto.java new file mode 100644 index 0000000..eb8493a --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/request/dto/RequestDto.java @@ -0,0 +1,14 @@ +package ru.practicum.shareit.request.dto; + + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Data +public class RequestDto { + @NotBlank + @NotNull + private String description; +} 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..a4af497 --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/user/UserController.java @@ -0,0 +1,47 @@ +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.UserClient; +import ru.practicum.shareit.user.dto.UserDto; +import ru.practicum.shareit.user.dto.UserUpdateDto; + +import javax.validation.Valid; + +@Controller +@RequiredArgsConstructor +@Slf4j +@Validated +@RequestMapping(path = "/users") +public class UserController { + private final UserClient userClient; + + @PostMapping + public ResponseEntity create(@RequestBody @Valid UserDto userDto) throws Exception { + return userClient.create(userDto); + } + + @PatchMapping("/{id}") + public ResponseEntity update(@PathVariable long id, @RequestBody @Valid UserUpdateDto userDto) throws Exception { + return userClient.update(id, userDto); + } + + @DeleteMapping("/{id}") + public ResponseEntity delete(@PathVariable long id) throws Exception { + return userClient.delete(id); + } + + @GetMapping("/{id}") + public ResponseEntity getById(@PathVariable long id) throws Exception { + return userClient.getById(id); + } + + @GetMapping + public ResponseEntity getAll() { + return userClient.getAll(); + } +} \ No newline at end of file diff --git a/gateway/src/main/java/ru/practicum/shareit/user/dto/UserClient.java b/gateway/src/main/java/ru/practicum/shareit/user/dto/UserClient.java new file mode 100644 index 0000000..b043a4c --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/user/dto/UserClient.java @@ -0,0 +1,50 @@ +package ru.practicum.shareit.user.dto; + +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; + +@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 getAll() { + return get(""); + + } + + public ResponseEntity create(UserDto userDto) { + + return post("", userDto); + } + + public ResponseEntity update(long id, UserUpdateDto userDto) { + return patch("/" + id, userDto); + + } + + public ResponseEntity getById(long id) { + return get("/" + id); + + } + + public ResponseEntity delete(long id) { + + return delete("/" + id); + } +} diff --git a/gateway/src/main/java/ru/practicum/shareit/user/dto/UserDto.java b/gateway/src/main/java/ru/practicum/shareit/user/dto/UserDto.java new file mode 100644 index 0000000..aa9024a --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/user/dto/UserDto.java @@ -0,0 +1,19 @@ +package ru.practicum.shareit.user.dto; + +import lombok.Data; + +import javax.validation.constraints.Email; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Data +public class UserDto { + + @NotNull + @NotBlank + private String name; + + @Email + @NotNull + private String email; +} diff --git a/gateway/src/main/java/ru/practicum/shareit/user/dto/UserUpdateDto.java b/gateway/src/main/java/ru/practicum/shareit/user/dto/UserUpdateDto.java new file mode 100644 index 0000000..4bee05d --- /dev/null +++ b/gateway/src/main/java/ru/practicum/shareit/user/dto/UserUpdateDto.java @@ -0,0 +1,14 @@ +package ru.practicum.shareit.user.dto; + +import lombok.Data; + +import javax.validation.constraints.Email; + +@Data +public class UserUpdateDto { + + private String name; + + @Email + private String email; +} 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 bfdf252..cba4430 100644 --- a/pom.xml +++ b/pom.xml @@ -5,86 +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.springframework.boot - spring-boot-starter-data-jpa - - - - - 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 - - + + 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 @@ -231,17 +188,5 @@ - - coverage - - - - org.jacoco - jacoco-maven-plugin - - - - - diff --git a/postman/sprint.json b/postman/sprint.json new file mode 100644 index 0000000..d5d4403 --- /dev/null +++ b/postman/sprint.json @@ -0,0 +1,11050 @@ +{ + "info": { + "_postman_id": "02b3b696-d51d-4750-b4dc-35e6712fd023", + "name": "Sprint 16 ShareIt (add-docker)", + "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json", + "_exporter_id": "2036415" + }, + "item": [ + { + "name": "users", + "item": [ + { + "name": "User 1 create", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has user create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"user@user.com\"').to.eql('user@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"user\"').to.eql('user');", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"user\",\n \"email\": \"user@user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "User 2 create fail duplicate email", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 409\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([409, 500]);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"user\",\n \"email\": \"user@user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "User create fail no email", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"user\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "User create fail invalid email", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"user\",\n \"email\": \"user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "User 1 update", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has user update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"update@user.com\"').to.eql('update@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"update\"').to.eql('update');", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"update\",\n \"email\": \"update@user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "User 3 create", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has user create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 3').to.eql(3);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"user@user.com\"').to.eql('user@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"user\"').to.eql('user');", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"user\",\n \"email\": \"user@user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "User 1 update name", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has user update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"update@user.com\"').to.eql('update@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"updateName\"').to.eql('updateName');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"updateName\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "User 1 update email", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has user update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"updateName@user.com\"').to.eql('updateName@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"updateName\"').to.eql('updateName');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"email\": \"updateName@user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "User 1 update with same email", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has user update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"updateName@user.com\"').to.eql('updateName@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"updateName\"').to.eql('updateName');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"email\": \"updateName@user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "User 1 name update fail email exists", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 409\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([409, 500]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"email\": \"user@user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "User 1 get updated", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has user update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"updateName@user.com\"').to.eql('updateName@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"updateName\"').to.eql('updateName');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "User 3 get", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has user update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 3').to.eql(3);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"user@user.com\"').to.eql('user@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"user\"').to.eql('user');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "3" + } + ] + } + }, + "response": [] + }, + { + "name": "User 100 get unkonwn", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "100" + } + ] + } + }, + "response": [] + }, + { + "name": "User 3 delete", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,204]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "DELETE", + "header": [ + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/users/:userId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users", + ":userId" + ], + "variable": [ + { + "key": "userId", + "value": "3" + } + ] + } + }, + "response": [] + }, + { + "name": "User 4 create after delete", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has user create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 4').to.eql(4);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"user@user.com\"').to.eql('user@user.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"user\"').to.eql('user');", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"user\",\n \"email\": \"user@user.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "User get all", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list user response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test user[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test user[0] 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('email');", + " pm.expect(jsonData[0].email, '\"email\" must be \"updateName@user.com\"').to.eql('updateName@user.com');", + "});", + "pm.test(\"Test user[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('name');", + " pm.expect(jsonData[0].name, '\"name\" must be \"updateName\"').to.eql('updateName');", + "});", + "", + "pm.test(\"Test user[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 4').to.eql(4);", + "});", + "pm.test(\"Test user[1] 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('email');", + " pm.expect(jsonData[1].email, '\"email\" must be \"user@user.com\"').to.eql('user@user.com');", + "});", + "pm.test(\"Test user[1] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('name');", + " pm.expect(jsonData[1].name, '\"name\" must be \"user\"').to.eql('user');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "items", + "item": [ + { + "name": "Item 1 create by user 1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has item create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Дрель\"').to.eql('Дрель');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Простая дрель\"').to.eql('Простая дрель');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Дрель\",\n \"description\": \"Простая дрель\",\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item create without X-Sharer-User-Id", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500, 400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text", + "disabled": true + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Дрель\",\n \"description\": \"Простая дрель\",\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item create with not found user", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404,403]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "10", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Дрель\",\n \"description\": \"Простая дрель\",\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item create without available", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "3", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Отвертка\",\n \"description\": \"Аккумуляторная отвертка\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item create with empty name", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "3", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"\",\n \"description\": \"Аккумуляторная отвертка\",\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item create with empty description", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "3", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Отвертка\",\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "item 1 update", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Дрель+\"').to.eql('Дрель+');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"false\"').to.false;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"id\": 1,\n \"name\": \"Дрель+\",\n \"description\": \"Аккумуляторная дрель\",\n \"available\": false\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "item 1 update without X-Sharer-User-Id", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500, 400]);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text", + "disabled": true + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"id\": 1,\n \"name\": \"Дрель\",\n \"description\": \"Простая дрель\",\n \"available\": false\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "item 1 update with other user 3", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500, 404, 403]);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "3", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Дрель\",\n \"description\": \"Простая дрель\",\n \"available\": false\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "item 1 update available", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Дрель+\"').to.eql('Дрель+');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "item 1 update description", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Дрель+\"').to.eql('Дрель+');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"description\": \"Аккумуляторная дрель + аккумулятор\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "item 1 update name", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "", + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Аккумуляторная дрель\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 1 get from owner user 1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "", + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 1 get from user 4", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Test get item\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.id, '\"id\" field').to.eql(1);", + " pm.expect(jsonData.name, '\"name\" field').to.eql('Аккумуляторная дрель');", + " pm.expect(jsonData.description, '\"description\" field').to.eql('Аккумуляторная дрель + аккумулятор');", + " pm.expect(jsonData.available, '\"available\" field').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 100 get from user 4", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "100" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 2 create by user 4", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has item create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Отвертка\",\n \"description\": \"Аккумуляторная отвертка\",\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item 3 create by user 4", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has item create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 3').to.eql(3);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Тюбик суперклея марки Момент\"').to.eql('Тюбик суперклея марки Момент');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Клей Момент\",\n \"description\": \"Тюбик суперклея марки Момент\",\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item get all user 1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test item[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('name');", + " pm.expect(jsonData[0].name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", + "});", + "pm.test(\"Test item[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('available');", + " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item get all user 4", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test item[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('name');", + " pm.expect(jsonData[0].name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('available');", + " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "", + "", + "pm.test(\"Test item[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 3').to.eql(3);", + "});", + "pm.test(\"Test item[1] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('name');", + " pm.expect(jsonData[1].name, '\"name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "pm.test(\"Test item[1] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('description');", + " pm.expect(jsonData[1].description, '\"description\" must be \"Тюбик суперклея марки Момент\"').to.eql('Тюбик суперклея марки Момент');", + "});", + "pm.test(\"Test item[1] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('available');", + " pm.expect(jsonData[1].available, '\"available\" must be \"true\"').to.true;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item search аккумуляторная", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test item[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('name');", + " pm.expect(jsonData[0].name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", + "});", + "pm.test(\"Test item[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('available');", + " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "", + "pm.test(\"Test item[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item[1] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('name');", + " pm.expect(jsonData[1].name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item[1] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('description');", + " pm.expect(jsonData[1].description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item[1] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('available');", + " pm.expect(jsonData[1].available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/search?text=аккУМУляторная", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + "search" + ], + "query": [ + { + "key": "text", + "value": "аккУМУляторная" + } + ] + } + }, + "response": [] + }, + { + "name": "item 2 update set unavailable", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"false\"').to.false;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"available\": false\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Item search дрель", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test search item response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test item[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('name');", + " pm.expect(jsonData[0].name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", + "});", + "pm.test(\"Test item[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('available');", + " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/search?text=дРелЬ", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + "search" + ], + "query": [ + { + "key": "text", + "value": "дРелЬ" + } + ] + } + }, + "response": [] + }, + { + "name": "Item search аккумуляторная available", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test search item response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test item[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('name');", + " pm.expect(jsonData[0].name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", + "});", + "pm.test(\"Test item[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('available');", + " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/search?text=аккУМУляторная", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + "search" + ], + "query": [ + { + "key": "text", + "value": "аккУМУляторная" + } + ] + } + }, + "response": [] + }, + { + "name": "item 2 update set available", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Item search отвертка", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test search item response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "pm.test(\"Test item[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('name');", + " pm.expect(jsonData[0].name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('available');", + " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/search?text=оТверТ", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + "search" + ], + "query": [ + { + "key": "text", + "value": "оТверТ" + } + ] + } + }, + "response": [] + }, + { + "name": "Item search empty", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test search item response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 0').to.eql(0);", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/search?text=", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + "search" + ], + "query": [ + { + "key": "text", + "value": "" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "bookings", + "item": [ + { + "name": "item 2 update set unavailable", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"false\"').to.false;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"available\": false\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking create from user1 to item2 unavailable", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(1, 'd');\r", + "var end = moment().add(2, 'd');\r", + "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "item 2 update set available", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking create failed by wrong userId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500, 404, 403]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(1, 'd');\r", + "var end = moment().add(2, 'd');\r", + "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "100", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking create failed by not found itemId", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(1, 'd');\r", + "var end = moment().add(2, 'd');\r", + "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 200,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking create failed by end in past", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(1, 'd');\r", + "var end = moment().add(-1, 'd');\r", + "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking create failed by end before start", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(2, 'd');\r", + "var end = moment().add(1, 'd');\r", + "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking create failed by start equal end", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(2, 'd');\r", + "pm.environment.set('start_equal_end', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start_equal_end}}\",\n \"end\": \"{{start_equal_end}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking create failed by start equal null", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(2, 'd');\r", + "pm.environment.set('start_null', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"end\": \"{{start_null}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking create failed by end equal null", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(2, 'd');\r", + "pm.environment.set('end_null', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{end_null}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking create failed by start in past", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(-1, 'd');\r", + "var end = moment().add(1, 'd');\r", + "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking 1 create from user 1 to item 2 current", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(3, 's');\r", + "var end = moment().add(4, 's')\r", + "pm.environment.set('start', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start}}\",\n \"end\": \"{{end}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking set approve by owner current", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Has booking patch response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "true" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 2 create from user 1 to item 2", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(1, 'd');\r", + "var end = moment().add(2, 'd');\r", + "pm.environment.set('start2', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end2', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start2}}\",\n \"end\": \"{{end2}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking 2 get by user 1 (booker)", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Has booking get response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "variable": [ + { + "key": "bookingId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 2 get by user 4 (owner)", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Has booking get response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "variable": [ + { + "key": "bookingId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for wrong user 100", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,404,403]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "100", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "" + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for wrong owner user 100", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,404,403]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "100", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", + "});", + "pm.test(\"Test booking[1] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", + "});", + "pm.test(\"Test booking[1] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[1] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[1] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 1 by ALL state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", + "});", + "pm.test(\"Test booking[1] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", + "});", + "pm.test(\"Test booking[1] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[1] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[1] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?state=ALL", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "state", + "value": "ALL" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 1 by FUTURE state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(new Date(jsonData[0].start), '\"start\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(new Date(jsonData[0].end), '\"end\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + "});", + "pm.test(\"Test booking[1] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(new Date(jsonData[1].start), '\"start\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "", + "});", + "pm.test(\"Test booking[1] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(new Date(jsonData[1].end), '\"end\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "});", + "pm.test(\"Test booking[1] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[1] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[1] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?state=FUTURE", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "state", + "value": "FUTURE" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 1 by wrong state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});", + "pm.test(\"Test get user bookings by 'UNSUPPORTED_STATUS' state\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.error, 'Error message').to.be.eql('Unknown state: UNSUPPORTED_STATUS');", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?state=UNSUPPORTED_STATUS", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "state", + "value": "UNSUPPORTED_STATUS" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for owner", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", + "});", + "pm.test(\"Test booking[1] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", + "});", + "pm.test(\"Test booking[1] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[1] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[1] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for owner by ALL state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", + "});", + "pm.test(\"Test booking[1] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", + "});", + "pm.test(\"Test booking[1] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[1] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[1] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?state=ALL", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "state", + "value": "ALL" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for owner by FUTURE state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(new Date(jsonData[0].start), '\"start\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(new Date(jsonData[0].end), '\"end\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + "});", + "pm.test(\"Test booking[1] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(new Date(jsonData[1].start), '\"start\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "", + "});", + "pm.test(\"Test booking[1] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(new Date(jsonData[1].end), '\"end\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "});", + "pm.test(\"Test booking[1] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[1] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[1] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?state=FUTURE", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "state", + "value": "FUTURE" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for owner by wrong state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});", + "pm.test(\"Test get owner bookings by 'UNSUPPORTED_STATUS' state\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.error, 'Error message').to.be.eql('Unknown state: UNSUPPORTED_STATUS');", + "});" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?state=UNSUPPORTED_STATUS", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "state", + "value": "UNSUPPORTED_STATUS" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 1000 get from user 4", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "variable": [ + { + "key": "bookingId", + "value": "1000" + } + ] + } + }, + "response": [] + }, + { + "name": "User 5 create", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has user create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"other@other.com\"').to.eql('other@other.com');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"other\"').to.eql('other');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"other\",\n \"email\": \"other@other.com\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "Booking 1 get from user 5", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "5", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "variable": [ + { + "key": "bookingId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 2 change status from user 5 fail", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "5", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "variable": [ + { + "key": "bookingId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 2 change status by user 1 (booker)", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "true" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 2 set approve by user 4 (owner)", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Has booking get response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start2') + '\"').to.eql(pm.environment.get('start2'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end2') + '\"').to.eql(pm.environment.get('end2'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "true" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 2 change status by user 4 (owner) after approve", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "true" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "User 6 create", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has user create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test user 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 6').to.eql(6);", + "});", + "pm.test(\"Test user 'email' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('email');", + " pm.expect(jsonData.email, '\"email\" must be \"practicum@yandex.ru\"').to.eql('practicum@yandex.ru');", + "});", + "pm.test(\"Test user 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"practicum\"').to.eql('practicum');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"practicum\",\n \"email\": \"practicum@yandex.ru\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/users", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "users" + ] + } + }, + "response": [] + }, + { + "name": "Booking create from user 1 to item 1 failed", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(2, 'd');\r", + "var end = moment().add(3, 'd');\r", + "pm.environment.set('start3', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end3', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 1,\n \"start\": \"{{start3}}\",\n \"end\": \"{{end3}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking 3 create from user 4 to item 1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 3').to.eql(3);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start3') + '\"').to.eql(pm.environment.get('start3'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end3') + '\"').to.eql(pm.environment.get('end3'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"4\"').to.eql(4);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(1, 'd');\r", + "var end = moment().add(1, 'd').add(1, 'h');\r", + "pm.environment.set('start3', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end3', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 1,\n \"start\": \"{{start3}}\",\n \"end\": \"{{end3}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking 3 set rejected by user 1 (owner)", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.ok;", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 3').to.eql(3);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start3') + '\"').to.eql(pm.environment.get('start3'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end3') + '\"').to.eql(pm.environment.get('end3'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"4\"').to.eql(4);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=false", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "false" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "3" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 4 create from user 5 to item 2", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 4').to.eql(4);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start4') + '\"').to.eql(pm.environment.get('start4'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end4') + '\"').to.eql(pm.environment.get('end4'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"5\"').to.eql(5);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(1, 'h');\r", + "var end = moment().add(2, 'h');\r", + "pm.environment.set('start4', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end4', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "5", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start4}}\",\n \"end\": \"{{end4}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking 4 set approve by user 4 (owner)", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Has booking get response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 4').to.eql(4);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start4') + '\"').to.eql(pm.environment.get('start4'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end4') + '\"').to.eql(pm.environment.get('end4'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"5\"').to.eql(5);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "true" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "4" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 2 get by user 4 (owner) with bookings", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "", + "pm.test(\"Test item 'lastBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking).to.have.property('id');", + " pm.expect(jsonData.lastBooking.id, '\"lastBooking.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test item 'lastBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking).to.have.property('bookerId');", + " pm.expect(jsonData.lastBooking.bookerId, '\"lastBooking.bookerId\" must be \"1\"').to.eql(1);", + "});", + "", + "pm.test(\"Test item 'nextBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking).to.have.property('id');", + " pm.expect(jsonData.nextBooking.id, '\"nextBooking.id\" must be \"1\"').to.eql(4);", + "});", + "pm.test(\"Test item 'nextBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking).to.have.property('bookerId');", + " pm.expect(jsonData.nextBooking.bookerId, '\"nextBooking.bookerId\" must be \"1\"').to.eql(5);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var time = setTimeout(function(){}, 4000);\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 2 get by user 1 without bookings", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "", + "pm.test(\"Test item 'lastBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking, '\"lastBooking\" must be \"null\"').null;", + "});", + "pm.test(\"Test item 'nextBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 2 get by user 5 without bookings", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "", + "pm.test(\"Test item 'lastBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking, '\"lastBooking\" must be \"null\"').null;", + "});", + "pm.test(\"Test item 'nextBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "5", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Item get all user 4 with bookings", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test item[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('name');", + " pm.expect(jsonData[0].name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('available');", + " pm.expect(jsonData[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test item[0] 'lastBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('lastBooking');", + " pm.expect(jsonData[0].lastBooking).to.have.property('id');", + " pm.expect(jsonData[0].lastBooking.id, '\"lastBooking.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test item[0] 'lastBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('lastBooking');", + " pm.expect(jsonData[0].lastBooking).to.have.property('bookerId');", + " pm.expect(jsonData[0].lastBooking.bookerId, '\"lastBooking.bookerId\" must be \"1\"').to.eql(1);", + "});", + "", + "pm.test(\"Test item[0] 'nextBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('nextBooking');", + " pm.expect(jsonData[0].nextBooking).to.have.property('id');", + " pm.expect(jsonData[0].nextBooking.id, '\"nextBooking.id\" must be \"1\"').to.eql(4);", + "});", + "pm.test(\"Test item[0] 'nextBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('nextBooking');", + " pm.expect(jsonData[0].nextBooking).to.have.property('bookerId');", + " pm.expect(jsonData[0].nextBooking.bookerId, '\"nextBooking.bookerId\" must be \"1\"').to.eql(5);", + "});", + "", + "", + "pm.test(\"Test item[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 3').to.eql(3);", + "});", + "pm.test(\"Test item[1] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('name');", + " pm.expect(jsonData[1].name, '\"name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "pm.test(\"Test item[1] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('description');", + " pm.expect(jsonData[1].description, '\"description\" must be \"Тюбик суперклея марки Момент\"').to.eql('Тюбик суперклея марки Момент');", + "});", + "pm.test(\"Test item[1] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('available');", + " pm.expect(jsonData[1].available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test item[1] 'lastBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('lastBooking');", + " pm.expect(jsonData[1].lastBooking, '\"lastBooking\" must be \"null\"').null;", + "});", + "pm.test(\"Test item[1] 'nextBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('nextBooking');", + " pm.expect(jsonData[1].nextBooking, '\"nextBooking\" must be \"null\"').null;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Booking 5 create from user 1 to item 3 current", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"3\"').to.eql(3);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(3, 's');\r", + "var end = moment().add(1, 'd')\r", + "pm.environment.set('start5', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end5', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 3,\n \"start\": \"{{start5}}\",\n \"end\": \"{{end5}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 1 by WAITING state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?state=WAITING", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "state", + "value": "WAITING" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 4 (owner) by WAITING state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?state=WAITING", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "state", + "value": "WAITING" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 6 create from user 1 to item 2 current", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 6').to.eql(6);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start6') + '\"').to.eql(pm.environment.get('start6'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end6') + '\"').to.eql(pm.environment.get('end6'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(3, 's');\r", + "var end = moment().add(4, 's')\r", + "pm.environment.set('start6', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end6', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 2,\n \"start\": \"{{start6}}\",\n \"end\": \"{{end6}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking 5 set rejected by user 4 (owner)", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"3\"').to.eql(3);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=false", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "false" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "5" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 1 by REJECTED state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?state=REJECTED", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "state", + "value": "REJECTED" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 4 (owner) by REJECTED state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?state=REJECTED", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "state", + "value": "REJECTED" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 6 set approve by owner 4 current", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Has booking patch response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 6').to.eql(6);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start6') + '\"').to.eql(pm.environment.get('start6'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end6') + '\"').to.eql(pm.environment.get('end6'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "true" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "6" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "comments", + "item": [ + { + "name": "Item 4 create by user 6", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has item create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 4').to.eql(4);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Кухонный стол\"').to.eql('Кухонный стол');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Стол для празднования\"').to.eql('Стол для празднования');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "6", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Кухонный стол\",\n \"description\": \"Стол для празднования\",\n \"available\": true\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Item 1 get from user 1 (owner) without comments", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "", + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная дрель + аккумулятор\"').to.eql('Аккумуляторная дрель + аккумулятор');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test item 'lastBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking, '\"lastBooking\" must be \"null\"').null;", + "});", + "pm.test(\"Test item 'nextBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", + "});", + "pm.test(\"Test item 'comments' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('comments');", + " pm.expect(jsonData.comments.length, 'length of \"comments\" must be \"0\"').to.eql(0);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 7 future create from user 5 to item 1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 7').to.eql(7);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start7') + '\"').to.eql(pm.environment.get('start7'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end7') + '\"').to.eql(pm.environment.get('end7'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"5\"').to.eql(5);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(10, 'd');\r", + "var end = moment().add(11, 'd')\r", + "pm.environment.set('start7', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end7', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "5", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 1,\n \"start\": \"{{start7}}\",\n \"end\": \"{{end7}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking 8 create from user 1 to item 4 start past and end future", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 8').to.eql(8);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start8') + '\"').to.eql(pm.environment.get('start8'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end8') + '\"').to.eql(pm.environment.get('end8'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"WAITING\"').to.eql('WAITING');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"4\"').to.eql(4);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Кухонный стол\"').to.eql('Кухонный стол');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment().add(2, 's');\r", + "var end = moment().add(1, 'h');\r", + "pm.environment.set('start8', start.format('YYYY-MM-DDTHH:mm:ss'));\r", + "pm.environment.set('end8', end.format('YYYY-MM-DDTHH:mm:ss'));\r", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"itemId\": 4,\n \"start\": \"{{start8}}\",\n \"end\": \"{{end8}}\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/bookings", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ] + } + }, + "response": [] + }, + { + "name": "Booking 8 set approve by user 6 (owner)", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Has booking get response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 8').to.eql(8);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start8') + '\"').to.eql(pm.environment.get('start8'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end8') + '\"').to.eql(pm.environment.get('end8'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"4\"').to.eql(4);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Кухонный стол\"').to.eql('Кухонный стол');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "6", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "true" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "8" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 2 get from user 1 without comments", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test item 'lastBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking, '\"lastBooking\" must be \"null\"').null;", + "});", + "pm.test(\"Test item 'nextBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", + "});", + "", + "pm.test(\"Test item 'comments' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('comments');", + " pm.expect(jsonData.comments.length, 'length of \"comments\" must be \"0\"').to.eql(0);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var time = setTimeout(function(){}, 3000);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 2 get from user 4 (owner) without comments", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "", + "pm.test(\"Test item 'lastBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking).to.have.property('id');", + " pm.expect(jsonData.lastBooking.id, '\"lastBooking.id\" must be \"6\"').to.eql(6);", + "});", + "pm.test(\"Test item 'lastBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking).to.have.property('bookerId');", + " pm.expect(jsonData.lastBooking.bookerId, '\"lastBooking.bookerId\" must be \"1\"').to.eql(1);", + "});", + "", + "pm.test(\"Test item 'nextBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking).to.have.property('id');", + " pm.expect(jsonData.nextBooking.id, '\"nextBooking.id\" must be \"1\"').to.eql(4);", + "});", + "pm.test(\"Test item 'nextBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking).to.have.property('bookerId');", + " pm.expect(jsonData.nextBooking.bookerId, '\"nextBooking.bookerId\" must be \"1\"').to.eql(5);", + "});", + "", + "pm.test(\"Test item 'comments' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('comments');", + " pm.expect(jsonData.comments.length, 'length of \"comments\" must be \"0\"').to.eql(0);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var time = setTimeout(function(){}, 3000);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Comment from user 4 to item 1 without booking failed", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + }, + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"text\": \"Comment for item 1\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId/comment", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId", + "comment" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Comment from user 1 to item 2 empty failed", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + }, + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"text\": \"\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId/comment", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId", + "comment" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Comment 1 from user 1 to item 2", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Test add comment to item 2 from user1\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.id, '\"id\" field').to.eql(1);", + " pm.expect(jsonData.text, '\"text\" field').to.eql(\"Add comment from user1\");", + " pm.expect(jsonData.authorName, '\"authorName\" field').to.eql(\"updateName\");", + " pm.expect(jsonData.created, '\"created\" field').not.null;", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment();\r", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + }, + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"text\": \"Add comment from user1\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId/comment", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId", + "comment" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 2 get by user 1 with comments", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test item 'lastBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking, '\"lastBooking\" must be \"null\"').null;", + "});", + "pm.test(\"Test item 'nextBooking' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", + "});", + "", + "pm.test(\"Test item 'comments' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('comments');", + " pm.expect(jsonData.comments.length, 'length of \"comments\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test item 'comments[0].id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.comments[0]).to.have.property('id');", + " pm.expect(jsonData.comments[0].id, '\"id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test item 'comments[0].text' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.comments[0]).to.have.property('text');", + " pm.expect(jsonData.comments[0].text, '\"text\" must be \"Add comment from user1\"').to.eql('Add comment from user1');", + "});", + "pm.test(\"Test item 'comments[0].authorName' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.comments[0]).to.have.property('authorName');", + " pm.expect(jsonData.comments[0].authorName, '\"authorName\" must be \"updateName\"').to.eql(\"updateName\");", + "});", + "pm.test(\"Test item 'comments[0].created' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.comments[0]).to.have.property('created');", + " pm.expect(new Date(jsonData.comments[0].created), '\"created\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 2 get by user 4 (owner) with comments", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 2').to.eql(2);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Аккумуляторная отвертка\"').to.eql('Аккумуляторная отвертка');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "", + "pm.test(\"Test item 'lastBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking).to.have.property('id');", + " pm.expect(jsonData.lastBooking.id, '\"lastBooking.id\" must be \"6\"').to.eql(6);", + "});", + "pm.test(\"Test item 'lastBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking).to.have.property('bookerId');", + " pm.expect(jsonData.lastBooking.bookerId, '\"lastBooking.bookerId\" must be \"1\"').to.eql(1);", + "});", + "", + "pm.test(\"Test item 'nextBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking).to.have.property('id');", + " pm.expect(jsonData.nextBooking.id, '\"nextBooking.id\" must be \"1\"').to.eql(4);", + "});", + "pm.test(\"Test item 'nextBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking).to.have.property('bookerId');", + " pm.expect(jsonData.nextBooking.bookerId, '\"nextBooking.bookerId\" must be \"1\"').to.eql(5);", + "});", + "", + "pm.test(\"Test item 'comments' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('comments');", + " pm.expect(jsonData.comments.length, 'length of \"comments\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test item 'comments[0].id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.comments[0]).to.have.property('id');", + " pm.expect(jsonData.comments[0].id, '\"id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test item 'comments[0].text' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.comments[0]).to.have.property('text');", + " pm.expect(jsonData.comments[0].text, '\"text\" must be \"Add comment from user1\"').to.eql('Add comment from user1');", + "});", + "pm.test(\"Test item 'comments[0].authorName' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.comments[0]).to.have.property('authorName');", + " pm.expect(jsonData.comments[0].authorName, '\"authorName\" must be \"updateName\"').to.eql(\"updateName\");", + "});", + "pm.test(\"Test item 'comments[0].created' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.comments[0]).to.have.property('created');", + " pm.expect(new Date(jsonData.comments[0].created), '\"created\" must be > \"' + pm.environment.get('currentDateTime') + '\"').to.greaterThan(new Date(pm.environment.get('currentDateTime')));", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking 7 set approve by owner future", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has booking create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test booking 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 7').to.eql(7);", + "});", + "pm.test(\"Test booking 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('start');", + " pm.expect(jsonData.start, '\"start\" must be \"' + pm.environment.get('start7') + '\"').to.eql(pm.environment.get('start7'));", + "});", + "pm.test(\"Test booking 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('end');", + " pm.expect(jsonData.end, '\"end\" must be \"' + pm.environment.get('end7') + '\"').to.eql(pm.environment.get('end7'));", + "});", + "pm.test(\"Test booking 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('status');", + " pm.expect(jsonData.status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('booker');", + " pm.expect(jsonData.booker).to.have.property('id');", + " pm.expect(jsonData.booker.id, '\"booker.id\" must be \"5\"').to.eql(5);", + "});", + "pm.test(\"Test booking 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('id');", + " pm.expect(jsonData.item.id, '\"item.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('item');", + " pm.expect(jsonData.item).to.have.property('name');", + " pm.expect(jsonData.item.name, '\"item.name\" must be \"Аккумуляторная дрель\"').to.eql('Аккумуляторная дрель');", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "PATCH", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/:bookingId?approved=true", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + ":bookingId" + ], + "query": [ + { + "key": "approved", + "value": "true" + } + ], + "variable": [ + { + "key": "bookingId", + "value": "7" + } + ] + } + }, + "response": [] + }, + { + "name": "Add comment to item 1 from user5 failed by future booking", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + }, + { + "key": "X-Sharer-User-Id", + "value": "5", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"text\": \"Add comment from user5\"\n}" + }, + "url": { + "raw": "{{baseUrl}}/items/:itemId/comment", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId", + "comment" + ], + "variable": [ + { + "key": "itemId", + "value": "1" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 1 by CURRENT state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 8').to.eql(8);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start8') + '\"').to.eql(pm.environment.get('start8'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end8') + '\"').to.eql(pm.environment.get('end8'));", + "});", + "pm.test(\"Test booking[1] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"4\"').to.eql(4);", + "});", + "pm.test(\"Test booking[1] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Кухонный стол\"').to.eql('Кухонный стол');", + "});", + "", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?state=CURRENT", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "state", + "value": "CURRENT" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 4 (owner) by CURRENT state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start5') + '\"').to.eql(pm.environment.get('start5'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end5') + '\"').to.eql(pm.environment.get('end5'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"REJECTED\"').to.eql('REJECTED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"3\"').to.eql(3);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Клей Момент\"').to.eql('Клей Момент');", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?state=CURRENT", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "state", + "value": "CURRENT" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 1 by PAST state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 6').to.eql(6);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start6') + '\"').to.eql(pm.environment.get('start6'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end6') + '\"').to.eql(pm.environment.get('end6'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?state=PAST", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "state", + "value": "PAST" + } + ] + } + }, + "response": [] + }, + { + "name": "Booking get all for user 4 (owner) by PAST state", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list booking response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 2').to.eql(2);", + "});", + "", + "pm.test(\"Test booking[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 6').to.eql(6);", + "});", + "pm.test(\"Test booking[0] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('start');", + " pm.expect(jsonData[0].start, '\"start\" must be \"' + pm.environment.get('start6') + '\"').to.eql(pm.environment.get('start6'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('end');", + " pm.expect(jsonData[0].end, '\"end\" must be \"' + pm.environment.get('end6') + '\"').to.eql(pm.environment.get('end6'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('status');", + " pm.expect(jsonData[0].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('booker');", + " pm.expect(jsonData[0].booker).to.have.property('id');", + " pm.expect(jsonData[0].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('id');", + " pm.expect(jsonData[0].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('item');", + " pm.expect(jsonData[0].item).to.have.property('name');", + " pm.expect(jsonData[0].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});", + "", + "pm.test(\"Test booking[1] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('id');", + " pm.expect(jsonData[1].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test booking[1] 'start' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('start');", + " pm.expect(jsonData[1].start, '\"start\" must be \"' + pm.environment.get('start') + '\"').to.eql(pm.environment.get('start'));", + "});", + "pm.test(\"Test booking[0] 'end' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('end');", + " pm.expect(jsonData[1].end, '\"end\" must be \"' + pm.environment.get('end') + '\"').to.eql(pm.environment.get('end'));", + "});", + "pm.test(\"Test booking[0] 'status' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('status');", + " pm.expect(jsonData[1].status, '\"status\" must be \"APPROVED\"').to.eql('APPROVED');", + "});", + "pm.test(\"Test booking[0] 'booker.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('booker');", + " pm.expect(jsonData[1].booker).to.have.property('id');", + " pm.expect(jsonData[1].booker.id, '\"booker.id\" must be \"1\"').to.eql(1);", + "});", + "pm.test(\"Test booking[0] 'item.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('id');", + " pm.expect(jsonData[1].item.id, '\"item.id\" must be \"2\"').to.eql(2);", + "});", + "pm.test(\"Test booking[0] 'item.name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[1]).to.have.property('item');", + " pm.expect(jsonData[1].item).to.have.property('name');", + " pm.expect(jsonData[1].item.name, '\"item.name\" must be \"Отвертка\"').to.eql('Отвертка');", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?state=PAST", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "state", + "value": "PAST" + } + ] + } + }, + "response": [] + }, + { + "name": "Item 4 get by user 6 (owner) without comments", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Has item update response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 4').to.eql(4);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Кухонный стол\"').to.eql('Кухонный стол');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Стол для празднования\"').to.eql('Стол для празднования');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "", + "pm.test(\"Test item 'lastBooking.id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking).to.have.property('id');", + " pm.expect(jsonData.lastBooking.id, '\"lastBooking.id\" must be \"8\"').to.eql(8);", + "});", + "pm.test(\"Test item 'lastBooking.bookerId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('lastBooking');", + " pm.expect(jsonData.lastBooking).to.have.property('bookerId');", + " pm.expect(jsonData.lastBooking.bookerId, '\"lastBooking.bookerId\" must be \"1\"').to.eql(1);", + "});", + "", + "pm.test(\"Test item 'nextBooking'\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('nextBooking');", + " pm.expect(jsonData.nextBooking, '\"nextBooking\" must be \"null\"').null;", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "6", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/items/:itemId", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items", + ":itemId" + ], + "variable": [ + { + "key": "itemId", + "value": "4" + } + ] + } + }, + "response": [] + } + ] + }, + { + "name": "item requests", + "item": [ + { + "name": "Add item request with wrong user", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,404,403]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "99", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"description\": \"Хотел бы воспользоваться щёткой для обуви\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{baseUrl}}/requests", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests" + ] + } + }, + "response": [] + }, + { + "name": "Add item request with empty description", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"description\": null\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{baseUrl}}/requests", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests" + ] + } + }, + "response": [] + }, + { + "name": "Requests get own by wrong user id", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,404,403]);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "99", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests" + ] + } + }, + "response": [] + }, + { + "name": "Requests get own by user id without requests", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item requests response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 0').to.eql(0);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests" + ] + } + }, + "response": [] + }, + { + "name": "Requests get all without pagination params", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item requests response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 0').to.eql(0);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/all", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "all" + ] + } + }, + "response": [] + }, + { + "name": "Requests get all with from = 0 & size = 0", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/all?from=0&size=0", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "all" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "0" + } + ] + } + }, + "response": [] + }, + { + "name": "Requests get all with from = -1 & size = 20", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/all?from=-1&size=20", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "all" + ], + "query": [ + { + "key": "from", + "value": "-1" + }, + { + "key": "size", + "value": "20" + } + ] + } + }, + "response": [] + }, + { + "name": "Requests get all with from = 0 & size = -1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/all?from=0&size=-1", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "all" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "-1" + } + ] + } + }, + "response": [] + }, + { + "name": "Requests get all with from = 0 & size = 20 when empty", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item requests response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 0').to.eql(0);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/all?from=0&size=20", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "all" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "20" + } + ] + } + }, + "response": [] + }, + { + "name": "Add item request 1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has item request create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item request 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item request 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", + "});", + "pm.test(\"Test item request 'created' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('created');", + " pm.expect(jsonData.created, '\"created\" must be not null').is.not.null;", + "", + " var current = pm.environment.get('currentDateTime');", + " var created = new Date(jsonData.created);", + " var future = new Date(current);", + " future.setSeconds(future.getSeconds() + 2);", + " pm.expect(created, '\"created\" must be > ' + pm.environment.get('currentDateTime')).to.gte(new Date(current));", + " pm.expect(created, '\"created\" must be < ' + future).to.lte(future);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"description\": \"Хотел бы воспользоваться щёткой для обуви\"\n}", + "options": { + "raw": { + "language": "json" + } + } + }, + "url": { + "raw": "{{baseUrl}}/requests", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests" + ] + } + }, + "response": [] + }, + { + "name": "Requests get own by user id with requests empty items", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item requests response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test item request[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item request[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", + "});", + "pm.test(\"Test item request[0] 'created' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('created');", + " pm.expect(jsonData[0].created, '\"created\" must be not null').is.not.null;", + "});", + "pm.test(\"Test item request[0] 'items' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('items');", + " pm.expect(jsonData[0].items, '\"items\" must be not null').is.not.null;", + " pm.expect(jsonData[0].items.length, 'items count in total').to.eql(0);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var time = setTimeout(function(){}, 1000);" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests" + ] + } + }, + "response": [] + }, + { + "name": "Add item 5 to request 1 from user 4", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200 or 201\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200,201]);", + "});", + "pm.test(\"Has item create response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "pm.test(\"Test item 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test item 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('name');", + " pm.expect(jsonData.name, '\"name\" must be \"Щётка для обуви\"').to.eql('Щётка для обуви');", + "});", + "pm.test(\"Test item 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Стандартная щётка для обуви\"').to.eql('Стандартная щётка для обуви');", + "});", + "pm.test(\"Test item 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('available');", + " pm.expect(jsonData.available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test item 'requestId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('requestId');", + " pm.expect(jsonData.requestId, '\"requestId\" must be \"1\"').to.eq(1);", + "});", + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "POST", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Content-Type", + "value": "application/json", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "body": { + "mode": "raw", + "raw": "{\n \"name\": \"Щётка для обуви\",\n \"description\": \"Стандартная щётка для обуви\",\n \"available\": true,\n \"requestId\": 1\n}" + }, + "url": { + "raw": "{{baseUrl}}/items", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "items" + ] + } + }, + "response": [] + }, + { + "name": "Requests get own by user id with requests", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item requests response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test item request[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item request[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", + "});", + "pm.test(\"Test item request[0] 'created' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('created');", + " pm.expect(jsonData[0].created, '\"created\" must be not null').is.not.null;", + " ", + " var created = new Date(jsonData[0].created);", + " var future = new Date(pm.environment.get('currentDateTime'));", + " pm.expect(created, '\"created\" must be < ' + pm.environment.get('currentDateTime')).to.lte(future);", + "});", + "pm.test(\"Test item request[0] 'items' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('items');", + " pm.expect(jsonData[0].items, '\"items\" must be not null').is.not.null;", + " pm.expect(jsonData[0].items.length, 'items count must be 1').to.eql(1);", + "});", + "pm.test(\"Test request[0].items[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('id');", + " pm.expect(jsonData[0].items[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test request[0].items[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('name');", + " pm.expect(jsonData[0].items[0].name, '\"name\" must be \"Щётка для обуви\"').to.eql('Щётка для обуви');", + "});", + "pm.test(\"Test request[0].items[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('description');", + " pm.expect(jsonData[0].items[0].description, '\"description\" must be \"Стандартная щётка для обуви\"').to.eql('Стандартная щётка для обуви');", + "});", + "pm.test(\"Test request[0].items[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('available');", + " pm.expect(jsonData[0].items[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test request[0].items[0] 'requestId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('requestId');", + " pm.expect(jsonData[0].items[0].requestId, '\"requestId\" must be \"1\"').to.eq(1);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss.sss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests" + ] + } + }, + "response": [] + }, + { + "name": "Requests get all with from = 0 & size = 20 for request owner", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item requests response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 0').to.eql(0);", + "});", + "" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/all?from=0&size=20", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "all" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "20" + } + ] + } + }, + "response": [] + }, + { + "name": "Requests get all with from = 0 & size = 20 for other user", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test list item requests response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'List length must be 1').to.eql(1);", + "});", + "", + "pm.test(\"Test item request[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('id');", + " pm.expect(jsonData[0].id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item request[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('description');", + " pm.expect(jsonData[0].description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", + "});", + "pm.test(\"Test item request[0] 'created' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('created');", + " pm.expect(jsonData[0].created, '\"created\" must be not null').is.not.null;", + " ", + " var created = new Date(jsonData[0].created);", + " var future = new Date(pm.environment.get('currentDateTime'));", + " pm.expect(created, '\"created\" must be < ' + pm.environment.get('currentDateTime')).to.lte(future);", + "});", + "pm.test(\"Test item request[0] 'items' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0]).to.have.property('items');", + " pm.expect(jsonData[0].items, '\"items\" must be not null').is.not.null;", + " pm.expect(jsonData[0].items.length, 'items count must be 1').to.eql(1);", + "});", + "pm.test(\"Test request[0].items[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('id');", + " pm.expect(jsonData[0].items[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test request[0].items[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('name');", + " pm.expect(jsonData[0].items[0].name, '\"name\" must be \"Щётка для обуви\"').to.eql('Щётка для обуви');", + "});", + "pm.test(\"Test request[0].items[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('description');", + " pm.expect(jsonData[0].items[0].description, '\"description\" must be \"Стандартная щётка для обуви\"').to.eql('Стандартная щётка для обуви');", + "});", + "pm.test(\"Test request[0].items[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('available');", + " pm.expect(jsonData[0].items[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test request[0].items[0] 'requestId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData[0].items[0]).to.have.property('requestId');", + " pm.expect(jsonData[0].items[0].requestId, '\"requestId\" must be \"1\"').to.eq(1);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss.sss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/all?from=0&size=20", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "all" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "20" + } + ] + } + }, + "response": [] + }, + { + "name": "Requests get by id for wrong user", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 500\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500, 404, 403]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "99", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/1", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "1" + ] + } + }, + "response": [] + }, + { + "name": "Requests get by wrong id", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 404\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([404]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/99", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "99" + ] + } + }, + "response": [] + }, + { + "name": "Requests get by id for other user", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test item request response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "", + "pm.test(\"Test item request 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item request 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", + "});", + "pm.test(\"Test item request 'created' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('created');", + " pm.expect(jsonData.created, '\"created\" must be not null').is.not.null;", + "", + " var created = new Date(jsonData.created);", + " var future = new Date(pm.environment.get('currentDateTime'));", + " pm.expect(created, '\"created\" must be < ' + pm.environment.get('currentDateTime')).to.lte(future);", + "});", + "pm.test(\"Test item request 'items' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('items');", + " pm.expect(jsonData.items, '\"items\" must be not null').is.not.null;", + " pm.expect(jsonData.items.length, 'items count must be 1').to.eql(1);", + "});", + "pm.test(\"Test request.items[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('id');", + " pm.expect(jsonData.items[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test request.items[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('name');", + " pm.expect(jsonData.items[0].name, '\"name\" must be \"Щётка для обуви\"').to.eql('Щётка для обуви');", + "});", + "pm.test(\"Test request.items[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('description');", + " pm.expect(jsonData.items[0].description, '\"description\" must be \"Стандартная щётка для обуви\"').to.eql('Стандартная щётка для обуви');", + "});", + "pm.test(\"Test request.items[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('available');", + " pm.expect(jsonData.items[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test request.items[0] 'requestId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('requestId');", + " pm.expect(jsonData.items[0].requestId, '\"requestId\" must be \"1\"').to.eq(1);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');\r", + "\r", + "var start = moment();\r", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss.sss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "4", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/1", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "1" + ] + } + }, + "response": [] + }, + { + "name": "Requests get by id", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.response.to.be.ok;", + "});", + "pm.test(\"Test item request response\", function () {", + " pm.response.to.be.withBody;", + " pm.response.to.be.json;", + "});", + "", + "pm.test(\"Test item request 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('id');", + " pm.expect(jsonData.id, '\"id\" must be 1').to.eql(1);", + "});", + "pm.test(\"Test item request 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('description');", + " pm.expect(jsonData.description, '\"description\" must be \"Хотел бы воспользоваться щёткой для обуви\"').to.eql(\"Хотел бы воспользоваться щёткой для обуви\");", + "});", + "pm.test(\"Test item request 'created' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('created');", + " pm.expect(jsonData.created, '\"created\" must be not null').is.not.null;", + "", + " var created = new Date(jsonData.created);", + " var future = new Date(pm.environment.get('currentDateTime'));", + " pm.expect(created, '\"created\" must be < ' + pm.environment.get('currentDateTime')).to.lte(future);", + "});", + "pm.test(\"Test item request 'items' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData).to.have.property('items');", + " pm.expect(jsonData.items, '\"items\" must be not null').is.not.null;", + " pm.expect(jsonData.items.length, 'items count must be 1').to.eql(1);", + "});", + "pm.test(\"Test request.items[0] 'id' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('id');", + " pm.expect(jsonData.items[0].id, '\"id\" must be 5').to.eql(5);", + "});", + "pm.test(\"Test request.items[0] 'name' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('name');", + " pm.expect(jsonData.items[0].name, '\"name\" must be \"Щётка для обуви\"').to.eql('Щётка для обуви');", + "});", + "pm.test(\"Test request.items[0] 'description' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('description');", + " pm.expect(jsonData.items[0].description, '\"description\" must be \"Стандартная щётка для обуви\"').to.eql('Стандартная щётка для обуви');", + "});", + "pm.test(\"Test request.items[0] 'available' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('available');", + " pm.expect(jsonData.items[0].available, '\"available\" must be \"true\"').to.true;", + "});", + "pm.test(\"Test request.items[0] 'requestId' field\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.items[0]).to.have.property('requestId');", + " pm.expect(jsonData.items[0].requestId, '\"requestId\" must be \"1\"').to.eq(1);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "var moment = require('moment');", + "", + "var start = moment();", + "pm.environment.set('currentDateTime', start.format('YYYY-MM-DDTHH:mm:ss.sss'));" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/requests/1", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "requests", + "1" + ] + } + }, + "response": [] + } + ] + }, + { + "name": "Pagination", + "item": [ + { + "name": "Bookings get all with from = 0 & size = 0", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?from=0&size=0", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "0" + } + ] + } + }, + "response": [] + }, + { + "name": "Bookings owner get all with from = 0 & size = 0", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?from=0&size=0", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "0" + } + ] + } + }, + "response": [] + }, + { + "name": "Bookings get all with from = -1 & size = 20", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?from=-1&size=20", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "from", + "value": "-1" + }, + { + "key": "size", + "value": "20" + } + ] + } + }, + "response": [] + }, + { + "name": "Bookings owner get all with from = -1 & size = 20", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?from=-1&size=20", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "from", + "value": "-1" + }, + { + "key": "size", + "value": "20" + } + ] + } + }, + "response": [] + }, + { + "name": "Bookings get all with from = 0 & size = -1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?from=0&size=-1", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "-1" + } + ] + } + }, + "response": [] + }, + { + "name": "Bookings owner get all with from = 0 & size = -1", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 400\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([500,400]);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?from=0&size=-1", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "from", + "value": "0" + }, + { + "key": "size", + "value": "-1" + } + ] + } + }, + "response": [] + }, + { + "name": "Bookings get all with from = 4 & size = 2 when all=5", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Test get all bookings\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'bookings count in total').to.eql(1);", + " pm.expect(jsonData[0].id, 'result[0]: \"id\" field').to.eql(1);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings?from=4&size=2", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings" + ], + "query": [ + { + "key": "from", + "value": "4" + }, + { + "key": "size", + "value": "2" + } + ] + } + }, + "response": [] + }, + { + "name": "Bookings owner get all with from = 1 & size = 1 when all=2", + "event": [ + { + "listen": "test", + "script": { + "exec": [ + "pm.test(\"Status code is 200\", function () {", + " pm.expect(pm.response.code).to.be.oneOf([200]);", + "});", + "pm.test(\"Test get all owner bookings\", function () {", + " var jsonData = pm.response.json();", + " pm.expect(jsonData.length, 'owner bookings count in total').to.eql(1);", + " pm.expect(jsonData[0].id, 'result[0]: \"id\" field').to.eql(3);", + "});" + ], + "type": "text/javascript" + } + }, + { + "listen": "prerequest", + "script": { + "exec": [ + "" + ], + "type": "text/javascript" + } + } + ], + "request": { + "method": "GET", + "header": [ + { + "key": "X-Sharer-User-Id", + "value": "1", + "type": "text" + }, + { + "key": "Accept", + "value": "*/*", + "type": "text" + } + ], + "url": { + "raw": "{{baseUrl}}/bookings/owner?from=1&size=1", + "host": [ + "{{baseUrl}}" + ], + "path": [ + "bookings", + "owner" + ], + "query": [ + { + "key": "from", + "value": "1" + }, + { + "key": "size", + "value": "1" + } + ] + } + }, + "response": [] + } + ] + } + ], + "variable": [ + { + "key": "baseUrl", + "value": "http://localhost:8080" + } + ] +} \ No newline at end of file diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..c7d26a9 --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,4 @@ +FROM amazoncorretto:11 +COPY target/*.jar shareit-server.jar +ENV JAVA_OPTS='-Xmx3g -Xms3g' +ENTRYPOINT ["java","-jar","/shareit-server.jar"] \ No newline at end of file diff --git a/server/pom.xml b/server/pom.xml new file mode 100644 index 0000000..566db3e --- /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/src/main/java/ru/practicum/shareit/ShareItApp.java b/server/src/main/java/ru/practicum/shareit/ShareItServer.java similarity index 73% rename from src/main/java/ru/practicum/shareit/ShareItApp.java rename to server/src/main/java/ru/practicum/shareit/ShareItServer.java index a00ad56..303541d 100644 --- a/src/main/java/ru/practicum/shareit/ShareItApp.java +++ b/server/src/main/java/ru/practicum/shareit/ShareItServer.java @@ -4,10 +4,10 @@ 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); } } diff --git a/src/main/java/ru/practicum/shareit/booking/BookingMapper.java b/server/src/main/java/ru/practicum/shareit/booking/BookingMapper.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/BookingMapper.java rename to server/src/main/java/ru/practicum/shareit/booking/BookingMapper.java diff --git a/src/main/java/ru/practicum/shareit/booking/BookingState.java b/server/src/main/java/ru/practicum/shareit/booking/BookingState.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/BookingState.java rename to server/src/main/java/ru/practicum/shareit/booking/BookingState.java diff --git a/src/main/java/ru/practicum/shareit/booking/controller/BookingController.java b/server/src/main/java/ru/practicum/shareit/booking/controller/BookingController.java similarity index 74% 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 4e9105e..e264460 100644 --- a/src/main/java/ru/practicum/shareit/booking/controller/BookingController.java +++ b/server/src/main/java/ru/practicum/shareit/booking/controller/BookingController.java @@ -1,18 +1,14 @@ package ru.practicum.shareit.booking.controller; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import ru.practicum.shareit.booking.dto.BookingDto; import ru.practicum.shareit.booking.service.BookingService; -import javax.validation.constraints.Min; -import javax.validation.constraints.PositiveOrZero; import java.util.List; @RestController @RequestMapping(path = "/bookings") -@Validated public class BookingController { private BookingService bookingService; @@ -42,16 +38,16 @@ public BookingDto getById(@PathVariable Long bookingId, @RequestHeader("X-Sharer @GetMapping public List getAllBookings(@RequestHeader("X-Sharer-User-Id") long userId, @RequestParam(name = "state", required = false, defaultValue = "ALL") String state, - @PositiveOrZero @Min(0) @RequestParam(value = "from", defaultValue = "0") Integer from, - @Min(1) @RequestParam(value = "size", defaultValue = "20") Integer size) throws Exception { + @RequestParam(value = "from", defaultValue = "0") Integer from, + @RequestParam(value = "size", defaultValue = "20") Integer size) throws Exception { return bookingService.getAll(userId, state, from, size); } @GetMapping("/owner") public List getItemsByAll(@RequestHeader("X-Sharer-User-Id") long userId, @RequestParam(name = "state", required = false, defaultValue = "ALL") String state, - @PositiveOrZero @Min(0) @RequestParam(value = "from", defaultValue = "0") Integer from, - @Min(1) @RequestParam(value = "size", defaultValue = "20") Integer size) throws Exception { + @RequestParam(value = "from", defaultValue = "0") Integer from, + @RequestParam(value = "size", defaultValue = "20") Integer size) throws Exception { return bookingService.getItemsForUser(userId, state, from, size); } diff --git a/src/main/java/ru/practicum/shareit/booking/dto/BookingDto.java b/server/src/main/java/ru/practicum/shareit/booking/dto/BookingDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/dto/BookingDto.java rename to server/src/main/java/ru/practicum/shareit/booking/dto/BookingDto.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/repository/BookingRepository.java b/server/src/main/java/ru/practicum/shareit/booking/repository/BookingRepository.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/repository/BookingRepository.java rename to server/src/main/java/ru/practicum/shareit/booking/repository/BookingRepository.java diff --git a/src/main/java/ru/practicum/shareit/booking/service/BookingService.java b/server/src/main/java/ru/practicum/shareit/booking/service/BookingService.java similarity index 100% rename from src/main/java/ru/practicum/shareit/booking/service/BookingService.java rename to server/src/main/java/ru/practicum/shareit/booking/service/BookingService.java diff --git a/src/main/java/ru/practicum/shareit/booking/service/BookingServiceImpl.java b/server/src/main/java/ru/practicum/shareit/booking/service/BookingServiceImpl.java similarity index 93% rename from src/main/java/ru/practicum/shareit/booking/service/BookingServiceImpl.java rename to server/src/main/java/ru/practicum/shareit/booking/service/BookingServiceImpl.java index fe3ac04..f708202 100644 --- a/src/main/java/ru/practicum/shareit/booking/service/BookingServiceImpl.java +++ b/server/src/main/java/ru/practicum/shareit/booking/service/BookingServiceImpl.java @@ -35,7 +35,6 @@ public BookingServiceImpl(UserRepository userRepository, ItemRepository itemRepo @Override public BookingDto create(BookingDto bookingDto, long userId) throws Exception { - checkBookingDates(bookingDto); Booking booking = BookingMapper.toBooking(bookingDto); booking.setStatus(BookingState.WAITING); User booker = userRepository.findById(userId).orElseThrow(() -> new UserNotFoundException("User not found")); @@ -156,16 +155,4 @@ public List getItemsForUser(long userId, String status, Integer from .collect(Collectors.toList()); } - - private void checkBookingDates(BookingDto bookingDto) throws ValidationException { - if (bookingDto.getStart() == null || bookingDto.getEnd() == null) { - throw new ValidationException("Start or End is null"); - } - LocalDateTime now = LocalDateTime.now(); - if (bookingDto.getStart().isBefore(now) || bookingDto.getEnd().isBefore(now) - || bookingDto.getStart().equals(bookingDto.getEnd()) - || bookingDto.getStart().isAfter(bookingDto.getEnd())) { - throw new ValidationException("Start or End is wrong"); - } - } } diff --git a/server/src/main/java/ru/practicum/shareit/exception/ApiSubError.java b/server/src/main/java/ru/practicum/shareit/exception/ApiSubError.java new file mode 100644 index 0000000..3972fcd --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/exception/ApiSubError.java @@ -0,0 +1,4 @@ +package ru.practicum.shareit.exception; + +public interface ApiSubError { +} diff --git a/server/src/main/java/ru/practicum/shareit/exception/ApplicationError.java b/server/src/main/java/ru/practicum/shareit/exception/ApplicationError.java new file mode 100644 index 0000000..0ace125 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/exception/ApplicationError.java @@ -0,0 +1,52 @@ +package ru.practicum.shareit.exception; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springframework.http.HttpStatus; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +@Data +@EqualsAndHashCode(callSuper = false) +public class ApplicationError { + + private HttpStatus status; + + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy") + private LocalDateTime timestamp; + + private String error; + + private List errors; + + private ApplicationError() { + timestamp = LocalDateTime.now(); + errors = new ArrayList<>(); + } + + public ApplicationError(HttpStatus status) { + this(); + this.status = status; + } + + public ApplicationError(HttpStatus status, Exception ex) { + this(); + this.status = status; + this.error = "Ошибка валидации"; + if (ex instanceof ApiSubError) { + errors.add((ApiSubError) ex); + } + } + + public ApplicationError(HttpStatus status, String error, Exception ex) { + this(); + this.status = status; + this.error = error; + if (ex instanceof ApiSubError) { + errors.add((ApiSubError) ex); + } + } +} diff --git a/server/src/main/java/ru/practicum/shareit/exception/BookingNotFoundException.java b/server/src/main/java/ru/practicum/shareit/exception/BookingNotFoundException.java new file mode 100644 index 0000000..7d39315 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/exception/BookingNotFoundException.java @@ -0,0 +1,12 @@ +package ru.practicum.shareit.exception; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +@Data +@JsonIgnoreProperties({"cause", "stackTrace", "suppressed", "localizedMessage"}) +public class BookingNotFoundException extends Exception implements ApiSubError { + public BookingNotFoundException(String message) { + super(message); + } +} diff --git a/src/main/java/ru/practicum/shareit/exception/ControllerExceptionHandler.java b/server/src/main/java/ru/practicum/shareit/exception/ControllerExceptionHandler.java similarity index 100% rename from src/main/java/ru/practicum/shareit/exception/ControllerExceptionHandler.java rename to server/src/main/java/ru/practicum/shareit/exception/ControllerExceptionHandler.java diff --git a/server/src/main/java/ru/practicum/shareit/exception/DuplicateValueException.java b/server/src/main/java/ru/practicum/shareit/exception/DuplicateValueException.java new file mode 100644 index 0000000..bfa809a --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/exception/DuplicateValueException.java @@ -0,0 +1,12 @@ +package ru.practicum.shareit.exception; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +@Data +@JsonIgnoreProperties({"cause", "stackTrace", "suppressed", "localizedMessage"}) +public class DuplicateValueException extends Exception implements ApiSubError { + public DuplicateValueException(String message) { + super(message); + } +} diff --git a/server/src/main/java/ru/practicum/shareit/exception/ItemNotAvailableException.java b/server/src/main/java/ru/practicum/shareit/exception/ItemNotAvailableException.java new file mode 100644 index 0000000..c5d0f46 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/exception/ItemNotAvailableException.java @@ -0,0 +1,12 @@ +package ru.practicum.shareit.exception; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +@Data +@JsonIgnoreProperties({"cause", "stackTrace", "suppressed", "localizedMessage"}) +public class ItemNotAvailableException extends Exception implements ApiSubError { + public ItemNotAvailableException(String message) { + super(message); + } +} diff --git a/server/src/main/java/ru/practicum/shareit/exception/ItemNotFoundException.java b/server/src/main/java/ru/practicum/shareit/exception/ItemNotFoundException.java new file mode 100644 index 0000000..5c87fbf --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/exception/ItemNotFoundException.java @@ -0,0 +1,12 @@ +package ru.practicum.shareit.exception; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +@Data +@JsonIgnoreProperties({"cause", "stackTrace", "suppressed", "localizedMessage"}) +public class ItemNotFoundException extends Exception implements ApiSubError { + public ItemNotFoundException(String message) { + super(message); + } +} diff --git a/server/src/main/java/ru/practicum/shareit/exception/ItemRequestNotFoundException.java b/server/src/main/java/ru/practicum/shareit/exception/ItemRequestNotFoundException.java new file mode 100644 index 0000000..0f1455d --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/exception/ItemRequestNotFoundException.java @@ -0,0 +1,12 @@ +package ru.practicum.shareit.exception; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +@Data +@JsonIgnoreProperties({"cause", "stackTrace", "suppressed", "localizedMessage"}) +public class ItemRequestNotFoundException extends Exception implements ApiSubError { + public ItemRequestNotFoundException(String message) { + super(message); + } +} diff --git a/server/src/main/java/ru/practicum/shareit/exception/UnauthorizedException.java b/server/src/main/java/ru/practicum/shareit/exception/UnauthorizedException.java new file mode 100644 index 0000000..1da4f2d --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/exception/UnauthorizedException.java @@ -0,0 +1,12 @@ +package ru.practicum.shareit.exception; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +@Data +@JsonIgnoreProperties({"cause", "stackTrace", "suppressed", "localizedMessage"}) +public class UnauthorizedException extends Exception implements ApiSubError { + public UnauthorizedException(String message) { + super(message); + } +} diff --git a/server/src/main/java/ru/practicum/shareit/exception/UserNotFoundException.java b/server/src/main/java/ru/practicum/shareit/exception/UserNotFoundException.java new file mode 100644 index 0000000..76089b6 --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/exception/UserNotFoundException.java @@ -0,0 +1,12 @@ +package ru.practicum.shareit.exception; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +@Data +@JsonIgnoreProperties({"cause", "stackTrace", "suppressed", "localizedMessage"}) +public class UserNotFoundException extends Exception implements ApiSubError { + public UserNotFoundException(String message) { + super(message); + } +} diff --git a/server/src/main/java/ru/practicum/shareit/exception/ValidationException.java b/server/src/main/java/ru/practicum/shareit/exception/ValidationException.java new file mode 100644 index 0000000..81940eb --- /dev/null +++ b/server/src/main/java/ru/practicum/shareit/exception/ValidationException.java @@ -0,0 +1,27 @@ +package ru.practicum.shareit.exception; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import lombok.Data; + +@Data +@JsonIgnoreProperties({"cause", "stackTrace", "suppressed", "localizedMessage"}) +public class ValidationException extends Exception implements ApiSubError { + + private String object; + private String field; + private Object rejectedValue; + private String message; + + public ValidationException(Object object, String message, String field, Object rejectedValue) { + super(message); + this.field = field; + this.rejectedValue = rejectedValue; + this.object = object.getClass().getName(); + this.message = message; + } + + public ValidationException(String message) { + super(message); + this.message = message; + } +} diff --git a/src/main/java/ru/practicum/shareit/item/CommentMapper.java b/server/src/main/java/ru/practicum/shareit/item/CommentMapper.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/CommentMapper.java rename to server/src/main/java/ru/practicum/shareit/item/CommentMapper.java diff --git a/src/main/java/ru/practicum/shareit/item/ItemMapper.java b/server/src/main/java/ru/practicum/shareit/item/ItemMapper.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/ItemMapper.java rename to server/src/main/java/ru/practicum/shareit/item/ItemMapper.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 79% 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 e1f1c7b..3f517b6 100644 --- a/src/main/java/ru/practicum/shareit/item/controller/ItemController.java +++ b/server/src/main/java/ru/practicum/shareit/item/controller/ItemController.java @@ -7,8 +7,6 @@ import ru.practicum.shareit.item.dto.ItemDto; import ru.practicum.shareit.item.service.ItemService; -import javax.validation.constraints.Min; -import javax.validation.constraints.PositiveOrZero; import java.util.List; @RestController @@ -48,15 +46,15 @@ public ItemDto getById(@PathVariable long id, @GetMapping public List getAll(@RequestHeader("X-Sharer-User-Id") long userId, - @PositiveOrZero @Min(0) @RequestParam(value = "from", defaultValue = "0") Integer from, - @Min(1) @RequestParam(value = "size", defaultValue = "10") Integer size) { + @RequestParam(value = "from", defaultValue = "0") Integer from, + @RequestParam(value = "size", defaultValue = "10") Integer size) { return service.getAll(userId, from, size); } @GetMapping("/search") public List search(@RequestParam(name = "text") String text, - @PositiveOrZero @Min(0) @RequestParam(value = "from", defaultValue = "0") Integer from, - @Min(1) @RequestParam(value = "size", defaultValue = "10") Integer size) { + @RequestParam(value = "from", defaultValue = "0") Integer from, + @RequestParam(value = "size", defaultValue = "10") Integer size) { return service.search(text, from, size); } diff --git a/src/main/java/ru/practicum/shareit/item/dto/CommentDto.java b/server/src/main/java/ru/practicum/shareit/item/dto/CommentDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/dto/CommentDto.java rename to server/src/main/java/ru/practicum/shareit/item/dto/CommentDto.java diff --git a/src/main/java/ru/practicum/shareit/item/dto/ItemDto.java b/server/src/main/java/ru/practicum/shareit/item/dto/ItemDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/dto/ItemDto.java rename to server/src/main/java/ru/practicum/shareit/item/dto/ItemDto.java diff --git a/src/main/java/ru/practicum/shareit/item/dto/ItemDtoShort.java b/server/src/main/java/ru/practicum/shareit/item/dto/ItemDtoShort.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/dto/ItemDtoShort.java rename to server/src/main/java/ru/practicum/shareit/item/dto/ItemDtoShort.java diff --git a/src/main/java/ru/practicum/shareit/item/model/Comment.java b/server/src/main/java/ru/practicum/shareit/item/model/Comment.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/model/Comment.java rename to server/src/main/java/ru/practicum/shareit/item/model/Comment.java 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/CommentRepository.java b/server/src/main/java/ru/practicum/shareit/item/repository/CommentRepository.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/repository/CommentRepository.java rename to server/src/main/java/ru/practicum/shareit/item/repository/CommentRepository.java diff --git a/src/main/java/ru/practicum/shareit/item/repository/ItemRepository.java b/server/src/main/java/ru/practicum/shareit/item/repository/ItemRepository.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/repository/ItemRepository.java rename to server/src/main/java/ru/practicum/shareit/item/repository/ItemRepository.java diff --git a/src/main/java/ru/practicum/shareit/item/service/ItemService.java b/server/src/main/java/ru/practicum/shareit/item/service/ItemService.java similarity index 100% rename from src/main/java/ru/practicum/shareit/item/service/ItemService.java rename to server/src/main/java/ru/practicum/shareit/item/service/ItemService.java diff --git a/src/main/java/ru/practicum/shareit/item/service/ItemServiceImpl.java b/server/src/main/java/ru/practicum/shareit/item/service/ItemServiceImpl.java similarity index 98% rename from src/main/java/ru/practicum/shareit/item/service/ItemServiceImpl.java rename to server/src/main/java/ru/practicum/shareit/item/service/ItemServiceImpl.java index 77b0abf..779000f 100644 --- a/src/main/java/ru/practicum/shareit/item/service/ItemServiceImpl.java +++ b/server/src/main/java/ru/practicum/shareit/item/service/ItemServiceImpl.java @@ -130,7 +130,7 @@ public List getAll(long userId, Integer from, Integer size) { itemDto.setNextBooking(next.get(item.getId()) == null ? null : BookingMapper.toBookingDto(next.get(item.getId()).get(0))); itemDtos.add(itemDto); }); - return itemDtos; + return itemDtos.stream().sorted(Comparator.comparing(ItemDto::getId)).collect(Collectors.toList()); } @Override diff --git a/src/main/java/ru/practicum/shareit/request/ItemRequestMapper.java b/server/src/main/java/ru/practicum/shareit/request/ItemRequestMapper.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/ItemRequestMapper.java rename to server/src/main/java/ru/practicum/shareit/request/ItemRequestMapper.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 90% 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 caa24f6..fc192fa 100644 --- a/src/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java +++ b/server/src/main/java/ru/practicum/shareit/request/controller/ItemRequestController.java @@ -6,7 +6,6 @@ import ru.practicum.shareit.request.dto.ItemRequestDto; import ru.practicum.shareit.request.service.ItemRequestService; -import javax.validation.constraints.PositiveOrZero; import java.util.List; @RestController @@ -33,7 +32,7 @@ public List getItemRequests(@RequestHeader("X-Sharer-User-Id") L @GetMapping("/all") public List getAllItemRequests(@RequestHeader("X-Sharer-User-Id") Long userId, - @PositiveOrZero @RequestParam(value = "from", required = false) Integer from, + @RequestParam(value = "from", required = false) Integer from, @RequestParam(value = "size", required = false) Integer size) throws Exception { return service.getAllUserRequests(userId, from, size); } diff --git a/src/main/java/ru/practicum/shareit/request/dto/ItemRequestDto.java b/server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestDto.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/dto/ItemRequestDto.java rename to server/src/main/java/ru/practicum/shareit/request/dto/ItemRequestDto.java diff --git a/src/main/java/ru/practicum/shareit/request/model/ItemRequest.java b/server/src/main/java/ru/practicum/shareit/request/model/ItemRequest.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/model/ItemRequest.java rename to server/src/main/java/ru/practicum/shareit/request/model/ItemRequest.java diff --git a/src/main/java/ru/practicum/shareit/request/repository/ItemRequestRepository.java b/server/src/main/java/ru/practicum/shareit/request/repository/ItemRequestRepository.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/repository/ItemRequestRepository.java rename to server/src/main/java/ru/practicum/shareit/request/repository/ItemRequestRepository.java diff --git a/src/main/java/ru/practicum/shareit/request/service/ItemRequestService.java b/server/src/main/java/ru/practicum/shareit/request/service/ItemRequestService.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/service/ItemRequestService.java rename to server/src/main/java/ru/practicum/shareit/request/service/ItemRequestService.java diff --git a/src/main/java/ru/practicum/shareit/request/service/ItemRequestServiceImpl.java b/server/src/main/java/ru/practicum/shareit/request/service/ItemRequestServiceImpl.java similarity index 100% rename from src/main/java/ru/practicum/shareit/request/service/ItemRequestServiceImpl.java rename to server/src/main/java/ru/practicum/shareit/request/service/ItemRequestServiceImpl.java diff --git a/src/main/java/ru/practicum/shareit/user/UserMapper.java b/server/src/main/java/ru/practicum/shareit/user/UserMapper.java similarity index 100% rename from src/main/java/ru/practicum/shareit/user/UserMapper.java rename to server/src/main/java/ru/practicum/shareit/user/UserMapper.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 82% 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 03f4a1a..c56f2cd 100644 --- a/src/main/java/ru/practicum/shareit/user/controller/UserController.java +++ b/server/src/main/java/ru/practicum/shareit/user/controller/UserController.java @@ -5,7 +5,6 @@ import ru.practicum.shareit.user.dto.UserDto; import ru.practicum.shareit.user.service.UserService; -import javax.validation.Valid; import java.util.List; @RestController @@ -19,12 +18,12 @@ public UserController(UserService service) { } @PostMapping - public UserDto create(@RequestBody @Valid UserDto userDto) throws Exception { + public UserDto create(@RequestBody UserDto userDto) throws Exception { return service.create(userDto); } @PatchMapping("/{id}") - public UserDto update(@PathVariable long id, @RequestBody @Valid UserDto userDto) throws Exception { + public UserDto update(@PathVariable long id, @RequestBody UserDto userDto) throws Exception { return service.update(id, userDto); } diff --git a/src/main/java/ru/practicum/shareit/user/dto/UserDto.java b/server/src/main/java/ru/practicum/shareit/user/dto/UserDto.java similarity index 75% rename from src/main/java/ru/practicum/shareit/user/dto/UserDto.java rename to server/src/main/java/ru/practicum/shareit/user/dto/UserDto.java index bbc117e..708b124 100644 --- a/src/main/java/ru/practicum/shareit/user/dto/UserDto.java +++ b/server/src/main/java/ru/practicum/shareit/user/dto/UserDto.java @@ -2,13 +2,11 @@ import lombok.Data; -import javax.validation.constraints.Email; - @Data public class UserDto { private long id; private String name; - @Email + private String email; } diff --git a/src/main/java/ru/practicum/shareit/user/dto/UserDtoShort.java b/server/src/main/java/ru/practicum/shareit/user/dto/UserDtoShort.java similarity index 100% rename from src/main/java/ru/practicum/shareit/user/dto/UserDtoShort.java rename to server/src/main/java/ru/practicum/shareit/user/dto/UserDtoShort.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/UserRepository.java b/server/src/main/java/ru/practicum/shareit/user/repository/UserRepository.java similarity index 100% rename from src/main/java/ru/practicum/shareit/user/repository/UserRepository.java rename to server/src/main/java/ru/practicum/shareit/user/repository/UserRepository.java diff --git a/src/main/java/ru/practicum/shareit/user/service/UserService.java b/server/src/main/java/ru/practicum/shareit/user/service/UserService.java similarity index 100% rename from src/main/java/ru/practicum/shareit/user/service/UserService.java rename to server/src/main/java/ru/practicum/shareit/user/service/UserService.java diff --git a/src/main/java/ru/practicum/shareit/user/service/UserServiceImpl.java b/server/src/main/java/ru/practicum/shareit/user/service/UserServiceImpl.java similarity index 80% rename from src/main/java/ru/practicum/shareit/user/service/UserServiceImpl.java rename to server/src/main/java/ru/practicum/shareit/user/service/UserServiceImpl.java index 56a1700..476f566 100644 --- a/src/main/java/ru/practicum/shareit/user/service/UserServiceImpl.java +++ b/server/src/main/java/ru/practicum/shareit/user/service/UserServiceImpl.java @@ -2,9 +2,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import ru.practicum.shareit.exception.DuplicateValueException; import ru.practicum.shareit.exception.UserNotFoundException; -import ru.practicum.shareit.exception.ValidationException; import ru.practicum.shareit.user.UserMapper; import ru.practicum.shareit.user.dto.UserDto; import ru.practicum.shareit.user.model.User; @@ -24,7 +22,6 @@ public UserServiceImpl(UserRepository userRepository) { @Override public UserDto create(UserDto userDto) throws Exception { - validateUser(userDto); User user = new User(); user.setName(userDto.getName()); user.setEmail(userDto.getEmail()); @@ -63,12 +60,4 @@ public List getAll() { return userRepository.findAll().stream().map(UserMapper::toUserDto).collect(Collectors.toList()); } - private void validateUser(UserDto userDto) throws ValidationException, DuplicateValueException { - if (userDto.getEmail() == null) { - throw new ValidationException("Email is null!"); - } - if (userDto.getName() == null || userDto.getName().isBlank()) { - throw new ValidationException("Name is null or empty"); - } - } } diff --git a/server/src/main/resources/application.properties b/server/src/main/resources/application.properties new file mode 100644 index 0000000..fd9d086 --- /dev/null +++ b/server/src/main/resources/application.properties @@ -0,0 +1,23 @@ +server.port=9090 + +spring.jpa.hibernate.ddl-auto=create-drop +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/postgres +spring.datasource.username=postgres +spring.datasource.password=postgres + +#spring.datasource.url=jdbc:postgresql://${DB_HOST}:${DB_PORT}/${DB_NAME} +#spring.datasource.username=${POSTGRES_USER} +#spring.datasource.password=${POSTGRES_PASSWORD} + +#--- +#spring.config.activate.on-profile=ci,test +#spring.datasource.driverClassName=org.h2.Driver +#spring.datasource.url=jdbc:h2:mem:shareit +#spring.datasource.username=test +#spring.datasource.password=test \ No newline at end of file diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties deleted file mode 100644 index 25af65d..0000000 --- a/src/main/resources/application.properties +++ /dev/null @@ -1,18 +0,0 @@ -spring.jpa.hibernate.ddl-auto=create-drop -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 - -#--- -# TODO Append connection to DB -#--- -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 diff --git a/src/main/resources/schema.sql b/src/main/resources/schema.sql deleted file mode 100644 index 431426c..0000000 --- a/src/main/resources/schema.sql +++ /dev/null @@ -1,51 +0,0 @@ -create TABLE IF NOT EXISTS users -( - id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, - email VARCHAR (512) NOT NULL, - name VARCHAR (512) NOT NULL, - CONSTRAINT pk_user PRIMARY KEY (id), - CONSTRAINT UQ_USER_EMAIL UNIQUE (email)); - -create TABLE IF NOT EXISTS item_requests -( - id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, - description VARCHAR (1024) NOT NULL, - requester_id BIGINT not null, - created TIMESTAMP not null, - CONSTRAINT pk_item_request PRIMARY KEY (id), - CONSTRAINT FK_ITEM_REQUEST_REQUESTER FOREIGN KEY (requester_id) REFERENCES users (id)); - -create TABLE IF NOT EXISTS items -( - id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, - description VARCHAR (1024) NOT NULL, - name VARCHAR(512) NOT NULL, - available BOOLEAN DEFAULT TRUE, - owner_id BIGINT, - request_id BIGINT, - CONSTRAINT pk_item PRIMARY KEY (id), - CONSTRAINT FK_ITEM_REQUEST FOREIGN KEY (request_id) REFERENCES item_requests(id), - CONSTRAINT FK_ITEM_OWNER FOREIGN KEY (owner_id) REFERENCES users (id)); - -create TABLE IF NOT EXISTS bookings -( - id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, - booking_start TIMESTAMP NOT NULL, - booking_end TIMESTAMP NOT NULL, - booking_status VARCHAR(512) NOT NULL, - booker_id BIGINT, - item_id BIGINT, - CONSTRAINT pk_booking PRIMARY KEY(id), - CONSTRAINT FK_BOOKING_OWNER FOREIGN KEY(booker_id) REFERENCES users(id), - CONSTRAINT FK_BOOKING_ITEM FOREIGN KEY(item_id) REFERENCES items (id)); - -create TABLE IF NOT EXISTS comments -( - id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, - text VARCHAR (1024) NOT NULL, - item BIGINT, - author BIGINT, - created TIMESTAMP NOT NULL, - CONSTRAINT pk_comment PRIMARY KEY(id), - CONSTRAINT FK_COMMENT_OWNER FOREIGN KEY(author) REFERENCES users(id), - CONSTRAINT FK_COMMENT_ITEM FOREIGN KEY(item) REFERENCES items (id)); \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/BaseTest.java b/src/test/java/ru/practicum/shareit/BaseTest.java deleted file mode 100644 index 109cc08..0000000 --- a/src/test/java/ru/practicum/shareit/BaseTest.java +++ /dev/null @@ -1,121 +0,0 @@ -package ru.practicum.shareit; - -import ru.practicum.shareit.booking.BookingState; -import ru.practicum.shareit.booking.dto.BookingDto; -import ru.practicum.shareit.booking.model.Booking; -import ru.practicum.shareit.item.dto.CommentDto; -import ru.practicum.shareit.item.dto.ItemDto; -import ru.practicum.shareit.item.model.Comment; -import ru.practicum.shareit.item.model.Item; -import ru.practicum.shareit.request.dto.ItemRequestDto; -import ru.practicum.shareit.request.model.ItemRequest; -import ru.practicum.shareit.user.dto.UserDto; -import ru.practicum.shareit.user.model.User; - -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; - -public class BaseTest { - - protected final String xShareUserId = "X-Sharer-User-Id"; - protected final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - - - protected UserDto buildUserDto(Long id, String email, String name) { - UserDto userDto = new UserDto(); - userDto.setId(id); - userDto.setEmail(email); - userDto.setName(name); - return userDto; - } - - protected static ItemDto buildItemDto(Long id, String name, String description, Boolean available) { - ItemDto itemDto = new ItemDto(); - itemDto.setId(id); - itemDto.setName(name); - itemDto.setDescription(description); - itemDto.setAvailable(available); - itemDto.setRequestId(3L); - return itemDto; - } - - protected Item buildItem(Long id, String name, String description, boolean available, User owner, ItemRequest itemRequest) { - Item item = new Item(); - item.setId(id); - item.setName(name); - item.setDescription(description); - item.setAvailable(available); - item.setOwner(owner); - item.setRequest(itemRequest); - return item; - } - - protected static BookingDto buildBookingDto(Long id, Long itemId, Long bookerId, LocalDateTime start, LocalDateTime end, BookingState status) { - BookingDto bookingDto = new BookingDto(); - bookingDto.setId(id); - bookingDto.setItemId(itemId); - bookingDto.setStart(start); - bookingDto.setEnd(end); - bookingDto.setBookerId(bookerId); - bookingDto.setStatus(status); - return bookingDto; - } - - protected static Booking buildBooking(Long id, Item item, User booker, LocalDateTime start, LocalDateTime end, BookingState status) { - Booking booking = new Booking(); - booking.setId(id); - booking.setItem(item); - booking.setStart(start); - booking.setEnd(end); - booking.setBooker(booker); - booking.setStatus(status); - return booking; - } - - - protected User buildUser(Long id, String email, String name) { - User user = new User(); - user.setId(id); - user.setEmail(email); - user.setName(name); - return user; - } - - protected LocalDateTime getDateFromString(String dateString) { - return LocalDateTime.parse(dateString, formatter); - } - - protected CommentDto buildCommentDto(Long id, String text, LocalDateTime created, String name) { - CommentDto commentDto = new CommentDto(); - commentDto.setId(id); - commentDto.setText(text); - commentDto.setCreated(created); - commentDto.setAuthorName(name); - return commentDto; - } - - protected Comment buildComment(Long id, String text, LocalDateTime created, String name, User user) { - Comment comment = new Comment(); - comment.setId(id); - comment.setText(text); - comment.setCreated(created); - comment.setAuthor(user); - return comment; - } - - protected ItemRequestDto buildItemRequestDto(Long id, Long requester, String description) { - ItemRequestDto itemRequestDto = new ItemRequestDto(); - itemRequestDto.setId(id); - itemRequestDto.setRequester(requester); - itemRequestDto.setDescription(description); - return itemRequestDto; - } - - protected ItemRequest buildItemRequest(Long id, User requester, String description) { - ItemRequest itemRequest = new ItemRequest(); - itemRequest.setId(id); - itemRequest.setRequester(requester); - itemRequest.setDescription(description); - return itemRequest; - } -} diff --git a/src/test/java/ru/practicum/shareit/ShareItTests.java b/src/test/java/ru/practicum/shareit/ShareItTests.java deleted file mode 100644 index 4d79052..0000000 --- a/src/test/java/ru/practicum/shareit/ShareItTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package ru.practicum.shareit; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class ShareItTests { - - @Test - void contextLoads() { - } - -} diff --git a/src/test/java/ru/practicum/shareit/booking/controller/BookingControllerTest.java b/src/test/java/ru/practicum/shareit/booking/controller/BookingControllerTest.java deleted file mode 100644 index 693531a..0000000 --- a/src/test/java/ru/practicum/shareit/booking/controller/BookingControllerTest.java +++ /dev/null @@ -1,320 +0,0 @@ -package ru.practicum.shareit.booking.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import ru.practicum.shareit.BaseTest; -import ru.practicum.shareit.booking.BookingState; -import ru.practicum.shareit.booking.dto.BookingDto; -import ru.practicum.shareit.booking.service.BookingServiceImpl; -import ru.practicum.shareit.exception.*; - -import java.util.List; - -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@AutoConfigureMockMvc -@WebMvcTest({BookingController.class}) -class BookingControllerTest extends BaseTest { - - @Autowired - private MockMvc mockMvc; - @Autowired - private ObjectMapper mapper; - @MockBean - private BookingServiceImpl service; - - @Test - void createBookingHappyFlow() throws Exception { - when(service.create(any(), anyLong())).thenReturn(buildBookingDto( - 43L, - 17L, - 38L, - getDateFromString("2023-04-15 15:00:00"), - getDateFromString("2023-04-17 12:00:00"), - BookingState.WAITING)); - mockMvc.perform(post("/bookings") - .header(xShareUserId, 38) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new BookingDto()))) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(43)) - .andExpect(jsonPath("$.start").value("2023-04-15T15:00:00")) - .andExpect(jsonPath("$.end").value("2023-04-17T12:00:00")) - .andExpect(jsonPath("$.status").value("WAITING")) - .andExpect(jsonPath("$.bookerId").value(38)) - .andExpect(jsonPath("$.itemId").value(17)); - } - - @Test - void createBookingUserNotFound() throws Exception { - when(service.create(any(), anyLong())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(post("/bookings") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new BookingDto()))) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void createBookingItemNotFound() throws Exception { - when(service.create(any(), anyLong())).thenThrow(new ItemNotFoundException("Item not found")); - - mockMvc.perform(post("/bookings") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new BookingDto()))) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void createBookingItemNotAvailable() throws Exception { - when(service.create(any(), anyLong())).thenThrow(new ItemNotAvailableException("Item not available")); - - mockMvc.perform(post("/bookings") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new BookingDto()))) - .andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.error").value("Ошибка валидации")); - } - - @Test - void updateBookingHappyFlow() throws Exception { - when(service.update(anyLong(), any(), anyLong(), anyBoolean())).thenReturn(buildBookingDto( - 43L, - 17L, - 38L, - getDateFromString("2023-04-15 15:00:00"), - getDateFromString("2023-04-17 12:00:00"), - BookingState.REJECTED)); - mockMvc.perform(patch("/bookings/14") - .param("approved", "false") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new BookingDto()))) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(43)) - .andExpect(jsonPath("$.start").value("2023-04-15T15:00:00")) - .andExpect(jsonPath("$.end").value("2023-04-17T12:00:00")) - .andExpect(jsonPath("$.status").value("REJECTED")) - .andExpect(jsonPath("$.bookerId").value(38)) - .andExpect(jsonPath("$.itemId").value(17)); - } - - @Test - void updateBookingBookerNotFound() throws Exception { - when(service.update(anyLong(), any(), anyLong(), anyBoolean())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(patch("/bookings/14") - .param("approved", "true") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new BookingDto()))) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void updateBookingBookingNotFound() throws Exception { - when(service.update(anyLong(), any(), anyLong(), anyBoolean())).thenThrow(new BookingNotFoundException("Booking not found")); - - mockMvc.perform(patch("/bookings/14") - .param("approved", "true") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new BookingDto()))) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void updateBookingItemNotFound() throws Exception { - when(service.update(anyLong(), any(), anyLong(), anyBoolean())).thenThrow(new ItemNotFoundException("Item not found")); - - mockMvc.perform(patch("/bookings/14") - .param("approved", "true") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new BookingDto()))) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void updateBookingValidationError() throws Exception { - when(service.update(anyLong(), any(), anyLong(), anyBoolean())).thenThrow(new ValidationException("Status is approved.")); - - mockMvc.perform(patch("/bookings/14") - .param("approved", "true") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new BookingDto()))) - .andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.error").value("Status is approved.")); - } - - @Test - void updateBookingUnauthorized() throws Exception { - when(service.update(anyLong(), any(), anyLong(), anyBoolean())).thenThrow(new UnauthorizedException("Unauthorized")); - - mockMvc.perform(patch("/bookings/14") - .param("approved", "true") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new BookingDto()))) - .andExpect(status().isForbidden()) - .andExpect(jsonPath("$.error").value("Нет доступа")); - } - - @Test - void getByIdBookingNotFound() throws Exception { - when(service.getById(anyLong(), anyLong())).thenThrow(new BookingNotFoundException("Booking not found")); - - mockMvc.perform(MockMvcRequestBuilders.get("/bookings/14") - .header(xShareUserId, 18L)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void getByIdUserNotFound() throws Exception { - when(service.getById(anyLong(), anyLong())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(MockMvcRequestBuilders.get("/bookings/14") - .header(xShareUserId, 18L)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void getByIdHappyFlow() throws Exception { - when(service.getById(anyLong(), anyLong())).thenReturn(buildBookingDto( - 43L, - 17L, - 38L, - getDateFromString("2023-04-15 15:00:00"), - getDateFromString("2023-04-17 12:00:00"), - BookingState.REJECTED)); - - mockMvc.perform(MockMvcRequestBuilders.get("/bookings/14") - .header(xShareUserId, 18L)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(43)) - .andExpect(jsonPath("$.start").value("2023-04-15T15:00:00")) - .andExpect(jsonPath("$.end").value("2023-04-17T12:00:00")) - .andExpect(jsonPath("$.status").value("REJECTED")) - .andExpect(jsonPath("$.bookerId").value(38)) - .andExpect(jsonPath("$.itemId").value(17)); - } - - - @Test - void getAllBookings() throws Exception { - List bookingDtos = List.of( - buildBookingDto(43L, 17L, 38L, - getDateFromString("2023-04-15 15:00:00"), - getDateFromString("2023-04-17 12:00:00"), - BookingState.REJECTED), - buildBookingDto(14L, 2L, 38L, - getDateFromString("2023-04-19 15:00:00"), - getDateFromString("2023-04-20 12:00:00"), - BookingState.APPROVED) - ); - when(service.getAll(anyLong(), anyString(), anyInt(), anyInt())).thenReturn(bookingDtos); - - mockMvc.perform(MockMvcRequestBuilders.get("/bookings") - .header(xShareUserId, 38L) - .param("state", "ALL")) - .andExpect(status().isOk()) - .andExpect(jsonPath("$[0].id").value(43)) - .andExpect(jsonPath("$[0].start").value("2023-04-15T15:00:00")) - .andExpect(jsonPath("$[0].end").value("2023-04-17T12:00:00")) - .andExpect(jsonPath("$[0].status").value("REJECTED")) - .andExpect(jsonPath("$[0].bookerId").value(38)) - .andExpect(jsonPath("$[0].itemId").value(17)) - .andExpect(jsonPath("$[1].id").value(14)) - .andExpect(jsonPath("$[1].start").value("2023-04-19T15:00:00")) - .andExpect(jsonPath("$[1].end").value("2023-04-20T12:00:00")) - .andExpect(jsonPath("$[1].status").value("APPROVED")) - .andExpect(jsonPath("$[1].bookerId").value(38)) - .andExpect(jsonPath("$[1].itemId").value(2)); - } - - @Test - void getAllBookingsUserNotFound() throws Exception { - when(service.getAll(anyLong(), anyString(), anyInt(), anyInt())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(MockMvcRequestBuilders.get("/bookings") - .header(xShareUserId, 18L)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void getItemsByAll() throws Exception { - List bookingDtos = List.of( - buildBookingDto(43L, 17L, 38L, - getDateFromString("2023-04-15 15:00:00"), - getDateFromString("2023-04-17 12:00:00"), - BookingState.REJECTED), - buildBookingDto(14L, 2L, 38L, - getDateFromString("2023-04-19 15:00:00"), - getDateFromString("2023-04-20 12:00:00"), - BookingState.APPROVED) - ); - when(service.getItemsForUser(anyLong(), anyString(), anyInt(), anyInt())).thenReturn(bookingDtos); - - mockMvc.perform(MockMvcRequestBuilders.get("/bookings/owner") - .header(xShareUserId, 38L) - .param("state", "ALL")) - .andExpect(status().isOk()) - .andExpect(jsonPath("$[0].id").value(43)) - .andExpect(jsonPath("$[0].start").value("2023-04-15T15:00:00")) - .andExpect(jsonPath("$[0].end").value("2023-04-17T12:00:00")) - .andExpect(jsonPath("$[0].status").value("REJECTED")) - .andExpect(jsonPath("$[0].bookerId").value(38)) - .andExpect(jsonPath("$[0].itemId").value(17)) - .andExpect(jsonPath("$[1].id").value(14)) - .andExpect(jsonPath("$[1].start").value("2023-04-19T15:00:00")) - .andExpect(jsonPath("$[1].end").value("2023-04-20T12:00:00")) - .andExpect(jsonPath("$[1].status").value("APPROVED")) - .andExpect(jsonPath("$[1].bookerId").value(38)) - .andExpect(jsonPath("$[1].itemId").value(2)); - } - - @Test - void getItemsByAllUserNotFound() throws Exception { - when(service.getItemsForUser(anyLong(), anyString(), anyInt(), anyInt())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(MockMvcRequestBuilders.get("/bookings/owner") - .header(xShareUserId, 18L)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void getItemsByAllUnauthorized() throws Exception { - when(service.getItemsForUser(anyLong(), anyString(), anyInt(), anyInt())).thenThrow(new UnauthorizedException("Unauthorized")); - - mockMvc.perform(MockMvcRequestBuilders.get("/bookings/owner") - .header(xShareUserId, 18L)) - .andExpect(status().isForbidden()) - .andExpect(jsonPath("$.error").value("Нет доступа")); - } - -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/booking/repository/BookingRepositoryTest.java b/src/test/java/ru/practicum/shareit/booking/repository/BookingRepositoryTest.java deleted file mode 100644 index 9245661..0000000 --- a/src/test/java/ru/practicum/shareit/booking/repository/BookingRepositoryTest.java +++ /dev/null @@ -1,174 +0,0 @@ -package ru.practicum.shareit.booking.repository; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.jdbc.Sql; -import ru.practicum.shareit.BaseTest; -import ru.practicum.shareit.booking.BookingState; -import ru.practicum.shareit.booking.model.Booking; - -import java.time.format.DateTimeFormatter; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; -import static ru.practicum.shareit.booking.BookingState.*; - -@DataJpaTest -@ActiveProfiles("test") -@Sql("/data.sql") -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -class BookingRepositoryTest extends BaseTest { - @Autowired - private BookingRepository bookingRepository; - - private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); - - @Test - void findAllByBookerId() { - List bookings = bookingRepository.findAllByBookerId(3); - assertEquals(2, bookings.size()); - assertArrayEquals(new long[]{4L, 7L}, new long[]{bookings.get(0).getId(), bookings.get(1).getId()}); - List emptyBookings = bookingRepository.findAllByBookerId(48); - assertTrue(emptyBookings.isEmpty()); - - } - - @Test - void findAllByBookerIdAndStatusInAndStartBeforeAndEndAfter() { - List bookings = bookingRepository.findAllByBookerIdAndStatusInAndStartBeforeAndEndAfter(1L, List.of(BookingState.WAITING), - getDateFromString("2023-04-03 15:35:40"), - getDateFromString("2023-04-03 16:24:40"), - PageRequest.of(0, 10)).getContent(); - assertEquals(1, bookings.size()); - assertEquals(8L, bookings.get(0).getId()); - } - - @Test - void findAllByBookerIdAndEndBeforeAndStatus() { - List bookings = bookingRepository.findAllByBookerIdAndEndBeforeAndStatus(1L, - getDateFromString("2023-04-03 16:44:40"), - APPROVED, - PageRequest.of(0, 10, Sort.by("start"))).getContent(); - assertEquals(1, bookings.size()); - assertEquals(1, bookings.get(0).getId()); - } - - @Test - void findAllByBookerIdAndStatus() { - List bookings = bookingRepository.findAllByBookerIdAndStatus(1L, - BookingState.WAITING, - PageRequest.of(0, 10, - Sort.by("id").descending())).getContent(); - assertEquals(2, bookings.size()); - assertEquals(8, bookings.get(0).getId()); - assertEquals(6, bookings.get(1).getId()); - } - - @Test - void findAllByBookerIdAndStatusInAndStartAfter() { - List bookings = bookingRepository.findAllByBookerIdAndStatusInAndStartAfter(3L, - List.of(APPROVED, BookingState.WAITING), - getDateFromString("2023-04-10 13:44:40"), - PageRequest.of(0, 10)).getContent(); - assertEquals(1, bookings.size()); - assertEquals(7, bookings.get(0).getId()); - } - - @Test - void findAllByItemOwnerIdAndStatusInAndStartBeforeAndEndAfter() { - List bookings = bookingRepository.findAllByItemOwnerIdAndStatusInAndStartBeforeAndEndAfter(4L, List.of(APPROVED, WAITING), - getDateFromString("2023-04-03 17:00:00"), - getDateFromString("2023-04-03 17:00:00"), - PageRequest.of(0, 10)).getContent(); - assertEquals(1, bookings.size()); - assertEquals(4, bookings.get(0).getId()); - } - - @Test - void findAllByItemOwnerIdAndEndBeforeAndStatus() { - List bookings = bookingRepository.findAllByItemOwnerIdAndEndBeforeAndStatus(4L, - getDateFromString("2023-04-03 16:30:00"), - APPROVED, PageRequest.of(0, 10)).getContent(); - assertEquals(1, bookings.size()); - assertEquals(1, bookings.get(0).getId()); - } - - @Test - void findAllByItemOwnerIdAndStatus() { - List bookings = bookingRepository.findAllByItemOwnerIdAndStatus(4L, - APPROVED, PageRequest.of(0, 10, Sort.by("start"))).getContent(); - assertEquals(2, bookings.size()); - assertEquals(1, bookings.get(0).getId()); - assertEquals(4, bookings.get(1).getId()); - } - - @Test - void findAllByItemOwnerIdAndStatusInAndStartAfter() { - List bookings = bookingRepository.findAllByItemOwnerIdAndStatusInAndStartAfter(4L, - List.of(APPROVED, REJECTED), - getDateFromString("2023-04-03 15:30:00"), PageRequest.of(0, 10, Sort.by("start"))).getContent(); - assertEquals(3, bookings.size()); - assertEquals(1, bookings.get(0).getId()); - assertEquals(5, bookings.get(1).getId()); - assertEquals(4, bookings.get(2).getId()); - } - - @Test - void findAllByItemIdInAndStatusAndStartBeforeOrderByStartDesc() { - List bookings = bookingRepository.findAllByItemIdInAndStatusAndStartBeforeOrderByStartDesc(List.of(2L, 1L), - APPROVED, - getDateFromString("2023-04-03 16:30:00")); - assertEquals(1, bookings.size()); - assertEquals(1, bookings.get(0).getId()); - } - - @Test - void findAllByItemIdInAndStatusAndStartAfterOrderByStart() { - List bookings = bookingRepository.findAllByItemIdInAndStatusAndStartAfterOrderByStart(List.of(2L, 1L), - APPROVED, - getDateFromString("2023-04-03 16:30:00")); - assertEquals(2, bookings.size()); - assertEquals(4, bookings.get(0).getId()); - assertEquals(7, bookings.get(1).getId()); - } - - @Test - void findAllByItemOwnerId() { - List bookings = bookingRepository.findAllByItemOwnerId(4L, PageRequest.of(0, 10, Sort.by("start"))).getContent(); - assertEquals(5, bookings.size()); - assertEquals(1, bookings.get(0).getId()); - assertEquals(5, bookings.get(1).getId()); - assertEquals(6, bookings.get(2).getId()); - assertEquals(4, bookings.get(3).getId()); - assertEquals(2, bookings.get(4).getId()); - } - - @Test - void findAllByItemIdInAndStatusAndEndBeforeOrStartBeforeAndEndAfter() { - List bookings = bookingRepository.findAllByItemIdInAndStatusAndEndBeforeOrStartBeforeAndEndAfter(List.of(2L, 1L, 4L), - APPROVED, - getDateFromString("2023-04-03 15:45:00"), - getDateFromString("2023-04-03 16:37:00"), - getDateFromString("2023-04-03 16:40:00")); - assertEquals(3, bookings.size()); - assertEquals(1, bookings.get(0).getId()); - assertEquals(4, bookings.get(1).getId()); - assertEquals(5, bookings.get(2).getId()); - } - - @Test - void findAllByItemIdInAndStatusAndStartAfter() { - List bookings = bookingRepository.findAllByItemIdInAndStatusAndStartAfter(List.of(2L, 1L, 4L), - APPROVED, - getDateFromString("2023-04-03 15:45:00")); - assertEquals(2, bookings.size()); - assertEquals(7, bookings.get(0).getId()); - assertEquals(4, bookings.get(1).getId()); - } - -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/booking/service/BookingServiceImplTest.java b/src/test/java/ru/practicum/shareit/booking/service/BookingServiceImplTest.java deleted file mode 100644 index 85c3b18..0000000 --- a/src/test/java/ru/practicum/shareit/booking/service/BookingServiceImplTest.java +++ /dev/null @@ -1,448 +0,0 @@ -package ru.practicum.shareit.booking.service; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.domain.PageImpl; -import ru.practicum.shareit.BaseTest; -import ru.practicum.shareit.booking.dto.BookingDto; -import ru.practicum.shareit.booking.model.Booking; -import ru.practicum.shareit.booking.repository.BookingRepository; -import ru.practicum.shareit.exception.*; -import ru.practicum.shareit.item.model.Item; -import ru.practicum.shareit.item.repository.ItemRepository; -import ru.practicum.shareit.user.model.User; -import ru.practicum.shareit.user.repository.UserRepository; - -import java.time.LocalDateTime; -import java.util.List; -import java.util.Optional; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; -import static ru.practicum.shareit.booking.BookingState.APPROVED; -import static ru.practicum.shareit.booking.BookingState.WAITING; - -@AutoConfigureMockMvc -@WebMvcTest({BookingServiceImpl.class, BookingRepository.class, UserRepository.class, ItemRepository.class}) -class BookingServiceImplTest extends BaseTest { - - @Autowired - private BookingServiceImpl service; - @MockBean - private UserRepository userRepository; - @MockBean - private ItemRepository itemRepository; - @MockBean - BookingRepository bookingRepository; - - private static final LocalDateTime NOW = LocalDateTime.now(); - - @Test - void create() throws Exception { - User owner = buildUser(4L, "mail@mail.com", "user"); - User booker = buildUser(7L, "mail@mail.com", "user"); - Item item = buildItem(2L, "item", "description", true, owner, null); - when(itemRepository.findById(anyLong())).thenReturn(Optional.of(item)); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(booker)); - when(bookingRepository.save(any())).thenReturn(buildBooking(5L, item, booker, NOW.plusDays(3), NOW.plusDays(4), WAITING)); - - BookingDto bookingDto = service.create(buildBookingDto(null, 2L, null, NOW.plusDays(3), NOW.plusDays(4), null), 7L); - assertEquals(5L, bookingDto.getId()); - assertEquals(NOW.plusDays(3), bookingDto.getStart()); - assertEquals(NOW.plusDays(4), bookingDto.getEnd()); - assertEquals(WAITING, bookingDto.getStatus()); - assertEquals(7L, bookingDto.getBookerId()); - assertEquals(2L, bookingDto.getItemId()); - } - - @ParameterizedTest - @MethodSource("prepareDataForCreateWithValidationError") - void createValidationError(BookingDto bookingDto, String expectedErrorMessage) { - assertThrows(ValidationException.class, () -> service.create(bookingDto, 5L), expectedErrorMessage); - } - - @Test - void createUserNotFoundException() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(UserNotFoundException.class, - () -> service.create(buildBookingDto(null, 5L, null, - NOW.plusDays(1), NOW.plusDays(2), null), 5L), "User not found"); - } - - @Test - void createItemNotFoundException() { - when(itemRepository.findById(anyLong())).thenReturn(Optional.empty()); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(4L, "mail@mail.com", "user"))); - assertThrows(ItemNotFoundException.class, - () -> service.create(buildBookingDto(null, - 5L, null, NOW.plusDays(1), - NOW.plusDays(2), null), 5L), "Item not found"); - } - - @Test - void createBookerEqualsOwnerException() { - User owner = buildUser(4L, "mail@mail.com", "user"); - when(itemRepository.findById(anyLong())).thenReturn(Optional.of(buildItem(2L, "item", "description", true, owner, null))); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(owner)); - assertThrows(ItemNotFoundException.class, - () -> service.create(buildBookingDto(null, - 2L, null, NOW.plusDays(1), - NOW.plusDays(2), null), 4L), "Item not found"); - } - - @Test - void createItemNotAvailableException() { - User owner = buildUser(4L, "mail@mail.com", "user"); - User booker = buildUser(7L, "mail@mail.com", "user"); - when(itemRepository.findById(anyLong())).thenReturn(Optional.of(buildItem(2L, "item", "description", false, owner, null))); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(booker)); - assertThrows(ItemNotAvailableException.class, () -> service.create(buildBookingDto(null, 2L, null, NOW.plusDays(1), NOW.plusDays(2), null), 7L), "Item not available"); - - } - - @Test - void updateUserNotFoundException() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(UserNotFoundException.class, - () -> service.update(1L, buildBookingDto(null, 5L, null, - NOW.plusDays(1), NOW.plusDays(2), null), 5L, null), "User not found"); - } - - @Test - void updateItemNotFoundException() { - User owner = buildUser(4L, "mail@mail.com", "user"); - Item item = buildItem(2L, "item", "description", true, owner, null); - when(bookingRepository.findById(anyLong())).thenReturn(Optional.of(buildBooking(5L, item, owner, NOW, NOW, WAITING))); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(owner)); - when(itemRepository.findById(anyLong())).thenReturn(Optional.empty()); - - assertThrows(ItemNotFoundException.class, - () -> service.update(1L, buildBookingDto(null, - 5L, null, NOW.plusDays(1), - NOW.plusDays(2), null), 5L, null), "Item not found"); - } - - @Test - void updateBookingNotFoundException() { - User owner = buildUser(4L, "mail@mail.com", "user"); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(owner)); - when(bookingRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(BookingNotFoundException.class, - () -> service.update(1L, buildBookingDto(null, - 2L, null, NOW.plusDays(1), - NOW.plusDays(2), null), 4L, null), "Booking not found"); - } - - @Test - void updateValidationException() { - User owner = buildUser(4L, "mail@mail.com", "user"); - Item item = buildItem(2L, "item", "description", true, owner, null); - Booking booking = buildBooking(5L, item, owner, NOW, NOW, WAITING); - when(bookingRepository.findById(anyLong())).thenReturn(Optional.of(booking)); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(owner)); - when(itemRepository.findById(anyLong())).thenReturn(Optional.of(item)); - assertThrows(ValidationException.class, - () -> service.update(1L, new BookingDto(), 3L, null), "Error"); - } - - @Test - void updateBookerEqualsOwner() { - User owner = buildUser(4L, "mail@mail.com", "user"); - User booker = buildUser(3L, "mail3@mail.com", "user"); - Item item = buildItem(2L, "item", "description", true, owner, null); - when(bookingRepository.findById(anyLong())).thenReturn(Optional.of(buildBooking(5L, item, owner, NOW, NOW, WAITING))); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(booker)); - when(itemRepository.findById(anyLong())).thenReturn(Optional.of(item)); - assertThrows(BookingNotFoundException.class, - () -> service.update(1L, new BookingDto(), 3L, true), "Booking Not Found"); - } - - @Test - void updateApproveForApproved() { - User owner = buildUser(4L, "mail@mail.com", "user"); - User booker = buildUser(3L, "mail3@mail.com", "user"); - Item item = buildItem(2L, "item", "description", true, owner, null); - when(bookingRepository.findById(anyLong())).thenReturn(Optional.of(buildBooking(5L, item, owner, NOW, NOW, APPROVED))); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(booker)); - when(itemRepository.findById(anyLong())).thenReturn(Optional.of(item)); - assertThrows(BookingNotFoundException.class, - () -> service.update(1L, new BookingDto(), 3L, true), "Booking Not Found"); - } - - @Test - void updateUnauthorized() { - User owner = buildUser(4L, "mail@mail.com", "user"); - User booker = buildUser(3L, "mail3@mail.com", "user"); - Item item = buildItem(2L, "item", "description", true, owner, null); - when(bookingRepository.findById(anyLong())).thenReturn(Optional.of(buildBooking(5L, item, owner, NOW, NOW, WAITING))); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(booker)); - when(itemRepository.findById(anyLong())).thenReturn(Optional.of(item)); - assertThrows(UnauthorizedException.class, - () -> service.update(1L, buildBookingDto(null, - 2L, null, NOW.plusDays(1), - NOW.plusDays(2), null), 3L, null), "Unauthorized"); - } - - @Test - void updateApprovedNull() throws Exception { - User owner = buildUser(4L, "mail@mail.com", "user"); - Item item = buildItem(2L, "item", "description", true, owner, null); - when(bookingRepository.findById(anyLong())).thenReturn(Optional.of(buildBooking(5L, item, owner, NOW, NOW, WAITING))); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(owner)); - when(itemRepository.findById(anyLong())).thenReturn(Optional.of(item)); - when(bookingRepository.save(any())).thenReturn(buildBooking(5L, item, owner, NOW.plusDays(3), NOW.plusDays(4), WAITING)); - - BookingDto bookingDto = service.update(1L, buildBookingDto(null, - 2L, null, NOW.plusDays(1), - NOW.plusDays(2), null), 3L, null); - assertEquals(5L, bookingDto.getId()); - assertEquals(NOW.plusDays(3), bookingDto.getStart()); - assertEquals(NOW.plusDays(4), bookingDto.getEnd()); - assertEquals(WAITING, bookingDto.getStatus()); - assertEquals(4L, bookingDto.getBookerId()); - assertEquals(2L, bookingDto.getItemId()); - - } - - @Test - void update() throws Exception { - User owner = buildUser(4L, "mail@mail.com", "user"); - Item item = buildItem(2L, "item", "description", true, owner, null); - when(bookingRepository.findById(anyLong())).thenReturn(Optional.of(buildBooking(5L, item, owner, NOW, NOW, WAITING))); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(owner)); - when(itemRepository.findById(anyLong())).thenReturn(Optional.of(item)); - when(bookingRepository.save(any())).thenReturn(buildBooking(5L, item, owner, NOW.plusDays(3), NOW.plusDays(4), WAITING)); - - BookingDto bookingDto = service.update(1L, buildBookingDto(null, - 2L, null, NOW.plusDays(1), - NOW.plusDays(2), null), 3L, true); - assertEquals(5L, bookingDto.getId()); - assertEquals(NOW.plusDays(3), bookingDto.getStart()); - assertEquals(NOW.plusDays(4), bookingDto.getEnd()); - assertEquals(WAITING, bookingDto.getStatus()); - assertEquals(4L, bookingDto.getBookerId()); - assertEquals(2L, bookingDto.getItemId()); - - } - - @Test - void getByIdUserNotFoundException() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(UserNotFoundException.class, - () -> service.getById(1L, 3L), "User not found"); - } - - @Test - void getByIdBookingNotFoundException() { - User owner = buildUser(4L, "mail@mail.com", "user"); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(owner)); - when(bookingRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(BookingNotFoundException.class, - () -> service.getById(1L, 3L), "Booking not found"); - } - - @Test - void getByIdOwnerNotEqualsBooker() { - User owner = buildUser(4L, "mail@mail.com", "user"); - User booker = buildUser(3L, "mail@mail.com", "user"); - Item item = buildItem(2L, "item", "description", true, owner, null); - Booking booking = buildBooking(5L, item, owner, NOW.plusDays(3), NOW.plusDays(4), WAITING); - when(bookingRepository.findById(anyLong())).thenReturn(Optional.of(booking)); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(booker)); - assertThrows(BookingNotFoundException.class, - () -> service.getById(1L, 3L), "Not found for booker"); - } - - @Test - void getById() throws Exception { - User owner = buildUser(4L, "mail@mail.com", "user"); - Item item = buildItem(2L, "item", "description", true, owner, null); - Booking booking = buildBooking(5L, item, owner, NOW.plusDays(3), NOW.plusDays(4), WAITING); - when(bookingRepository.findById(anyLong())).thenReturn(Optional.of(booking)); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(owner)); - when(bookingRepository.save(any())).thenReturn(buildBooking(5L, item, owner, NOW.plusDays(3), NOW.plusDays(4), WAITING)); - - BookingDto bookingDto = service.getById(3L, 7L); - assertEquals(5L, bookingDto.getId()); - assertEquals(NOW.plusDays(3), bookingDto.getStart()); - assertEquals(NOW.plusDays(4), bookingDto.getEnd()); - assertEquals(WAITING, bookingDto.getStatus()); - assertEquals(4L, bookingDto.getBookerId()); - assertEquals(2L, bookingDto.getItemId()); - } - - @Test - void getAllUserNotFoundException() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(UserNotFoundException.class, - () -> service.getAll(1L, "ALL", 0, 20), "User not found"); - } - - @ParameterizedTest - @ValueSource(strings = {"CURRENT", "PAST", "WAITING", "REJECTED", "FUTURE", "ALL"}) - void getAll(String status) throws Exception { - List bookings = List.of(buildBooking(3L, buildItem(2L, "item", "description", true, buildUser(4L, "mail@mail.com", "user"), null), buildUser(4L, "mail@mail.com", "user"), NOW.plusDays(3), NOW.plusDays(4), WAITING), - buildBooking(1L, buildItem(2L, "item", "description", true, buildUser(4L, "mail@mail.com", "user"), null), buildUser(4L, "mail@mail.com", "user"), NOW.plusDays(2), NOW.plusDays(4), WAITING), - buildBooking(2L, buildItem(2L, "item", "description", true, buildUser(4L, "mail@mail.com", "user"), null), buildUser(4L, "mail@mail.com", "user"), NOW.plusDays(1), NOW.plusDays(4), WAITING)); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(new User())); - when(bookingRepository.findAllByBookerIdAndStatusInAndStartBeforeAndEndAfter(anyLong(), anyList(), any(), any(), any())).thenReturn(new PageImpl<>(bookings)); - when(bookingRepository.findAllByBookerIdAndEndBeforeAndStatus(anyLong(), any(), any(), any())).thenReturn(new PageImpl<>(bookings)); - when(bookingRepository.findAllByBookerIdAndStatus(anyLong(), any(), any())).thenReturn(new PageImpl<>(bookings)); - when(bookingRepository.findAllByBookerIdAndStatusInAndStartAfter(anyLong(), anyList(), any(), any())).thenReturn(new PageImpl<>(bookings)); - when(bookingRepository.findAllByBookerId(anyLong(), any())).thenReturn(new PageImpl<>(bookings)); - - List bookingDtos = service.getAll(1L, status, 0, 20); - switch (status) { - case "CURRENT": - verify(bookingRepository, times(1)).findAllByBookerIdAndStatusInAndStartBeforeAndEndAfter(anyLong(), anyList(), any(), any(), any()); - verify(bookingRepository, times(0)).findAllByBookerIdAndEndBeforeAndStatus(anyLong(), any(), any(), any()); - verify(bookingRepository, times(0)).findAllByBookerIdAndStatus(anyLong(), any(), any()); - verify(bookingRepository, times(0)).findAllByBookerIdAndStatusInAndStartAfter(anyLong(), anyList(), any(), any()); - verify(bookingRepository, times(0)).findAllByBookerId(anyLong(), any()); - break; - case "PAST": - verify(bookingRepository, times(0)).findAllByBookerIdAndStatusInAndStartBeforeAndEndAfter(anyLong(), anyList(), any(), any(), any()); - verify(bookingRepository, times(1)).findAllByBookerIdAndEndBeforeAndStatus(anyLong(), any(), any(), any()); - verify(bookingRepository, times(0)).findAllByBookerIdAndStatus(anyLong(), any(), any()); - verify(bookingRepository, times(0)).findAllByBookerIdAndStatusInAndStartAfter(anyLong(), anyList(), any(), any()); - verify(bookingRepository, times(0)).findAllByBookerId(anyLong(), any()); - break; - case "WAITING": - case "REJECTED": - verify(bookingRepository, times(0)).findAllByBookerIdAndStatusInAndStartBeforeAndEndAfter(anyLong(), anyList(), any(), any(), any()); - verify(bookingRepository, times(0)).findAllByBookerIdAndEndBeforeAndStatus(anyLong(), any(), any(), any()); - verify(bookingRepository, times(1)).findAllByBookerIdAndStatus(anyLong(), any(), any()); - verify(bookingRepository, times(0)).findAllByBookerIdAndStatusInAndStartAfter(anyLong(), anyList(), any(), any()); - verify(bookingRepository, times(0)).findAllByBookerId(anyLong(), any()); - break; - case "FUTURE": - verify(bookingRepository, times(0)).findAllByBookerIdAndStatusInAndStartBeforeAndEndAfter(anyLong(), anyList(), any(), any(), any()); - verify(bookingRepository, times(0)).findAllByBookerIdAndEndBeforeAndStatus(anyLong(), any(), any(), any()); - verify(bookingRepository, times(0)).findAllByBookerIdAndStatus(anyLong(), any(), any()); - verify(bookingRepository, times(1)).findAllByBookerIdAndStatusInAndStartAfter(anyLong(), anyList(), any(), any()); - verify(bookingRepository, times(0)).findAllByBookerId(anyLong(), any()); - break; - case "ALL": - verify(bookingRepository, times(0)).findAllByBookerIdAndStatusInAndStartBeforeAndEndAfter(anyLong(), anyList(), any(), any(), any()); - verify(bookingRepository, times(0)).findAllByBookerIdAndEndBeforeAndStatus(anyLong(), any(), any(), any()); - verify(bookingRepository, times(0)).findAllByBookerIdAndStatus(anyLong(), any(), any()); - verify(bookingRepository, times(0)).findAllByBookerIdAndStatusInAndStartAfter(anyLong(), anyList(), any(), any()); - verify(bookingRepository, times(1)).findAllByBookerId(anyLong(), any()); - break; - } - assertEquals(3L, bookingDtos.get(0).getId()); - assertEquals(1L, bookingDtos.get(1).getId()); - assertEquals(2L, bookingDtos.get(2).getId()); - } - - @ParameterizedTest - @ValueSource(strings = {"CURRENT", "PAST", "WAITING", "REJECTED", "FUTURE", "ALL"}) - void getItemsForUser(String status) throws Exception { - List bookings = List.of(buildBooking(3L, buildItem(2L, "item", "description", true, buildUser(4L, "mail@mail.com", "user"), null), buildUser(4L, "mail@mail.com", "user"), NOW.plusDays(3), NOW.plusDays(4), WAITING), - buildBooking(1L, buildItem(2L, "item", "description", true, buildUser(4L, "mail@mail.com", "user"), null), buildUser(4L, "mail@mail.com", "user"), NOW.plusDays(2), NOW.plusDays(4), WAITING), - buildBooking(2L, buildItem(2L, "item", "description", true, buildUser(4L, "mail@mail.com", "user"), null), buildUser(4L, "mail@mail.com", "user"), NOW.plusDays(1), NOW.plusDays(4), WAITING)); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(new User())); - when(bookingRepository.findAllByItemOwnerIdAndStatusInAndStartBeforeAndEndAfter(anyLong(), anyList(), any(), any(), any())).thenReturn(new PageImpl<>(bookings)); - when(bookingRepository.findAllByItemOwnerIdAndEndBeforeAndStatus(anyLong(), any(), any(), any())).thenReturn(new PageImpl<>(bookings)); - when(bookingRepository.findAllByItemOwnerIdAndStatus(anyLong(), any(), any())).thenReturn(new PageImpl<>(bookings)); - when(bookingRepository.findAllByItemOwnerIdAndStatusInAndStartAfter(anyLong(), anyList(), any(), any())).thenReturn(new PageImpl<>(bookings)); - when(bookingRepository.findAllByItemOwnerId(anyLong(), any())).thenReturn(new PageImpl<>(bookings)); - when(itemRepository.findAll()).thenReturn(List.of(buildItem(2L, "item", "description", true, - buildUser(1L, "mail@mail.com", "user"), null))); - - List bookingDtos = service.getItemsForUser(1L, status, 0, 20); - switch (status) { - case "CURRENT": - verify(bookingRepository, times(1)).findAllByItemOwnerIdAndStatusInAndStartBeforeAndEndAfter(anyLong(), anyList(), any(), any(), any()); - verify(bookingRepository, times(0)).findAllByItemOwnerIdAndEndBeforeAndStatus(anyLong(), any(), any(), any()); - verify(bookingRepository, times(0)).findAllByItemOwnerIdAndStatus(anyLong(), any(), any()); - verify(bookingRepository, times(0)).findAllByItemOwnerIdAndStatusInAndStartAfter(anyLong(), anyList(), any(), any()); - verify(bookingRepository, times(0)).findAllByItemOwnerId(anyLong(), any()); - break; - case "PAST": - verify(bookingRepository, times(0)).findAllByItemOwnerIdAndStatusInAndStartBeforeAndEndAfter(anyLong(), anyList(), any(), any(), any()); - verify(bookingRepository, times(1)).findAllByItemOwnerIdAndEndBeforeAndStatus(anyLong(), any(), any(), any()); - verify(bookingRepository, times(0)).findAllByItemOwnerIdAndStatus(anyLong(), any(), any()); - verify(bookingRepository, times(0)).findAllByItemOwnerIdAndStatusInAndStartAfter(anyLong(), anyList(), any(), any()); - verify(bookingRepository, times(0)).findAllByItemOwnerId(anyLong(), any()); - break; - case "WAITING": - case "REJECTED": - verify(bookingRepository, times(0)).findAllByItemOwnerIdAndStatusInAndStartBeforeAndEndAfter(anyLong(), anyList(), any(), any(), any()); - verify(bookingRepository, times(0)).findAllByItemOwnerIdAndEndBeforeAndStatus(anyLong(), any(), any(), any()); - verify(bookingRepository, times(1)).findAllByItemOwnerIdAndStatus(anyLong(), any(), any()); - verify(bookingRepository, times(0)).findAllByItemOwnerIdAndStatusInAndStartAfter(anyLong(), anyList(), any(), any()); - verify(bookingRepository, times(0)).findAllByItemOwnerId(anyLong(), any()); - break; - case "FUTURE": - verify(bookingRepository, times(0)).findAllByItemOwnerIdAndStatusInAndStartBeforeAndEndAfter(anyLong(), anyList(), any(), any(), any()); - verify(bookingRepository, times(0)).findAllByItemOwnerIdAndEndBeforeAndStatus(anyLong(), any(), any(), any()); - verify(bookingRepository, times(0)).findAllByItemOwnerIdAndStatus(anyLong(), any(), any()); - verify(bookingRepository, times(1)).findAllByItemOwnerIdAndStatusInAndStartAfter(anyLong(), anyList(), any(), any()); - verify(bookingRepository, times(0)).findAllByItemOwnerId(anyLong(), any()); - break; - case "ALL": - verify(bookingRepository, times(0)).findAllByItemOwnerIdAndStatusInAndStartBeforeAndEndAfter(anyLong(), anyList(), any(), any(), any()); - verify(bookingRepository, times(0)).findAllByItemOwnerIdAndEndBeforeAndStatus(anyLong(), any(), any(), any()); - verify(bookingRepository, times(0)).findAllByItemOwnerIdAndStatus(anyLong(), any(), any()); - verify(bookingRepository, times(0)).findAllByItemOwnerIdAndStatusInAndStartAfter(anyLong(), anyList(), any(), any()); - verify(bookingRepository, times(1)).findAllByItemOwnerId(anyLong(), any()); - break; - } - assertEquals(3L, bookingDtos.get(0).getId()); - assertEquals(1L, bookingDtos.get(1).getId()); - assertEquals(2L, bookingDtos.get(2).getId()); - } - - @Test - void getAllUnsupportedStatus() { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(new User())); - assertThrows(ValidationException.class, () -> service.getAll(8L, "DONE", 0, 20), "Unknown state: UNSUPPORTED_STATUS"); - } - - @Test - void getItemsForUserUnauthorizedException() { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(new User())); - when(itemRepository.findAll()).thenReturn(List.of(buildItem(2L, "item", "description", true, - buildUser(1L, "mail@mail.com", "user"), null))); - assertThrows(UnauthorizedException.class, () -> service.getItemsForUser(8L, "ALL", 0, 20)); - } - - @Test - void getItemsForUserUserNotFoundException() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(UserNotFoundException.class, - () -> service.getItemsForUser(8L, "ALL", 0, 20), "User not found"); - } - - @Test - void getItemsForUserUnsupportedStatus() { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(new User())); - when(itemRepository.findAll()).thenReturn(List.of(buildItem(2L, "item", "description", true, - buildUser(1L, "mail@mail.com", "user"), null))); - assertThrows(ValidationException.class, () -> service.getItemsForUser(1L, "DONE", 0, 20), "Unknown state: UNSUPPORTED_STATUS"); - } - - - private static Stream prepareDataForCreateWithValidationError() { - return Stream.of( - Arguments.of(buildBookingDto(null, 5L, 3L, null, NOW.plusDays(2), null), "Start or End is null"), - Arguments.of(buildBookingDto(null, 5L, 3L, NOW.plusDays(5), null, null), "Start or End is null"), - Arguments.of(buildBookingDto(null, 5L, 3L, null, null, null), "Start or End is null"), - Arguments.of(buildBookingDto(null, 5L, 3L, NOW.plusDays(2), NOW.plusDays(2), null), "Start or End is wrong"), - Arguments.of(buildBookingDto(null, 5L, 3L, NOW.minusDays(4), NOW.plusDays(3), null), "Start or End is wrong"), - Arguments.of(buildBookingDto(null, 5L, 3L, NOW.plusDays(4), NOW.minusDays(3), null), "Start or End is wrong"), - Arguments.of(buildBookingDto(null, 5L, 3L, NOW.plusDays(10), NOW.plusDays(4), null), "Start or End is wrong") - ); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/item/controller/ItemControllerTest.java b/src/test/java/ru/practicum/shareit/item/controller/ItemControllerTest.java deleted file mode 100644 index 5f50836..0000000 --- a/src/test/java/ru/practicum/shareit/item/controller/ItemControllerTest.java +++ /dev/null @@ -1,342 +0,0 @@ -package ru.practicum.shareit.item.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.hamcrest.core.IsNull; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import ru.practicum.shareit.BaseTest; -import ru.practicum.shareit.booking.BookingState; -import ru.practicum.shareit.exception.ItemNotFoundException; -import ru.practicum.shareit.exception.UnauthorizedException; -import ru.practicum.shareit.exception.UserNotFoundException; -import ru.practicum.shareit.exception.ValidationException; -import ru.practicum.shareit.item.dto.CommentDto; -import ru.practicum.shareit.item.dto.ItemDto; -import ru.practicum.shareit.item.service.ItemServiceImpl; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; - -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@AutoConfigureMockMvc -@WebMvcTest({ItemController.class}) -class ItemControllerTest extends BaseTest { - @Autowired - private MockMvc mockMvc; - @Autowired - private ObjectMapper mapper; - @MockBean - private ItemServiceImpl service; - - - @Test - void create() throws Exception { - when(service.create(any(), anyLong())).thenReturn(buildItemDto(12L, "Бензопила", "Бензопила \"Дружба\"", true)); - - mockMvc.perform(post("/items") - .header(xShareUserId, 11) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new ItemDto()))) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(12)) - .andExpect(jsonPath("$.name").value("Бензопила")) - .andExpect(jsonPath("$.description").value("Бензопила \"Дружба\"")) - .andExpect(jsonPath("$.available").value(true)); - } - - @Test - void createUserNotFound() throws Exception { - when(service.create(any(), anyLong())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(post("/items") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new ItemDto()))) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void update() throws Exception { - when(service.update(anyLong(), any(), anyLong())).thenReturn(buildItemDto(12L, "Бензопила", "Бензопила \"Дружба\"", true)); - - mockMvc.perform(patch("/items/12") - .header(xShareUserId, 11) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new ItemDto()))) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(12)) - .andExpect(jsonPath("$.name").value("Бензопила")) - .andExpect(jsonPath("$.description").value("Бензопила \"Дружба\"")) - .andExpect(jsonPath("$.available").value(true)); - } - - @Test - void updateUserNotFound() throws Exception { - when(service.update(anyLong(), any(), anyLong())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(patch("/items/15") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new ItemDto()))) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void updateItemNotFound() throws Exception { - when(service.update(anyLong(), any(), anyLong())).thenThrow(new ItemNotFoundException("Item not found")); - - mockMvc.perform(patch("/items/15") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new ItemDto()))) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void updateUnauthorized() throws Exception { - when(service.update(anyLong(), any(), anyLong())).thenThrow(new UnauthorizedException("User can not update this item!")); - - mockMvc.perform(patch("/items/15") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new ItemDto()))) - .andExpect(status().isForbidden()) - .andExpect(jsonPath("$.error").value("Нет доступа")); - } - - @Test - void delete() throws Exception { - when(service.delete(anyLong(), anyLong())).thenReturn(buildItemDto(12L, "Бензопила", "Бензопила \"Дружба\"", true)); - - mockMvc.perform(MockMvcRequestBuilders.delete("/items/12") - .header(xShareUserId, 11) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(12)) - .andExpect(jsonPath("$.name").value("Бензопила")) - .andExpect(jsonPath("$.description").value("Бензопила \"Дружба\"")) - .andExpect(jsonPath("$.available").value(true)); - } - - @Test - void deleteUserNotFound() throws Exception { - when(service.delete(anyLong(), anyLong())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(MockMvcRequestBuilders.delete("/items/15") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void deleteItemNotFound() throws Exception { - when(service.delete(anyLong(), anyLong())).thenThrow(new ItemNotFoundException("Item not found")); - - mockMvc.perform(MockMvcRequestBuilders.delete("/items/15") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void deleteUnauthorized() throws Exception { - when(service.delete(anyLong(), anyLong())).thenThrow(new UnauthorizedException("User can not delete this item!")); - - mockMvc.perform(MockMvcRequestBuilders.delete("/items/15") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isForbidden()) - .andExpect(jsonPath("$.error").value("Нет доступа")); - } - - @Test - void getById() throws Exception { - when(service.getById(anyLong(), anyLong())).thenReturn(buildItemDto(12L, "Бензопила", "Бензопила \"Дружба\"", true)); - - mockMvc.perform(MockMvcRequestBuilders.get("/items/12") - .header(xShareUserId, 11) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(12)) - .andExpect(jsonPath("$.name").value("Бензопила")) - .andExpect(jsonPath("$.description").value("Бензопила \"Дружба\"")) - .andExpect(jsonPath("$.lastBooking").value(IsNull.nullValue())) - .andExpect(jsonPath("$.nextBooking").value(IsNull.nullValue())) - .andExpect(jsonPath("$.available").value(true)); - } - - @Test - void getByIdItemNotFound() throws Exception { - when(service.getById(anyLong(), anyLong())).thenThrow(new ItemNotFoundException("Item not found")); - - mockMvc.perform(MockMvcRequestBuilders.get("/items/15") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void getByIdUserNotFound() throws Exception { - when(service.getById(anyLong(), anyLong())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(MockMvcRequestBuilders.get("/items/15") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void getAll() throws Exception { - ItemDto item1 = buildItemDto(11L, "Бензопила", "Бензопила \"Дружба\"", true); - item1.setNextBooking(buildBookingDto(2L, 11L, 3L, getDateFromString("2023-04-06 12:00:00"), getDateFromString("2023-04-08 11:00:00"), BookingState.APPROVED)); - item1.setLastBooking(buildBookingDto(9L, 11L, 7L, getDateFromString("2023-04-03 12:00:00"), getDateFromString("2023-04-04 11:00:00"), BookingState.APPROVED)); - - ItemDto item2 = buildItemDto(17L, "Молоток", "Молоток новый", true); - item2.setNextBooking(buildBookingDto(5L, 11L, 36L, getDateFromString("2023-04-11 12:00:00"), getDateFromString("2023-04-12 11:00:00"), BookingState.APPROVED)); - - when(service.getAll(anyLong(), anyInt(), anyInt())).thenReturn(List.of(item1, item2)); - - mockMvc.perform(MockMvcRequestBuilders.get("/items") - .param("from", "0") - .param("size", "15") - .header(xShareUserId, 11) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$[0].id").value(11)) - .andExpect(jsonPath("$[0].name").value("Бензопила")) - .andExpect(jsonPath("$[0].description").value("Бензопила \"Дружба\"")) - .andExpect(jsonPath("$[0].lastBooking.id").value(9)) - .andExpect(jsonPath("$[0].lastBooking.itemId").value(11)) - .andExpect(jsonPath("$[0].lastBooking.bookerId").value(7)) - .andExpect(jsonPath("$[0].lastBooking.start").value("2023-04-03T12:00:00")) - .andExpect(jsonPath("$[0].lastBooking.end").value("2023-04-04T11:00:00")) - .andExpect(jsonPath("$[0].nextBooking.id").value(2)) - .andExpect(jsonPath("$[0].nextBooking.itemId").value(11)) - .andExpect(jsonPath("$[0].nextBooking.bookerId").value(3)) - .andExpect(jsonPath("$[0].nextBooking.start").value("2023-04-06T12:00:00")) - .andExpect(jsonPath("$[0].nextBooking.end").value("2023-04-08T11:00:00")) - .andExpect(jsonPath("$[0].available").value(true)) - .andExpect(jsonPath("$[1].id").value(17)) - .andExpect(jsonPath("$[1].name").value("Молоток")) - .andExpect(jsonPath("$[1].description").value("Молоток новый")) - .andExpect(jsonPath("$[1].nextBooking.id").value(5)) - .andExpect(jsonPath("$[1].nextBooking.itemId").value(11)) - .andExpect(jsonPath("$[1].nextBooking.bookerId").value(36)) - .andExpect(jsonPath("$[1].nextBooking.start").value("2023-04-11T12:00:00")) - .andExpect(jsonPath("$[1].nextBooking.end").value("2023-04-12T11:00:00")) - .andExpect(jsonPath("$[1].lastBooking").value(IsNull.nullValue())) - .andExpect(jsonPath("$[1].available").value(true)); - } - - @Test - void search() throws Exception { - ItemDto item1 = buildItemDto(11L, "Бензопила", "Бензопила \"Дружба\" новая, в упаковке", true); - ItemDto item2 = buildItemDto(17L, "Молоток", "Молоток в упаковке", true); - - when(service.search(anyString(), anyInt(), anyInt())).thenReturn(List.of(item1, item2)); - - mockMvc.perform(MockMvcRequestBuilders.get("/items/search") - .param("text", "в упаковке") - .param("from", "0") - .param("size", "15") - .header(xShareUserId, 11) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$[0].id").value(11)) - .andExpect(jsonPath("$[0].name").value("Бензопила")) - .andExpect(jsonPath("$[0].description").value("Бензопила \"Дружба\" новая, в упаковке")) - .andExpect(jsonPath("$[0].nextBooking").value(IsNull.nullValue())) - .andExpect(jsonPath("$[0].nextBooking").value(IsNull.nullValue())) - .andExpect(jsonPath("$[0].available").value(true)) - .andExpect(jsonPath("$[1].id").value(17)) - .andExpect(jsonPath("$[1].name").value("Молоток")) - .andExpect(jsonPath("$[1].description").value("Молоток в упаковке")) - .andExpect(jsonPath("$[1].nextBooking").value(IsNull.nullValue())) - .andExpect(jsonPath("$[1].lastBooking").value(IsNull.nullValue())) - .andExpect(jsonPath("$[1].available").value(true)); - } - - @Test - void searchNoResults() throws Exception { - when(service.search(anyString(), anyInt(), anyInt())).thenReturn(new ArrayList<>()); - - mockMvc.perform(MockMvcRequestBuilders.get("/items/search") - .param("text", "Дрель") - .param("from", "0") - .param("size", "15") - .header(xShareUserId, 11) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$").isEmpty()); - } - - @Test - void addComment() throws Exception { - when(service.addComment(anyLong(), anyLong(), any())).thenReturn(buildCommentDto(1L, "Бензопила отличная", LocalDateTime.now(), "user123")); - - mockMvc.perform(post("/items/12/comment") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new CommentDto()))) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(1)) - .andExpect(jsonPath("$.text").value("Бензопила отличная")) - .andExpect(jsonPath("$.authorName").value("user123")); - } - - @Test - void addCommentUserNotFound() throws Exception { - when(service.addComment(anyLong(), anyLong(), any())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(post("/items/12/comment") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new CommentDto()))) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void addCommentItemNotFound() throws Exception { - when(service.addComment(anyLong(), anyLong(), any())).thenThrow(new ItemNotFoundException("Item not found")); - - mockMvc.perform(post("/items/12/comment") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new CommentDto()))) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void addCommentValidationError() throws Exception { - when(service.addComment(anyLong(), anyLong(), any())).thenThrow(new ValidationException("Empty comment")); - - mockMvc.perform(post("/items/1/comment") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new CommentDto()))) - .andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.error").value("Empty comment")); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/item/repository/CommentRepositoryTest.java b/src/test/java/ru/practicum/shareit/item/repository/CommentRepositoryTest.java deleted file mode 100644 index ff6fd8d..0000000 --- a/src/test/java/ru/practicum/shareit/item/repository/CommentRepositoryTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package ru.practicum.shareit.item.repository; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.jdbc.Sql; -import ru.practicum.shareit.BaseTest; -import ru.practicum.shareit.item.model.Comment; - -import java.util.List; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -@DataJpaTest -@ActiveProfiles("test") -@Sql("/data.sql") -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -class CommentRepositoryTest extends BaseTest { - - @Autowired - private CommentRepository commentRepository; - - @Test - void save() { - Comment comment = new Comment(); - comment.setAuthor(buildUser(2L, "email", "name")); - comment.setText("new comment"); - Comment savedItemRequest = commentRepository.save(comment); - assertEquals(4, savedItemRequest.getId()); - } - - @Test - void findAll() { - List comments = commentRepository.findAll(); - assertEquals(3, comments.size()); - } - - @Test - void findById() { - Optional itemRequest = commentRepository.findById(2L); - assertTrue(itemRequest.isPresent()); - assertEquals("Add comment from user2", itemRequest.get().getText()); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/item/repository/ItemRepositoryTest.java b/src/test/java/ru/practicum/shareit/item/repository/ItemRepositoryTest.java deleted file mode 100644 index d3a21f0..0000000 --- a/src/test/java/ru/practicum/shareit/item/repository/ItemRepositoryTest.java +++ /dev/null @@ -1,60 +0,0 @@ -package ru.practicum.shareit.item.repository; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.data.domain.PageRequest; -import org.springframework.data.domain.Sort; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.jdbc.Sql; -import ru.practicum.shareit.item.model.Item; - -import java.util.List; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -@DataJpaTest -@ActiveProfiles("test") -@Sql("/data.sql") -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -class ItemRepositoryTest { - - @Autowired - private ItemRepository itemRepository; - - @Test - void findAllByOwnerId() { - List items = itemRepository.findAllByOwnerId(4L, - PageRequest.of(0, 10, Sort.by("id"))).getContent(); - assertEquals(3, items.size()); - assertEquals(2, items.get(0).getId()); - assertEquals(3, items.get(1).getId()); - assertEquals(5, items.get(2).getId()); - } - - @Test - void findAllByNameContainingIgnoreCaseOrDescriptionContainingIgnoreCaseAndAvailableTrueOrderById() { - List items = itemRepository.findAllByNameContainingIgnoreCaseOrDescriptionContainingIgnoreCaseAndAvailableTrue("АккУМулятОРНая", - "АккУМулятОРНая", - PageRequest.of(0, 10, Sort.by("id"))).getContent(); - assertEquals(2, items.size()); - assertEquals(1, items.get(0).getId()); - assertEquals(2, items.get(1).getId()); - } - - @Test - void findAllByRequestId() { - List items = itemRepository.findAllByRequestId(2L); - assertEquals(1, items.size()); - assertEquals(3, items.get(0).getId()); - } - - @Test - void findAllByRequestIdIn() { - List items = itemRepository.findAllByRequestIdIn(List.of(2L, 1L)); - assertEquals(2, items.size()); - assertEquals(3, items.get(0).getId()); - assertEquals(5, items.get(1).getId()); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/item/service/ItemServiceImplTest.java b/src/test/java/ru/practicum/shareit/item/service/ItemServiceImplTest.java deleted file mode 100644 index 0b4423f..0000000 --- a/src/test/java/ru/practicum/shareit/item/service/ItemServiceImplTest.java +++ /dev/null @@ -1,379 +0,0 @@ -package ru.practicum.shareit.item.service; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.NullSource; -import org.junit.jupiter.params.provider.ValueSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.domain.PageImpl; -import ru.practicum.shareit.BaseTest; -import ru.practicum.shareit.booking.BookingState; -import ru.practicum.shareit.booking.repository.BookingRepository; -import ru.practicum.shareit.exception.ItemNotFoundException; -import ru.practicum.shareit.exception.UnauthorizedException; -import ru.practicum.shareit.exception.UserNotFoundException; -import ru.practicum.shareit.exception.ValidationException; -import ru.practicum.shareit.item.dto.CommentDto; -import ru.practicum.shareit.item.dto.ItemDto; -import ru.practicum.shareit.item.model.Item; -import ru.practicum.shareit.item.repository.CommentRepository; -import ru.practicum.shareit.item.repository.ItemRepository; -import ru.practicum.shareit.request.model.ItemRequest; -import ru.practicum.shareit.request.repository.ItemRequestRepository; -import ru.practicum.shareit.user.model.User; -import ru.practicum.shareit.user.repository.UserRepository; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.when; - -@AutoConfigureMockMvc -@WebMvcTest({ItemServiceImpl.class, ItemRepository.class, BookingRepository.class, UserRepository.class, CommentRepository.class, ItemRequestRepository.class}) -class ItemServiceImplTest extends BaseTest { - - @Autowired - private ItemServiceImpl service; - @MockBean - ItemRepository repository; - @MockBean - UserRepository userRepository; - @MockBean - private BookingRepository bookingRepository; - @MockBean - private CommentRepository commentRepository; - @MockBean - private ItemRequestRepository itemRequestRepository; - - @ParameterizedTest - @MethodSource("prepareDataForCreate") - void create(ItemDto itemDto) { - assertThrows(ValidationException.class, () -> service.create(itemDto, 5L), "Not valid"); - } - - @Test - void createUserNotFound() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(UserNotFoundException.class, () -> service.create(buildItemDto(1L, "name", "abcde", true), 2L)); - } - - @Test - void create() throws Exception { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(2L, "email@mail.com", "name"))); - User user = buildUser(3L, "email@mail.com", "name"); - ItemRequest itemRequest = buildItemRequest(4L, user, "bavscd"); - when(itemRequestRepository.findById(anyLong())).thenReturn( - Optional.of(itemRequest)); - when(repository.save(any())).thenReturn(buildItem(2L, "name", "asdfg", true, user, itemRequest)); - ItemDto it = service.create(buildItemDto(2L, "name", "asdfgrt", true), 3L); - assertEquals(2L, it.getId()); - } - - @Test - void updateUserNotFound() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(UserNotFoundException.class, () -> service.update(3L, buildItemDto(1L, "name", "abcde", true), 2L)); - } - - @Test - void updateItemNotFound() { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(2L, "email@mail.com", "name"))); - when(repository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(ItemNotFoundException.class, () -> service.update(3L, buildItemDto(1L, "name", "abcde", true), 2L)); - } - - @Test - void updateUnauthorized() { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(2L, "email@mail.com", "name"))); - when(repository.findById(anyLong())).thenReturn( - Optional.of(buildItem(2L, "item", "description", true, - buildUser(2L, "email@mail.com", "name"), null))); - assertThrows(UnauthorizedException.class, () -> service.update(3L, buildItemDto(1L, "name", "abcde", true), 6L)); - } - - @Test - void update() throws Exception { - User user = buildUser(2L, "email@mail.com", "name"); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(user)); - when(repository.findById(anyLong())).thenReturn( - Optional.of(buildItem(2L, "item", "description", true, - buildUser(2L, "email@mail.com", "name"), null))); - when(repository.save(any())).thenReturn(buildItem(2L, "name", "asdfg", true, user, null)); - ItemDto updated = service.update(3L, buildItemDto(1L, "name", "abcde", true), 2L); - assertEquals(2L, updated.getId()); - } - - @Test - void delete() throws Exception { - User user = buildUser(2L, "email@mail.com", "name"); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(user)); - when(repository.findById(anyLong())).thenReturn( - Optional.of(buildItem(2L, "item", "description", true, - buildUser(2L, "email@mail.com", "name"), null))); - doNothing().when(repository).deleteById(anyLong()); - ItemDto deleted = service.delete(3L, 2L); - assertEquals(2L, deleted.getId()); - } - - @Test - void deleteUnauthorized() { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(2L, "email@mail.com", "name"))); - when(repository.findById(anyLong())).thenReturn( - Optional.of(buildItem(2L, "item", "description", true, - buildUser(2L, "email@mail.com", "name"), null))); - assertThrows(UnauthorizedException.class, () -> service.delete(3L, 6L)); - } - - @Test - void deleteUserNotFound() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(UserNotFoundException.class, () -> service.delete(3L, 2L)); - } - - @Test - void deleteItemNotfound() { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(2L, "email@mail.com", "name"))); - when(repository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(ItemNotFoundException.class, () -> service.delete(3L, 2L)); - } - - @Test - void getByIdUserNotFound() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - when(repository.findById(anyLong())).thenReturn( - Optional.of(buildItem(2L, "item", "description", true, - buildUser(2L, "email@mail.com", "name"), null))); - assertThrows(UserNotFoundException.class, () -> service.getById(3L, 2L)); - } - - @Test - void getByIdItemNotFound() { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(2L, "email@mail.com", "name"))); - when(repository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(ItemNotFoundException.class, () -> service.getById(3L, 2L)); - } - - @Test - void getByIdByOwner() throws Exception { - User user = buildUser(2L, "email@mail.com", "name"); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(user)); - when(repository.findById(anyLong())).thenReturn( - Optional.of(buildItem(2L, "item", "description", true, - user, null))); - ItemDto itemDto = service.getById(3L, 2L); - assertEquals(2L, itemDto.getId()); - assertNull(itemDto.getNextBooking()); - assertNull(itemDto.getLastBooking()); - } - - @Test - void getById() throws Exception { - User user = buildUser(2L, "email@mail.com", "name"); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(user)); - Item item = buildItem(2L, "item", "description", true, user, null); - when(repository.findById(anyLong())).thenReturn( - Optional.of(item)); - when(bookingRepository.findAllByItemIdInAndStatusAndStartBeforeOrderByStartDesc(anyList(), any(), any())).thenReturn(List.of( - buildBooking(2L, buildItem(1L, "abc", "def", true, user, null), - user, LocalDateTime.now(), LocalDateTime.now(), BookingState.APPROVED))); - when(bookingRepository.findAllByItemIdInAndStatusAndStartAfterOrderByStart(anyList(), any(), any())).thenReturn(List.of( - buildBooking(8L, buildItem(7L, "abc", "def", true, user, null), - user, LocalDateTime.now(), LocalDateTime.now(), BookingState.APPROVED) - )); - ItemDto itemDto = service.getById(3L, 2L); - assertNotNull(itemDto.getNextBooking()); - assertNotNull(itemDto.getLastBooking()); - assertEquals(8L, itemDto.getNextBooking().getId()); - assertEquals(2L, itemDto.getLastBooking().getId()); - } - - @Test - void getByIdEmptyLastNext() throws Exception { - User user = buildUser(2L, "email@mail.com", "name"); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(user)); - Item item = buildItem(2L, "item", "description", true, user, null); - when(repository.findById(anyLong())).thenReturn( - Optional.of(item)); - when(bookingRepository.findAllByItemIdInAndStatusAndStartBeforeOrderByStartDesc(anyList(), any(), any())).thenReturn(new ArrayList<>()); - when(bookingRepository.findAllByItemIdInAndStatusAndStartAfterOrderByStart(anyList(), any(), any())).thenReturn(new ArrayList<>()); - ItemDto itemDto = service.getById(3L, 2L); - assertNull(itemDto.getNextBooking()); - assertNull(itemDto.getLastBooking()); - } - - @Test - void getAll() { - User user1 = buildUser(2L, "email", "name"); - User user2 = buildUser(3L, "email", "name"); - User user3 = buildUser(4L, "email", "name"); - Item e1 = buildItem(2L, "item", "description", true, user1, null); - Item e2 = buildItem(3L, "item", "description", true, user1, null); - Item e3 = buildItem(4L, "item", "description", true, user1, null); - Item e4 = buildItem(5L, "item", "description", true, user1, null); - Item e5 = buildItem(6L, "item", "description", true, user1, null); - when(repository.findAllByOwnerId(anyLong(), any())).thenReturn(new PageImpl<>(List.of(e1, e2, e3, e4, e5))); - when(bookingRepository.findAllByItemIdInAndStatusAndEndBeforeOrStartBeforeAndEndAfter(anyList(), any(), any(), any(), any())).thenReturn(List.of( - buildBooking(4L, e1, user2, getDateFromString("2023-04-02 12:00:00"), getDateFromString("2023-04-03 12:00:00"), BookingState.APPROVED), - buildBooking(6L, e2, user2, getDateFromString("2023-04-03 12:00:00"), getDateFromString("2023-04-04 12:00:00"), BookingState.APPROVED), - buildBooking(7L, e3, user3, getDateFromString("2023-04-05 12:00:00"), getDateFromString("2023-04-12 12:00:00"), BookingState.APPROVED), - buildBooking(8L, e4, user3, getDateFromString("2023-04-04 12:00:00"), getDateFromString("2023-04-25 12:00:00"), BookingState.APPROVED), - buildBooking(9L, e5, user3, getDateFromString("2023-04-03 12:00:00"), getDateFromString("2023-04-08 12:00:00"), BookingState.APPROVED) - )); - when(bookingRepository.findAllByItemIdInAndStatusAndStartAfter(anyList(), any(), any())).thenReturn(List.of( - buildBooking(14L, e1, user2, getDateFromString("2023-04-08 12:00:00"), getDateFromString("2023-04-13 12:00:00"), BookingState.APPROVED), - buildBooking(16L, e2, user2, getDateFromString("2023-04-09 12:00:00"), getDateFromString("2023-04-14 12:00:00"), BookingState.APPROVED), - buildBooking(17L, e3, user3, getDateFromString("2023-04-10 12:00:00"), getDateFromString("2023-04-12 12:00:00"), BookingState.APPROVED), - buildBooking(18L, e4, user3, getDateFromString("2023-04-14 12:00:00"), getDateFromString("2023-04-25 12:00:00"), BookingState.APPROVED), - buildBooking(19L, e5, user3, getDateFromString("2023-04-23 12:00:00"), getDateFromString("2023-04-24 12:00:00"), BookingState.APPROVED) - )); - - List items = service.getAll(2L, 0, 10); - assertEquals(4L, items.get(0).getLastBooking().getId()); - assertEquals(14L, items.get(0).getNextBooking().getId()); - - assertEquals(6L, items.get(1).getLastBooking().getId()); - assertEquals(16L, items.get(1).getNextBooking().getId()); - - assertEquals(7L, items.get(2).getLastBooking().getId()); - assertEquals(17L, items.get(2).getNextBooking().getId()); - - assertEquals(8L, items.get(3).getLastBooking().getId()); - assertEquals(18L, items.get(3).getNextBooking().getId()); - - assertEquals(9L, items.get(4).getLastBooking().getId()); - assertEquals(19L, items.get(4).getNextBooking().getId()); - } - - @Test - void getAllEmptyLastAndNext() { - LocalDateTime now = LocalDateTime.now(); - User user1 = buildUser(2L, "email", "name"); - User user2 = buildUser(3L, "email", "name"); - Item e1 = buildItem(2L, "item", "description", true, user1, null); - Item e2 = buildItem(3L, "item", "description", true, user1, null); - - when(repository.findAllByOwnerId(anyLong(), any())).thenReturn(new PageImpl<>(List.of(e1, e2))); - when(bookingRepository.findAllByItemIdInAndStatusAndEndBeforeOrStartBeforeAndEndAfter(anyList(), any(), any(), any(), any())).thenReturn(List.of( - buildBooking(6L, e2, user2, now.minusDays(3), now.minusDays(2), BookingState.APPROVED) - )); - when(bookingRepository.findAllByItemIdInAndStatusAndStartAfter(anyList(), any(), any())).thenReturn(List.of( - buildBooking(4L, e2, user2, now.plusDays(2), now.plusDays(7), BookingState.APPROVED) - )); - - List items = service.getAll(2L, 0, 10); - assertEquals(6L, items.get(1).getLastBooking().getId()); - assertEquals(4L, items.get(1).getNextBooking().getId()); - assertNull(items.get(0).getLastBooking()); - assertNull(items.get(0).getNextBooking()); - } - - @Test - void search() { - User user = buildUser(2L, "email", "name"); - Item e1 = buildItem(2L, "item", "description", true, user, null); - Item e5 = buildItem(6L, "item", "description", true, user, null); - when(repository.findAllByNameContainingIgnoreCaseOrDescriptionContainingIgnoreCaseAndAvailableTrue(anyString(), anyString(), any())).thenReturn(new PageImpl<>(List.of(e1, e5))); - List items = service.search("description", 0, 15); - assertEquals(2, items.size()); - } - - @ParameterizedTest - @NullSource - @ValueSource(strings = {" ", ""}) - void searchEmpty(String text) { - List itemDtos = service.search(text, 0, 15); - assertTrue(itemDtos.isEmpty()); - } - - @ParameterizedTest - @NullSource - @ValueSource(strings = {" ", ""}) - void addCommentValidationError(String text) { - assertThrows(ValidationException.class, () -> service.addComment(2L, 4L, buildCommentDto(1L, text, LocalDateTime.now(), "name")), "Empty comment"); - } - - @Test - void addCommentUserNotFound() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - when(repository.findById(anyLong())).thenReturn( - Optional.of(buildItem(2L, "item", "description", true, - buildUser(2L, "email@mail.com", "name"), null))); - assertThrows(UserNotFoundException.class, () -> service.addComment(3L, 2L, buildCommentDto(1L, "abc", LocalDateTime.now(), "name"))); - } - - @Test - void addCommentItemNotFund() { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(2L, "email@mail.com", "name"))); - when(repository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(ItemNotFoundException.class, () -> service.addComment(3L, 2L, buildCommentDto(1L, "abc", LocalDateTime.now(), "name"))); - } - - @Test - void addComment() throws Exception { - User user = buildUser(2L, "email@mail.com", "name"); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(user)); - Item item = buildItem(2L, "item", "description", true, user, null); - when(repository.findById(anyLong())).thenReturn( - Optional.of(item)); - when(bookingRepository.findAllByBookerId(anyLong())).thenReturn(List.of( - buildBooking(2L, item, user, LocalDateTime.now().minusDays(3), LocalDateTime.now().plusDays(5), BookingState.APPROVED) - )); - when(commentRepository.save(any())).thenReturn(buildComment(2L, "text", LocalDateTime.now(), "name", user)); - CommentDto commentDto = service.addComment(2L, 2L, buildCommentDto(1L, "text", LocalDateTime.now(), "name")); - assertEquals(2L, commentDto.getId()); - } - - @Test - void addCommentUnauthorized() throws Exception { - User user = buildUser(2L, "email@mail.com", "name"); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(user)); - Item item = buildItem(2L, "item", "description", true, user, null); - when(repository.findById(anyLong())).thenReturn( - Optional.of(item)); - when(bookingRepository.findAllByBookerId(anyLong())).thenReturn(List.of( - buildBooking(2L, item, user, LocalDateTime.now().minusDays(3), LocalDateTime.now().plusDays(5), BookingState.WAITING) - )); - assertThrows(ValidationException.class, () -> service.addComment(2L, 2L, buildCommentDto(1L, "text", LocalDateTime.now(), "nmae"))); - } - - @Test - void getByIdByUser() throws Exception { - User user = buildUser(2L, "email@mail.com", "name"); - when(userRepository.findById(anyLong())).thenReturn(Optional.of(user)); - Item item = buildItem(5L, "item", "description", true, user, null); - when(repository.findById(anyLong())).thenReturn( - Optional.of(item)); - when(bookingRepository.findAllByItemIdInAndStatusAndStartBeforeOrderByStartDesc(anyList(), any(), any())).thenReturn(List.of( - buildBooking(2L, buildItem(1L, "abc", "def", true, user, null), - user, LocalDateTime.now(), LocalDateTime.now(), BookingState.APPROVED))); - when(bookingRepository.findAllByItemIdInAndStatusAndStartAfterOrderByStart(anyList(), any(), any())).thenReturn(List.of( - buildBooking(8L, buildItem(7L, "abc", "def", true, user, null), - user, LocalDateTime.now(), LocalDateTime.now(), BookingState.APPROVED) - )); - ItemDto itemDto = service.getById(3L, 8L); - assertNull(itemDto.getNextBooking()); - assertNull(itemDto.getLastBooking()); - } - - private static Stream prepareDataForCreate() { - return Stream.of( - Arguments.of(buildItemDto(1L, null, "description", true), "Not valid"), - Arguments.of(buildItemDto(1L, "name", null, true), "Not valid"), - Arguments.of(buildItemDto(1L, "", "description", true), "Not valid"), - Arguments.of(buildItemDto(1L, " ", "description", true), "Not valid"), - Arguments.of(buildItemDto(1L, "name", "", true), "Not valid"), - Arguments.of(buildItemDto(1L, "name", " ", true), "Not valid") - ); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/request/controller/ItemRequestControllerTest.java b/src/test/java/ru/practicum/shareit/request/controller/ItemRequestControllerTest.java deleted file mode 100644 index 62c9f24..0000000 --- a/src/test/java/ru/practicum/shareit/request/controller/ItemRequestControllerTest.java +++ /dev/null @@ -1,193 +0,0 @@ -package ru.practicum.shareit.request.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import ru.practicum.shareit.BaseTest; -import ru.practicum.shareit.exception.ItemRequestNotFoundException; -import ru.practicum.shareit.exception.UserNotFoundException; -import ru.practicum.shareit.exception.ValidationException; -import ru.practicum.shareit.request.dto.ItemRequestDto; -import ru.practicum.shareit.request.service.ItemRequestServiceImpl; - -import java.util.List; - -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@AutoConfigureMockMvc -@WebMvcTest({ItemRequestController.class}) -class ItemRequestControllerTest extends BaseTest { - - @Autowired - private MockMvc mockMvc; - @Autowired - private ObjectMapper mapper; - @MockBean - private ItemRequestServiceImpl service; - - @Test - void create() throws Exception { - when(service.create(any(), anyLong())).thenReturn(buildItemRequestDto(2L, 2L, "Хотел бы воспользоваться мясорубкой")); - mockMvc.perform(post("/requests") - .header(xShareUserId, 2) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new ItemRequestDto()))) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(2)) - .andExpect(jsonPath("$.requester").value(2)) - .andExpect(jsonPath("$.description").value("Хотел бы воспользоваться мясорубкой")); - } - - @Test - void createUserNotFound() throws Exception { - when(service.create(any(), anyLong())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(post("/requests") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new ItemRequestDto()))) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void createValidationError() throws Exception { - when(service.create(any(), anyLong())).thenThrow(new ValidationException("Description is null")); - - mockMvc.perform(post("/requests") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new ItemRequestDto()))) - .andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.error").value("Description is null")); - } - - @Test - void getItemRequests() throws Exception { - ItemRequestDto ir1 = buildItemRequestDto(2L, 2L, "Хотел бы воспользоваться мясорубкой"); - ItemRequestDto ir2 = buildItemRequestDto(4L, 2L, "Хотел бы воспользоваться бензопилой"); - ir2.setItems(List.of(buildItemDto(11L, "Бензопила", "Бензопила \"Дружба\" новая, в упаковке", true))); - when(service.getAllOwnRequests(anyLong())).thenReturn(List.of(ir1, ir2)); - mockMvc.perform(MockMvcRequestBuilders.get("/requests") - .header(xShareUserId, 2) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$[0].id").value(2)) - .andExpect(jsonPath("$[0].requester").value(2)) - .andExpect(jsonPath("$[0].description").value("Хотел бы воспользоваться мясорубкой")) - .andExpect(jsonPath("$[0].items").isEmpty()) - .andExpect(jsonPath("$[1].id").value(4)) - .andExpect(jsonPath("$[1].requester").value(2)) - .andExpect(jsonPath("$[1].items[0].id").value(11)) - .andExpect(jsonPath("$[1].items[0].name").value("Бензопила")) - .andExpect(jsonPath("$[1].items[0].description").value("Бензопила \"Дружба\" новая, в упаковке")) - .andExpect(jsonPath("$[1].description").value("Хотел бы воспользоваться бензопилой")); - } - - @Test - void getItemRequestsUserNotFound() throws Exception { - when(service.getAllOwnRequests(anyLong())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(MockMvcRequestBuilders.get("/requests") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void getItemRequestUserNotFound() throws Exception { - when(service.getById(anyLong(), anyLong())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(MockMvcRequestBuilders.get("/requests/45") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void getItemRequestItemRequestNotFound() throws Exception { - when(service.getById(anyLong(), anyLong())).thenThrow(new ItemRequestNotFoundException("Item request not found")); - - mockMvc.perform(MockMvcRequestBuilders.get("/requests/45") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void getItemRequest() throws Exception { - when(service.getById(anyLong(), anyLong())).thenReturn(buildItemRequestDto(2L, 2L, "Хотел бы воспользоваться мясорубкой")); - - mockMvc.perform(MockMvcRequestBuilders.get("/requests/1") - .header(xShareUserId, 2) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(2)) - .andExpect(jsonPath("$.requester").value(2)) - .andExpect(jsonPath("$.description").value("Хотел бы воспользоваться мясорубкой")); - } - - @Test - void getAllItemRequests() throws Exception { - ItemRequestDto ir1 = buildItemRequestDto(2L, 7L, "Хотел бы воспользоваться мясорубкой"); - ItemRequestDto ir2 = buildItemRequestDto(4L, 9L, "Хотел бы воспользоваться бензопилой"); - ir2.setItems(List.of(buildItemDto(11L, "Бензопила", "Бензопила \"Дружба\" новая, в упаковке", true))); - when(service.getAllUserRequests(anyLong(), anyInt(), anyInt())).thenReturn(List.of(ir1, ir2)); - mockMvc.perform(MockMvcRequestBuilders.get("/requests/all") - .param("from", "0") - .param("size", "20") - .header(xShareUserId, 2) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$[0].id").value(2)) - .andExpect(jsonPath("$[0].requester").value(7)) - .andExpect(jsonPath("$[0].description").value("Хотел бы воспользоваться мясорубкой")) - .andExpect(jsonPath("$[0].items").isEmpty()) - .andExpect(jsonPath("$[1].id").value(4)) - .andExpect(jsonPath("$[1].requester").value(9)) - .andExpect(jsonPath("$[1].items[0].id").value(11)) - .andExpect(jsonPath("$[1].items[0].name").value("Бензопила")) - .andExpect(jsonPath("$[1].items[0].description").value("Бензопила \"Дружба\" новая, в упаковке")) - .andExpect(jsonPath("$[1].description").value("Хотел бы воспользоваться бензопилой")); - } - - @Test - void getAllItemRequestsUserNotFound() throws Exception { - when(service.getAllUserRequests(anyLong(), anyInt(), anyInt())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(MockMvcRequestBuilders.get("/requests/all") - .param("from", "0") - .param("size", "20") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void getAllItemRequestsValidationError() throws Exception { - when(service.getAllUserRequests(anyLong(), anyInt(), anyInt())).thenThrow(new ValidationException("Error")); - - mockMvc.perform(MockMvcRequestBuilders.get("/requests/all") - .param("from", "0") - .param("size", "20") - .header(xShareUserId, 18L) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.error").value("Error")); - } - -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/request/repository/ItemRequestRepositoryTest.java b/src/test/java/ru/practicum/shareit/request/repository/ItemRequestRepositoryTest.java deleted file mode 100644 index dd5f238..0000000 --- a/src/test/java/ru/practicum/shareit/request/repository/ItemRequestRepositoryTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package ru.practicum.shareit.request.repository; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.data.domain.PageRequest; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.jdbc.Sql; -import ru.practicum.shareit.BaseTest; -import ru.practicum.shareit.request.model.ItemRequest; - -import java.util.List; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertTrue; - -@DataJpaTest -@ActiveProfiles("test") -@Sql("/data.sql") -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -class ItemRequestRepositoryTest extends BaseTest { - @Autowired - private ItemRequestRepository itemRequestRepository; - - - @Test - void findAllByRequesterIdOrderByCreatedDesc() { - List itemRequests = itemRequestRepository.findAllByRequesterIdOrderByCreatedDesc(1L); - assertEquals(1, itemRequests.size()); - assertEquals(1, itemRequests.get(0).getId()); - } - - @Test - void findAllByRequesterIdNotOrderByCreatedDesc() { - List itemRequests = itemRequestRepository.findAllByRequesterIdNotOrderByCreatedDesc(1L, - PageRequest.of(0, 10)).getContent(); - assertEquals(2, itemRequests.size()); - assertEquals(2, itemRequests.get(0).getId()); - assertEquals(3, itemRequests.get(1).getId()); - } - - @Test - void save() { - ItemRequest itemRequest = new ItemRequest(); - itemRequest.setRequester(buildUser(2L, "email", "name")); - itemRequest.setDescription("item request description"); - ItemRequest savedItemRequest = itemRequestRepository.save(itemRequest); - assertEquals(4, savedItemRequest.getId()); - } - - @Test - void findAll() { - List itemRequests = itemRequestRepository.findAll(); - assertEquals(3, itemRequests.size()); - } - - @Test - void findById() { - Optional itemRequest = itemRequestRepository.findById(2L); - assertTrue(itemRequest.isPresent()); - assertEquals("Хотел бы воспользоваться мясорубкой", itemRequest.get().getDescription()); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/request/service/ItemRequestServiceImplTest.java b/src/test/java/ru/practicum/shareit/request/service/ItemRequestServiceImplTest.java deleted file mode 100644 index c304ee7..0000000 --- a/src/test/java/ru/practicum/shareit/request/service/ItemRequestServiceImplTest.java +++ /dev/null @@ -1,166 +0,0 @@ -package ru.practicum.shareit.request.service; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.domain.PageImpl; -import ru.practicum.shareit.BaseTest; -import ru.practicum.shareit.exception.ItemRequestNotFoundException; -import ru.practicum.shareit.exception.UserNotFoundException; -import ru.practicum.shareit.exception.ValidationException; -import ru.practicum.shareit.item.repository.ItemRepository; -import ru.practicum.shareit.request.dto.ItemRequestDto; -import ru.practicum.shareit.request.model.ItemRequest; -import ru.practicum.shareit.request.repository.ItemRequestRepository; -import ru.practicum.shareit.user.repository.UserRepository; - -import java.util.List; -import java.util.Optional; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.when; - -@AutoConfigureMockMvc -@WebMvcTest({ItemRequestServiceImpl.class, ItemRequestRepository.class, UserRepository.class, ItemRepository.class}) -class ItemRequestServiceImplTest extends BaseTest { - - @Autowired - private ItemRequestServiceImpl service; - @MockBean - private ItemRequestRepository itemRequestRepository; - @MockBean - private UserRepository userRepository; - @MockBean - private ItemRepository itemRepository; - - @Test - void createUserNotFound() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(UserNotFoundException.class, - () -> service.create(buildItemRequestDto(1L, 2L, "123"), 2L), "User not found"); - } - - @ParameterizedTest - @MethodSource("prepareDataForCreate") - void createValidationError(String description, String expectedMessage) { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(2L, "mail@mail.com", "name"))); - assertThrows(ValidationException.class, () -> service.create(buildItemRequestDto(1L, 2L, description), 2L)); - } - - @Test - void create() throws Exception { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(2L, "mail@mail.com", "name"))); - when(itemRequestRepository.save(any())).thenReturn(buildItemRequest(1L, buildUser(2L, "email@mail.com", "name"), "abcde")); - when(itemRepository.findAllByRequestId(anyLong())).thenReturn(List.of(buildItem(1L, "name", "description", true, buildUser(3L, "mail@mail.com", "name"), null))); - ItemRequestDto created = service.create(buildItemRequestDto(1L, 2L, "abcde"), 2L); - assertEquals(1L, created.getId()); - assertFalse(created.getItems().isEmpty()); - } - - @Test - void getByIdUserNotFound() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(UserNotFoundException.class, - () -> service.getById(3L, 2L), "User not found"); - } - - @Test - void getByIdNotFound() { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(2L, "mail@mail.com", "name"))); - when(itemRequestRepository.findById(any())).thenReturn(Optional.empty()); - assertThrows(ItemRequestNotFoundException.class, () -> service.getById(2L, 1L), "Item request not found"); - } - - @Test - void getById() throws Exception { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(2L, "mail@mail.com", "name"))); - when(itemRequestRepository.findById(any())).thenReturn(Optional.of(buildItemRequest(1L, buildUser(2L, "email@mail.com", "name"), "abcde"))); - when(itemRepository.findAllByRequestId(anyLong())).thenReturn(List.of(buildItem(1L, "name", "description", true, buildUser(3L, "mail@mail.com", "name"), null))); - ItemRequestDto ir = service.getById(2L, 1L); - assertEquals(1L, ir.getId()); - assertFalse(ir.getItems().isEmpty()); - } - - @Test - void getAllOwnRequestsUserNotFound() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(UserNotFoundException.class, - () -> service.getAllOwnRequests(3L), "User not found"); - } - - @Test - void getAllOwnRequests() throws UserNotFoundException { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(2L, "mail@mail.com", "name"))); - ItemRequest e1 = buildItemRequest(1L, buildUser(2L, "email@mail.com", "name"), "abcde"); - ItemRequest e2 = buildItemRequest(2L, buildUser(2L, "email@mail.com", "name"), "abcde"); - ItemRequest e3 = buildItemRequest(3L, buildUser(2L, "email@mail.com", "name"), "abcde"); - when(itemRequestRepository.findAllByRequesterIdOrderByCreatedDesc(any())).thenReturn(List.of(e1, e2, e3)); - when(itemRepository.findAllByRequestIdIn(anyList())).thenReturn(List.of( - buildItem(4L, "name", "description", true, buildUser(3L, "mail@mail.com", "name"), e1), - buildItem(5L, "name", "description", true, buildUser(3L, "mail@mail.com", "name"), e1), - buildItem(6L, "name", "description", true, buildUser(3L, "mail@mail.com", "name"), e2), - buildItem(7L, "name", "description", true, buildUser(3L, "mail@mail.com", "name"), e3) - )); - List requests = service.getAllOwnRequests(2L); - assertEquals(3, requests.size()); - assertEquals(2, requests.get(0).getItems().size()); - assertEquals(1, requests.get(1).getItems().size()); - assertEquals(1, requests.get(2).getItems().size()); - } - - @Test - void getAllUserRequestsUserNotFound() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(UserNotFoundException.class, - () -> service.getAllUserRequests(3L, 0, 5), "User not found"); - } - - @Test - void getAllUserRequests() throws UserNotFoundException, ValidationException { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(2L, "mail@mail.com", "name"))); - ItemRequest e1 = buildItemRequest(1L, buildUser(3L, "email@mail.com", "name"), "abcde"); - ItemRequest e2 = buildItemRequest(2L, buildUser(4L, "email@mail.com", "name"), "abcde"); - ItemRequest e3 = buildItemRequest(3L, buildUser(5L, "email@mail.com", "name"), "abcde"); - when(itemRequestRepository.findAllByRequesterIdNotOrderByCreatedDesc(anyLong(), any())).thenReturn(new PageImpl<>(List.of(e1, e2, e3))); - when(itemRepository.findAllByRequestIdIn(anyList())).thenReturn(List.of( - buildItem(4L, "name", "description", true, buildUser(6L, "mail@mail.com", "name"), e1), - buildItem(5L, "name", "description", true, buildUser(7L, "mail@mail.com", "name"), e1), - buildItem(6L, "name", "description", true, buildUser(8L, "mail@mail.com", "name"), e2), - buildItem(7L, "name", "description", true, buildUser(9L, "mail@mail.com", "name"), e3) - )); - List requests = service.getAllUserRequests(2L, 0, 15); - assertEquals(3, requests.size()); - assertEquals(2, requests.get(0).getItems().size()); - assertEquals(1, requests.get(1).getItems().size()); - assertEquals(1, requests.get(2).getItems().size()); - } - - @Test - void getAllUserRequestsEmpty() throws UserNotFoundException, ValidationException { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(2L, "mail@mail.com", "name"))); - List requests = service.getAllUserRequests(2L, null, null); - assertTrue(requests.isEmpty()); - } - - @Test - void getAllUserRequestsValidationError() throws UserNotFoundException, ValidationException { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(2L, "mail@mail.com", "name"))); - assertThrows(ValidationException.class, () -> service.getAllUserRequests(2L, 0, 0), "Error"); - } - - private static Stream prepareDataForCreate() { - return Stream.of( - Arguments.of(null, "Description is null"), - Arguments.of(" ", "Description is null"), - Arguments.of("", "Description is null") - ); - } - -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/user/controller/UserControllerTest.java b/src/test/java/ru/practicum/shareit/user/controller/UserControllerTest.java deleted file mode 100644 index 9f8929d..0000000 --- a/src/test/java/ru/practicum/shareit/user/controller/UserControllerTest.java +++ /dev/null @@ -1,148 +0,0 @@ -package ru.practicum.shareit.user.controller; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import ru.practicum.shareit.BaseTest; -import ru.practicum.shareit.exception.UserNotFoundException; -import ru.practicum.shareit.exception.ValidationException; -import ru.practicum.shareit.user.dto.UserDto; -import ru.practicum.shareit.user.service.UserServiceImpl; - -import java.util.List; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.patch; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@AutoConfigureMockMvc -@WebMvcTest({UserController.class}) -class UserControllerTest extends BaseTest { - - @Autowired - private MockMvc mockMvc; - @Autowired - private ObjectMapper mapper; - @MockBean - private UserServiceImpl service; - - @Test - void create() throws Exception { - when(service.create(any())).thenReturn(buildUserDto(3L, "user@mail.com", "user")); - - mockMvc.perform(post("/users") - .header(xShareUserId, 38) - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new UserDto()))) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(3)) - .andExpect(jsonPath("$.email").value("user@mail.com")) - .andExpect(jsonPath("$.name").value("user")); - } - - @Test - void createValidationError() throws Exception { - when(service.create(any())).thenThrow(new ValidationException("Error")); - - mockMvc.perform(post("/users") - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new UserDto()))) - .andExpect(status().isBadRequest()) - .andExpect(jsonPath("$.error").value("Error")); - } - - @Test - void update() throws Exception { - when(service.update(anyLong(), any())).thenReturn(buildUserDto(3L, "user@mail.com", "user")); - - mockMvc.perform(patch("/users/2") - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new UserDto()))) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(3)) - .andExpect(jsonPath("$.email").value("user@mail.com")) - .andExpect(jsonPath("$.name").value("user")); - } - - @Test - void updateUserNotFound() throws Exception { - when(service.update(anyLong(), any())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(patch("/users/2") - .contentType(MediaType.APPLICATION_JSON) - .content(mapper.writeValueAsString(new UserDto()))) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void delete() throws Exception { - when(service.delete(anyLong())).thenReturn(buildUserDto(3L, "user@mail.com", "user")); - - mockMvc.perform(MockMvcRequestBuilders.delete("/users/2") - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(3)) - .andExpect(jsonPath("$.email").value("user@mail.com")) - .andExpect(jsonPath("$.name").value("user")); - } - - @Test - void deleteUserNotFound() throws Exception { - when(service.delete(anyLong())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(MockMvcRequestBuilders.delete("/users/2") - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void getById() throws Exception { - when(service.getById(anyLong())).thenReturn(buildUserDto(3L, "user@mail.com", "user")); - - mockMvc.perform(MockMvcRequestBuilders.get("/users/2") - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.id").value(3)) - .andExpect(jsonPath("$.email").value("user@mail.com")) - .andExpect(jsonPath("$.name").value("user")); - } - - @Test - void getByIdNotFound() throws Exception { - when(service.getById(anyLong())).thenThrow(new UserNotFoundException("User not found")); - - mockMvc.perform(MockMvcRequestBuilders.get("/users/2") - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isNotFound()) - .andExpect(jsonPath("$.error").value("Объект не найден")); - } - - @Test - void getAll() throws Exception { - when(service.getAll()).thenReturn(List.of( - buildUserDto(1L, "user@mail.com", "user"), - buildUserDto(2L, "user_user@mail.com", "user_user"))); - - mockMvc.perform(MockMvcRequestBuilders.get("/users") - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$[0].id").value(1)) - .andExpect(jsonPath("$[0].email").value("user@mail.com")) - .andExpect(jsonPath("$[0].name").value("user")) - .andExpect(jsonPath("$[1].id").value(2)) - .andExpect(jsonPath("$[1].email").value("user_user@mail.com")) - .andExpect(jsonPath("$[1].name").value("user_user")); - } -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/user/repository/UserRepositoryTest.java b/src/test/java/ru/practicum/shareit/user/repository/UserRepositoryTest.java deleted file mode 100644 index 6b7d22e..0000000 --- a/src/test/java/ru/practicum/shareit/user/repository/UserRepositoryTest.java +++ /dev/null @@ -1,53 +0,0 @@ -package ru.practicum.shareit.user.repository; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.dao.DataIntegrityViolationException; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.jdbc.Sql; -import ru.practicum.shareit.BaseTest; -import ru.practicum.shareit.user.model.User; - -import java.util.List; -import java.util.Optional; - -import static org.junit.jupiter.api.Assertions.*; - -@DataJpaTest -@ActiveProfiles("test") -@Sql("/data.sql") -@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) -class UserRepositoryTest extends BaseTest { - - @Autowired - private UserRepository userRepository; - - @Test - void save() { - User user = buildUser(null, "user78@mail.com", "user78"); - User savedUser = userRepository.save(user); - assertEquals(5, savedUser.getId()); - } - - @Test - void saveDuplicateEmail() { - User user = buildUser(null, "user@user.com", "user78"); - assertThrows(DataIntegrityViolationException.class, () -> userRepository.save(user)); - } - - @Test - void findAll() { - List itemRequests = userRepository.findAll(); - assertEquals(4, itemRequests.size()); - } - - @Test - void findById() { - Optional user = userRepository.findById(4L); - assertTrue(user.isPresent()); - assertEquals("practicum@yandex.ru", user.get().getEmail()); - } - -} \ No newline at end of file diff --git a/src/test/java/ru/practicum/shareit/user/service/UserServiceImplTest.java b/src/test/java/ru/practicum/shareit/user/service/UserServiceImplTest.java deleted file mode 100644 index 5bdd8ca..0000000 --- a/src/test/java/ru/practicum/shareit/user/service/UserServiceImplTest.java +++ /dev/null @@ -1,121 +0,0 @@ -package ru.practicum.shareit.user.service; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.MethodSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import ru.practicum.shareit.BaseTest; -import ru.practicum.shareit.exception.UserNotFoundException; -import ru.practicum.shareit.exception.ValidationException; -import ru.practicum.shareit.user.dto.UserDto; -import ru.practicum.shareit.user.repository.UserRepository; - -import java.util.List; -import java.util.Optional; -import java.util.stream.Stream; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.when; - -@AutoConfigureMockMvc -@WebMvcTest({UserServiceImpl.class, UserRepository.class}) -class UserServiceImplTest extends BaseTest { - @Autowired - private UserServiceImpl service; - @MockBean - UserRepository userRepository; - - @ParameterizedTest - @MethodSource("prepareDataForCreate") - void create(String email, String name, String expectedMessage) { - UserDto userDto = buildUserDto(1L, email, name); - assertThrows(ValidationException.class, () -> service.create(userDto), expectedMessage); - } - - @Test - void create() throws Exception { - when(userRepository.save(any())).thenReturn(buildUser(2L, "email@user.com", "name")); - UserDto createdUser = service.create(buildUserDto(0L, "email@user.com", "name")); - assertEquals(2L, createdUser.getId()); - assertEquals("email@user.com", createdUser.getEmail()); - assertEquals("name", createdUser.getName()); - } - - @Test - void updateUserNotFound() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(UserNotFoundException.class, - () -> service.update(2L, buildUserDto(2L, "email@mail.com", "name")), "User not found"); - } - - @Test - void update() throws Exception { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(3L, "email@mail.com", "name"))); - when(userRepository.save(any())).thenReturn(buildUser(3L, "updated@mail.com", "name updated")); - UserDto updated = service.update(3L, buildUserDto(3L, "update@mail.com", "name")); - assertEquals(3L, updated.getId()); - assertEquals("updated@mail.com", updated.getEmail()); - assertEquals("name updated", updated.getName()); - } - - @Test - void deleteWithError() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(UserNotFoundException.class, - () -> service.delete(2L), "User not found"); - } - - @Test - void delete() throws Exception { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(3L, "email@mail.com", "name"))); - doNothing().when(userRepository).deleteById(anyLong()); - UserDto updated = service.delete(3L); - assertEquals(3L, updated.getId()); - assertEquals("email@mail.com", updated.getEmail()); - assertEquals("name", updated.getName()); - } - - @Test - void getByIdWithError() { - when(userRepository.findById(anyLong())).thenReturn(Optional.empty()); - assertThrows(UserNotFoundException.class, - () -> service.getById(2L), "User not found"); - } - - @Test - void getById() throws Exception { - when(userRepository.findById(anyLong())).thenReturn(Optional.of(buildUser(3L, "email@mail.com", "name"))); - UserDto updated = service.getById(3L); - assertEquals(3L, updated.getId()); - assertEquals("email@mail.com", updated.getEmail()); - assertEquals("name", updated.getName()); - } - - @Test - void getAll() { - when(userRepository.findAll()).thenReturn(List.of( - buildUser(1L, "email@mail.com", "name"), - buildUser(2L, "user@mail.com", "anna") - )); - List users = service.getAll(); - assertEquals(2, users.size()); - } - - private static Stream prepareDataForCreate() { - return Stream.of( - Arguments.of(null, "name", "Email is null!"), - Arguments.of("emil@mail.com", " ", "Name is null or empty"), - Arguments.of("emil@mail.com", "", "Name is null or empty"), - Arguments.of("emil@mail.com", null, "Name is null or empty") - ); - } - -} \ No newline at end of file diff --git a/src/test/resources/application-test.properties b/src/test/resources/application-test.properties deleted file mode 100644 index 9cf7f98..0000000 --- a/src/test/resources/application-test.properties +++ /dev/null @@ -1,13 +0,0 @@ -spring.jpa.hibernate.ddl-auto=create-drop -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.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 diff --git a/src/test/resources/data.sql b/src/test/resources/data.sql deleted file mode 100644 index fb1336e..0000000 --- a/src/test/resources/data.sql +++ /dev/null @@ -1,27 +0,0 @@ -INSERT INTO users(email, name) VALUES ('updateName@user.com','updateName'); -INSERT INTO users(email, name) VALUES ('user@user.com','user'); -INSERT INTO users(email, name) VALUES ('other@other.com','other'); -INSERT INTO users(email, name) VALUES ('practicum@yandex.ru','practicum'); - -INSERT INTO item_requests(description, requester_id, created) VALUES ('Хотел бы воспользоваться щёткой для обуви',1,'2023-04-03 15:34:48'); -INSERT INTO item_requests(description, requester_id, created) VALUES ('Хотел бы воспользоваться мясорубкой',2,'2023-04-02 12:34:48'); -INSERT INTO item_requests(description, requester_id, created) VALUES ('Хотел бы воспользоваться бензопилой',4,'2023-03-23 10:34:48'); - -INSERT INTO items(description, name, available, owner_id, request_id)VALUES ('Аккумуляторная дрель + аккумулятор','Аккумуляторная дрель',true,1,3); -INSERT INTO items(description, name, available, owner_id, request_id)VALUES ('Аккумуляторная отвертка','Отвертка',true,4,NULL); -INSERT INTO items(description, name, available, owner_id, request_id)VALUES ('Тюбик суперклея марки Момент','Клей Момент',true,4,2); -INSERT INTO items( description, name, available, owner_id, request_id)VALUES ('Стол для празднования','Кухонный стол',true,3,NULL); -INSERT INTO items(description, name, available, owner_id, request_id)VALUES ('Стандартная щётка для обуви','Щётка для обуви',true,4,1); - -INSERT INTO bookings(booking_start, booking_end, booking_status, booker_id, item_id) VALUES ('2023-04-03 15:34:34','2023-04-03 15:34:35','APPROVED',1,2); -INSERT INTO bookings(booking_start, booking_end, booking_status, booker_id, item_id) VALUES ('2023-04-04 15:34:32','2023-04-05 15:34:32','CANCELED',1,2); -INSERT INTO bookings(booking_start, booking_end, booking_status, booker_id, item_id) VALUES ('2023-04-04 15:34:34','2023-04-04 16:34:34','REJECTED',4,1); -INSERT INTO bookings(booking_start, booking_end, booking_status, booker_id, item_id) VALUES ('2023-04-03 16:34:34','2023-04-03 17:34:34','APPROVED',3,2); -INSERT INTO bookings(booking_start, booking_end, booking_status, booker_id, item_id) VALUES ('2023-04-03 15:34:42','2023-04-04 15:34:39','REJECTED',1,3); -INSERT INTO bookings(booking_start, booking_end, booking_status, booker_id, item_id) VALUES ('2023-04-03 15:34:42','2023-04-03 15:34:43','WAITING',1,2); -INSERT INTO bookings(booking_start, booking_end, booking_status, booker_id, item_id) VALUES ('2023-04-13 15:34:40','2023-04-14 15:34:40','APPROVED',3,1); -INSERT INTO bookings(booking_start, booking_end, booking_status, booker_id, item_id) VALUES ('2023-04-03 15:34:42','2023-04-03 16:34:40','WAITING',1,4); - -INSERT INTO comments(text, item, author, created) VALUES ('Add comment from user1',2,1,'2023-04-03 15:34:46'); -INSERT INTO comments(text, item, author, created) VALUES ('Add comment from user2',3,2,'2023-03-23 15:34:46'); -INSERT INTO comments(text, item, author, created) VALUES ('Add comment from user3',4,3,'2023-04-01 15:34:46'); \ No newline at end of file diff --git a/src/test/resources/schema.sql b/src/test/resources/schema.sql deleted file mode 100644 index e9378ad..0000000 --- a/src/test/resources/schema.sql +++ /dev/null @@ -1,51 +0,0 @@ -create TABLE IF NOT EXISTS users -( - id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, - email VARCHAR (512) NOT NULL, - name VARCHAR (512) NOT NULL, - CONSTRAINT pk_user PRIMARY KEY (id), - CONSTRAINT UQ_USER_EMAIL UNIQUE (email)); - -create TABLE IF NOT EXISTS item_requests -( - id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, - description VARCHAR (1024) NOT NULL, - requester_id BIGINT not null, - created TIMESTAMP not null, - CONSTRAINT pk_item_request PRIMARY KEY (id), - CONSTRAINT FK_ITEM_REQUEST_REQUESTER FOREIGN KEY (requester_id) REFERENCES users (id)); - -create TABLE IF NOT EXISTS items -( - id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, - description VARCHAR (1024) NOT NULL, - name VARCHAR(512) NOT NULL, - available BOOLEAN DEFAULT TRUE, - owner_id BIGINT, - request_id BIGINT, - CONSTRAINT pk_item PRIMARY KEY (id), - CONSTRAINT FK_ITEM_REQUEST FOREIGN KEY (request_id) REFERENCES item_requests(id), - CONSTRAINT FK_ITEM_OWNER FOREIGN KEY (owner_id) REFERENCES users (id)); - -create TABLE IF NOT EXISTS bookings -( - id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, - booking_start TIMESTAMP NOT NULL, - booking_end TIMESTAMP NOT NULL, - booking_status VARCHAR(512) NOT NULL, - owner_id BIGINT, - item_id BIGINT, - CONSTRAINT pk_booking PRIMARY KEY(id), - CONSTRAINT FK_BOOKING_OWNER FOREIGN KEY(owner_id) REFERENCES users(id), - CONSTRAINT FK_BOOKING_ITEM FOREIGN KEY(item_id) REFERENCES items (id)); - -create TABLE IF NOT EXISTS comments -( - id BIGINT GENERATED BY DEFAULT AS IDENTITY NOT NULL, - text VARCHAR (1024) NOT NULL, - item BIGINT, - author BIGINT, - created TIMESTAMP NOT NULL, - CONSTRAINT pk_comment PRIMARY KEY(id), - CONSTRAINT FK_COMMENT_OWNER FOREIGN KEY(author) REFERENCES users(id), - CONSTRAINT FK_COMMENT_ITEM FOREIGN KEY(item) REFERENCES items (id)); \ No newline at end of file diff --git a/start-app.sh b/start-app.sh new file mode 100644 index 0000000..9585dc5 --- /dev/null +++ b/start-app.sh @@ -0,0 +1,2 @@ +#!/bin/bash +docker-compose -f docker-compose.yml up -d \ No newline at end of file