<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xmlns:tt="http://teletype.in/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:media="http://search.yahoo.com/mrss/"><channel><title>Pavel</title><generator>teletype.in</generator><description><![CDATA[Pavel]]></description><image><url>https://img3.teletype.in/files/e7/1d/e71d6982-2488-4ad6-851b-3b0dc91f403e.png</url><title>Pavel</title><link>https://teletype.in/@kekocola</link></image><link>https://teletype.in/@kekocola?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=kekocola</link><atom:link rel="self" type="application/rss+xml" href="https://teletype.in/rss/kekocola?offset=0"></atom:link><atom:link rel="next" type="application/rss+xml" href="https://teletype.in/rss/kekocola?offset=10"></atom:link><atom:link rel="search" type="application/opensearchdescription+xml" title="Teletype" href="https://teletype.in/opensearch.xml"></atom:link><pubDate>Fri, 17 Apr 2026 08:00:42 GMT</pubDate><lastBuildDate>Fri, 17 Apr 2026 08:00:42 GMT</lastBuildDate><item><guid isPermaLink="true">https://teletype.in/@kekocola/hBPzzPZqVQh</guid><link>https://teletype.in/@kekocola/hBPzzPZqVQh?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=kekocola</link><comments>https://teletype.in/@kekocola/hBPzzPZqVQh?utm_source=teletype&amp;utm_medium=feed_rss&amp;utm_campaign=kekocola#comments</comments><dc:creator>kekocola</dc:creator><title>тестеры записываемся на копайлот</title><pubDate>Wed, 28 Feb 2024 18:31:51 GMT</pubDate><description><![CDATA[Идете и даете своему бекендеру пизды, чтобы он замутил свагер]]></description><content:encoded><![CDATA[
  <h3 id="L1rC">Первый шаг:</h3>
  <p id="OHL6">Идете и даете своему бекендеру пизды, чтобы он замутил свагер</p>
  <h3 id="nx56">Второй шаг:</h3>
  <p id="8eW6">Копируете курл из сваггера и типовые ответы на запрос</p>
  <h3 id="3jaG">Третий шаг:</h3>
  <p id="lOU0">Идете в чатгпт или копайлот и делаете вот примерно такой запрос</p>
  <blockquote id="nmhU">Hi. I have a curl reqest. Its a login request to my service and i want to make autotests for this request. Write tests for me. Use Java language and okhttp3 library. Each test should be a separate method.<br /><br />This is curl: <code>curl -X POST --header &#x27;Content-Type: application/json&#x27; --header &#x27;Accept: application/json&#x27; -d &#x27;{ \ &quot;email&quot;: &quot;m%40m.ru&quot;, \ &quot;password&quot;: &quot;password&quot; \ }&#x27; &#x27;ИМАДЖИНИРУЙ ТУТ ЮРЛ&#x27;<br /><br /></code>Threre is a 200 response, that comes if user go with correct credetensials. Token changes each time as user logins: <code>{ &quot;refresh_token&quot;: ИМАДЖИНИРУЙ ЧТО ТУТ ТОКЕН&quot;, &quot;token&quot;: &quot;ИМАДЖИНИРУЙ ЧТО ТУТ ТОКЕН&quot; }<br /><br /></code>Threre is a 401 response if user go with invalid credetentials: <code>{ &quot;status&quot;: 401, &quot;data&quot;: { &quot;email&quot;: &quot;donotoreply@.org&quot; }, &quot;error&quot;: 2, &quot;message&quot;: &quot;Wrong email or password&quot; }</code></blockquote>
  <h3 id="Imkh">Четвертый шаг:</h3>
  <p id="zdnd">Ждете пока чудо Омниссии думает и выдает нам примерно вот что</p>
  <pre id="KYRz" data-lang="java">import okhttp3.*;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class LoginServiceTest {
    private static final MediaType JSON = MediaType.get(&quot;application/json; charset=utf-8&quot;);
    private static final OkHttpClient client = new OkHttpClient();

    private String post(String url, String json) throws IOException {
        RequestBody body = RequestBody.create(json, JSON);
        Request request = new Request.Builder()
                .url(url)
                .post(body)
                .build();
        try (Response response = client.newCall(request).execute()) {
            return response.body().string();
        }
    }

    @Test
    public void testSuccessfulLogin() throws IOException {
        String json = &quot;{ \&quot;email\&quot;: \&quot;m@m.ru\&quot;, \&quot;password\&quot;: \&quot;password\&quot; }&quot;;
        String response = post(&quot;ИМАДЖИНИРУЙ ТУТ ЮРЛ&quot;, json);
        // Assert that the response contains a token
        assert(response.contains(&quot;token&quot;));
    }

    @Test
    public void testUnsuccessfulLogin() throws IOException {
        String json = &quot;{ \&quot;email\&quot;: \&quot;wrong@m.ru\&quot;, \&quot;password\&quot;: \&quot;wrongpassword\&quot; }&quot;;
        String response = post(&quot;ИМАДЖИНИРУЙ ТУТ ЮРЛ&quot;, json);
        // Assert that the response contains an error message
        assertEquals(&quot;{\&quot;status\&quot;:401,\&quot;data\&quot;:{\&quot;email\&quot;:\&quot;donotoreply@.org\&quot;},\&quot;error\&quot;:2,\&quot;message\&quot;:\&quot;Wrong email or password\&quot;}&quot;, response);
    }
}
</pre>
  <h3 id="Q8TI">Пятый шаг:</h3>
  <p id="ztOI">Подумать самому все же придется, смотрим что тут не так. Хуемое, джейсончики как стринги прямо в коде, это беспонтово. Еще можно урл объявлять прям в самом начале, тестим то токо один метод.</p>
  <p id="dhhK">Хуярим новый промт</p>
  <blockquote id="a5TE">Can you fix what you write please. Request url <code>ИМАДЖИНИРУЙ ТУТ ЮРЛ</code> should not be specified in tests it should be specified as a variable in the begining of class.<br /><br />Also please make request body as separate class with getters and setters</blockquote>
  <h3 id="zWRK">Шестой шаг:</h3>
  <p id="r5b2">Оно нам нахуевертит вот такого примерно</p>
  <pre id="JJKC" data-lang="java">import okhttp3.*;
import org.junit.jupiter.api.Test;
import com.google.gson.Gson;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class LoginServiceTest {
    private static final MediaType JSON = MediaType.get(&quot;application/json; charset=utf-8&quot;);
    private static final OkHttpClient client = new OkHttpClient();
    private static final String URL = &quot;ИМАДЖИНИРУЙ ТУТ ЮРЛ&quot;;
    private static final Gson gson = new Gson();

    private String post(String url, LoginBody body) throws IOException {
        RequestBody requestBody = RequestBody.create(gson.toJson(body), JSON);
        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .build();
        try (Response response = client.newCall(request).execute()) {
            return response.body().string();
        }
    }

    @Test
    public void testSuccessfulLogin() throws IOException {
        LoginBody body = new LoginBody(&quot;m@m.ru&quot;, &quot;password&quot;);
        String response = post(URL, body);
        // Assert that the response contains a token
        assert(response.contains(&quot;token&quot;));
    }

    @Test
    public void testUnsuccessfulLogin() throws IOException {
        LoginBody body = new LoginBody(&quot;wrong@m.ru&quot;, &quot;wrongpassword&quot;);
        String response = post(URL, body);
        // Assert that the response contains an error message
        assertEquals(&quot;{\&quot;status\&quot;:401,\&quot;data\&quot;:{\&quot;email\&quot;:\&quot;donotoreply@.org\&quot;},\&quot;error\&quot;:2,\&quot;message\&quot;:\&quot;Wrong email or password\&quot;}&quot;, response);
    }

    static class LoginBody {
        private String email;
        private String password;

        public LoginBody(String email, String password) {
            this.email = email;
            this.password = password;
        }

        public String getEmail() {
            return email;
        }

        public void setEmail(String email) {
            this.email = email;
        }

        public String getPassword() {
            return password;
        }

        public void setPassword(String password) {
            this.password = password;
        }
    }
}</pre>
  <h3 id="wQW0">Седьмой шаг:</h3>
  <p id="1JQc">Думаем по новой, вспоминаем, что есть плагин который сам ставит геттеры сеттеры. Пишем.</p>
  <blockquote id="pFU1">Please use Lombok annotations and change LoginBody class</blockquote>
  <h3 id="zje2">Восьмой шаг:</h3>
  <p id="rctC">Воооо, теперь почти заебись</p>
  <pre id="H9yY" data-lang="java">
import okhttp3.*;
import org.junit.jupiter.api.Test;
import com.google.gson.Gson;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import lombok.Getter;
import lombok.Setter;
import lombok.AllArgsConstructor;

public class LoginServiceTest {
    private static final MediaType JSON = MediaType.get(&quot;application/json; charset=utf-8&quot;);
    private static final OkHttpClient client = new OkHttpClient();
    private static final String URL = &quot;ИМАДЖИНИРУЙ ТУТ ЮРЛ&quot;;
    private static final Gson gson = new Gson();

    private String post(String url, LoginBody body) throws IOException {
        RequestBody requestBody = RequestBody.create(gson.toJson(body), JSON);
        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .build();
        try (Response response = client.newCall(request).execute()) {
            return response.body().string();
        }
    }

    @Test
    public void testSuccessfulLogin() throws IOException {
        LoginBody body = new LoginBody(&quot;m@m.ru&quot;, &quot;password&quot;);
        String response = post(URL, body);
        // Assert that the response contains a token
        assert(response.contains(&quot;token&quot;));
    }

    @Test
    public void testUnsuccessfulLogin() throws IOException {
        LoginBody body = new LoginBody(&quot;wrong@m.ru&quot;, &quot;wrongpassword&quot;);
        String response = post(URL, body);
        // Assert that the response contains an error message
        assertEquals(&quot;{\&quot;status\&quot;:401,\&quot;data\&quot;:{\&quot;email\&quot;:\&quot;donotoreply@.org\&quot;},\&quot;error\&quot;:2,\&quot;message\&quot;:\&quot;Wrong email or password\&quot;}&quot;, response);
    }

    @Getter
    @Setter
    @AllArgsConstructor
    static class LoginBody {
        private String email;
        private String password;
    }
}</pre>
  <h3 id="jxok">Девятый шаг:</h3>
  <p id="dWX2">Бля, забыли про респонс боди, вежливо просим поправить.</p>
  <blockquote id="H2Zy">Thank you. Now please make a response body as sepatate class</blockquote>
  <h3 id="4xKE">Десятый шаг:</h3>
  <p id="TAiO">Смотрим, вроде заебись</p>
  <pre id="ytQt" data-lang="java">import okhttp3.*;
import org.junit.jupiter.api.Test;
import com.google.gson.Gson;
import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import lombok.Getter;
import lombok.Setter;
import lombok.AllArgsConstructor;

public class LoginServiceTest {
    private static final MediaType JSON = MediaType.get(&quot;application/json; charset=utf-8&quot;);
    private static final OkHttpClient client = new OkHttpClient();
    private static final String URL = &quot;ИМАДЖИНИРУЙ ТУТ ЮРЛ&quot;;
    private static final Gson gson = new Gson();

    private ResponseBody post(String url, LoginBody body) throws IOException {
        RequestBody requestBody = RequestBody.create(gson.toJson(body), JSON);
        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .build();
        try (Response response = client.newCall(request).execute()) {
            return gson.fromJson(response.body().string(), ResponseBody.class);
        }
    }

    @Test
    public void testSuccessfulLogin() throws IOException {
        LoginBody body = new LoginBody(&quot;m@m.ru&quot;, &quot;password&quot;);
        ResponseBody response = post(URL, body);
        // Assert that the response contains a token
        assert(response.getToken() != null);
    }

    @Test
    public void testUnsuccessfulLogin() throws IOException {
        LoginBody body = new LoginBody(&quot;wrong@m.ru&quot;, &quot;wrongpassword&quot;);
        ResponseBody response = post(URL, body);
        // Assert that the response contains an error message
        assertEquals(&quot;Wrong email or password&quot;, response.getMessage());
    }

    @Getter
    @Setter
    @AllArgsConstructor
    static class LoginBody {
        private String email;
        private String password;
    }

    @Getter
    @Setter
    static class ResponseBody {
        private String token;
        private String refresh_token;
        private int status;
        private Data data;
        private int error;
        private String message;

        @Getter
        @Setter
        static class Data {
            private String email;
        }
    }
}</pre>
  <h3 id="pNXw">Одиннадцатый шаг:</h3>
  <p id="epQI">Так, ну ладно, пора поработать руками. Сразу видим какую-то залупу с респос боди, некрасиво, но нам похуй, работает же.<br /><br />Копируем весь код в IDEA, сразу видим что все красное и ничо не работает, нажимаем пару раз Cntrl+Enter, ага, неправильно библиотеки подтянули. Кликаем cntrl+enter пока большинство проблем не решится. Остальное правим руками.</p>
  <h3 id="afvi">Итого что вышло по коду:</h3>
  <pre id="0FRj" data-lang="java">package http;

import okhttp3.*;
import org.junit.Test;
import com.google.gson.Gson;
import java.io.IOException;

import static org.junit.Assert.assertEquals;
import lombok.Getter;
import lombok.Setter;
import lombok.AllArgsConstructor;

public class LoginServiceTest {
    private static final MediaType JSON = MediaType.get(&quot;application/json; charset=utf-8&quot;);
    private static final OkHttpClient client = new OkHttpClient();
    private static final String URL = &quot;ИМАДЖИНИРУЙ ТУТ ЮРЛ&quot;;
    private static final Gson gson = new Gson();

    private ResponseBody post(String url, LoginBody body) throws IOException {
        RequestBody requestBody = RequestBody.create(gson.toJson(body), JSON);
        Request request = new Request.Builder()
                .url(url)
                .post(requestBody)
                .build();
        try (Response response = client.newCall(request).execute()) {
            return gson.fromJson(response.body().string(), ResponseBody.class);
        }
    }

    @Test
    public void testSuccessfulLogin() throws IOException {
        LoginBody body = new LoginBody(&quot;m@m.ru&quot;, &quot;password&quot;);
        ResponseBody response = post(URL, body);
        // Assert that the response contains a token
        assert(response.getToken() != null);
    }

    @Test
    public void testUnsuccessfulLogin() throws IOException {
        LoginBody body = new LoginBody(&quot;wrong@m.ru&quot;, &quot;wrongpassword&quot;);
        ResponseBody response = post(URL, body);
        // Assert that the response contains an error message
        assertEquals(&quot;Wrong email or password&quot;, response.getMessage());
    }

    @Getter
    @Setter
    @AllArgsConstructor
    static class LoginBody {
        private String email;
        private String password;
    }

    @Getter
    @Setter
    static class ResponseBody {
        private String token;
        private String refresh_token;
        private int status;
        private Data data;
        private int error;
        private String message;

        @Getter
        @Setter
        static class Data {
            private String email;
        }
    }
}
</pre>

]]></content:encoded></item></channel></rss>