add category integration tests

This commit is contained in:
Athou
2025-07-20 22:47:34 +02:00
parent 18084995b2
commit 427e020d27
2 changed files with 155 additions and 1 deletions

View File

@@ -22,8 +22,10 @@ import org.mockserver.integration.ClientAndServer;
import org.mockserver.model.HttpRequest;
import org.mockserver.model.HttpResponse;
import com.commafeed.frontend.model.Category;
import com.commafeed.frontend.model.Entries;
import com.commafeed.frontend.model.Subscription;
import com.commafeed.frontend.model.request.AddCategoryRequest;
import com.commafeed.frontend.model.request.SubscribeRequest;
import io.restassured.RestAssured;
@@ -88,10 +90,31 @@ public abstract class BaseIT {
return setCookieHeaders.stream().flatMap(h -> HttpCookie.parse(h.getValue()).stream()).toList();
}
protected String createCategory(String name) {
AddCategoryRequest addCategoryRequest = new AddCategoryRequest();
addCategoryRequest.setName(name);
return RestAssured.given()
.body(addCategoryRequest)
.contentType(MediaType.APPLICATION_JSON)
.post("rest/category/add")
.then()
.extract()
.as(String.class);
}
protected Category getRootCategory() {
return RestAssured.given().get("rest/category/get").then().statusCode(HttpStatus.SC_OK).extract().as(Category.class);
}
protected Long subscribe(String feedUrl) {
return subscribe(feedUrl, null);
}
protected Long subscribe(String feedUrl, String categoryId) {
SubscribeRequest subscribeRequest = new SubscribeRequest();
subscribeRequest.setUrl(feedUrl);
subscribeRequest.setTitle("my title for this feed");
subscribeRequest.setCategoryId(categoryId);
return RestAssured.given()
.body(subscribeRequest)
.contentType(MediaType.APPLICATION_JSON)
@@ -103,7 +126,11 @@ public abstract class BaseIT {
}
protected Long subscribeAndWaitForEntries(String feedUrl) {
Long subscriptionId = subscribe(feedUrl);
return subscribeAndWaitForEntries(feedUrl, null);
}
protected Long subscribeAndWaitForEntries(String feedUrl, String categoryId) {
Long subscriptionId = subscribe(feedUrl, categoryId);
Awaitility.await().atMost(Duration.ofSeconds(15)).until(() -> getFeedEntries(subscriptionId), e -> e.getEntries().size() == 2);
return subscriptionId;
}
@@ -126,6 +153,15 @@ public abstract class BaseIT {
.as(Entries.class);
}
protected Entries getCategoryEntries(String categoryId) {
return RestAssured.given()
.get("rest/category/entries?id={id}&readType=all", categoryId)
.then()
.statusCode(HttpStatus.SC_OK)
.extract()
.as(Entries.class);
}
protected int forceRefreshAllFeeds() {
return RestAssured.given().get("rest/feed/refreshAll").then().extract().statusCode();
}

View File

@@ -0,0 +1,118 @@
package com.commafeed.integration.rest;
import jakarta.ws.rs.core.MediaType;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import com.commafeed.frontend.model.Category;
import com.commafeed.frontend.model.Entries;
import com.commafeed.frontend.model.Entry;
import com.commafeed.frontend.model.request.CategoryModificationRequest;
import com.commafeed.frontend.model.request.CollapseRequest;
import com.commafeed.frontend.model.request.IDRequest;
import com.commafeed.frontend.model.request.StarRequest;
import com.commafeed.frontend.resource.CategoryREST;
import com.commafeed.integration.BaseIT;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
@QuarkusTest
class CategoryIT extends BaseIT {
@BeforeEach
void setup() {
RestAssured.authentication = RestAssured.preemptive().basic("admin", "admin");
}
@AfterEach
void cleanup() {
RestAssured.reset();
}
@Test
void modifyCategory() {
String category1Id = createCategory("test-category-1");
String category2Id = createCategory("test-category-2");
CategoryModificationRequest request = new CategoryModificationRequest();
request.setId(Long.valueOf(category2Id));
request.setName("modified-category");
request.setParentId(category1Id);
RestAssured.given().body(request).contentType(MediaType.APPLICATION_JSON).post("rest/category/modify").then().statusCode(200);
Category root = getRootCategory();
Assertions.assertEquals(1, root.getChildren().size());
Assertions.assertEquals("test-category-1", root.getChildren().get(0).getName());
Assertions.assertEquals(1, root.getChildren().get(0).getChildren().size());
Assertions.assertEquals("modified-category", root.getChildren().get(0).getChildren().get(0).getName());
}
@Test
void collapseCategory() {
String categoryId = createCategory("test-category");
Category root = getRootCategory();
Assertions.assertEquals(1, root.getChildren().size());
Assertions.assertTrue(root.getChildren().get(0).isExpanded());
CollapseRequest request = new CollapseRequest();
request.setId(Long.valueOf(categoryId));
request.setCollapse(true);
RestAssured.given().body(request).contentType(MediaType.APPLICATION_JSON).post("rest/category/collapse").then().statusCode(200);
root = getRootCategory();
Assertions.assertEquals(1, root.getChildren().size());
Assertions.assertFalse(root.getChildren().get(0).isExpanded());
}
@Test
void deleteCategory() {
String categoryId = createCategory("test-category");
Assertions.assertEquals(1, getRootCategory().getChildren().size());
IDRequest request = new IDRequest();
request.setId(Long.valueOf(categoryId));
RestAssured.given().body(request).contentType(MediaType.APPLICATION_JSON).post("rest/category/delete").then().statusCode(200);
Assertions.assertEquals(0, getRootCategory().getChildren().size());
}
@Nested
class GetEntries {
@Test
void all() {
subscribeAndWaitForEntries(getFeedUrl());
Entries entries = getCategoryEntries(CategoryREST.ALL);
Assertions.assertEquals(2, entries.getEntries().size());
}
@Test
void starred() {
Long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
Assertions.assertEquals(0, getCategoryEntries(CategoryREST.STARRED).getEntries().size());
Entry entry = getFeedEntries(subscriptionId).getEntries().get(0);
StarRequest starRequest = new StarRequest();
starRequest.setId(entry.getId());
starRequest.setFeedId(subscriptionId);
starRequest.setStarred(true);
RestAssured.given().body(starRequest).contentType(MediaType.APPLICATION_JSON).post("rest/entry/star");
Entries starredEntries = getCategoryEntries(CategoryREST.STARRED);
Assertions.assertEquals(1, starredEntries.getEntries().size());
Assertions.assertEquals(entry.getId(), starredEntries.getEntries().get(0).getId());
}
@Test
void specificCategory() {
String categoryId = createCategory("test-category");
subscribeAndWaitForEntries(getFeedUrl(), categoryId);
Entries entries = getCategoryEntries(categoryId);
Assertions.assertEquals(2, entries.getEntries().size());
}
}
}