Skip to content

Commit 84c5e8f

Browse files
committed
add tests
1 parent 664e86c commit 84c5e8f

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

app/src/test/java/hexlet/code/AppTest.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,28 @@ public void testUrlPage() {
6262
}
6363

6464
@Test
65-
void testUrlNotFound() {
65+
public void testUrlNotFound() {
6666
JavalinTest.test(app, (server, client) -> {
67-
var response = client.get("/urls/1");
67+
var response = client.get(NamedRoutes.urlPath("1"));
6868
assertEquals(404, response.code());
6969
});
7070
}
71+
72+
@Test
73+
public void testSaveUrl() {
74+
var urlName = "https://one.com";
75+
76+
JavalinTest.test(app, (server, client) -> {
77+
var requestBody = "url=" + urlName;
78+
var postResponse = client.post(NamedRoutes.urlsPath(), requestBody);
79+
var url = UrlRepository.findByName(urlName);
80+
81+
assertEquals(urlName, url.get().getName());
82+
assertEquals(200, postResponse.code());
83+
assertTrue(postResponse.body().string().contains("Главная страница"));
84+
85+
var getResponse = client.get(NamedRoutes.urlsPath());
86+
assertTrue(getResponse.body().string().contains(urlName));
87+
});
88+
}
7189
}

0 commit comments

Comments
 (0)