mirror of
https://github.com/Athou/commafeed.git
synced 2026-11-02 02:14:47 +00:00
refactor
This commit is contained in:
@@ -39,6 +39,7 @@ public abstract class BaseIT {
|
||||
|
||||
private static final HttpRequest FEED_REQUEST = HttpRequest.request().withMethod("GET").withPath("/");
|
||||
|
||||
@Getter
|
||||
private MockServerClient mockServerClient;
|
||||
private Client client;
|
||||
private String feedUrl;
|
||||
@@ -122,10 +123,15 @@ public abstract class BaseIT {
|
||||
}
|
||||
|
||||
protected Long subscribe(String feedUrl, String categoryId) {
|
||||
return subscribe(feedUrl, categoryId, false);
|
||||
}
|
||||
|
||||
protected Long subscribe(String feedUrl, String categoryId, boolean pushNotificationsEnabled) {
|
||||
SubscribeRequest subscribeRequest = new SubscribeRequest();
|
||||
subscribeRequest.setUrl(feedUrl);
|
||||
subscribeRequest.setTitle("my title for this feed");
|
||||
subscribeRequest.setCategoryId(categoryId);
|
||||
subscribeRequest.setPushNotificationsEnabled(pushNotificationsEnabled);
|
||||
return RestAssured.given()
|
||||
.body(subscribeRequest)
|
||||
.contentType(ContentType.JSON)
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package com.commafeed.integration;
|
||||
|
||||
import java.time.Duration;
|
||||
|
||||
import org.awaitility.Awaitility;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockserver.model.HttpRequest;
|
||||
import org.mockserver.model.HttpResponse;
|
||||
import org.mockserver.verify.VerificationTimes;
|
||||
|
||||
import com.commafeed.TestConstants;
|
||||
import com.commafeed.backend.model.UserSettings.PushNotificationType;
|
||||
import com.commafeed.frontend.model.Settings;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.RestAssured;
|
||||
import io.restassured.http.ContentType;
|
||||
|
||||
@QuarkusTest
|
||||
class PushNotificationIT extends BaseIT {
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
initialSetup(TestConstants.ADMIN_USERNAME, TestConstants.ADMIN_PASSWORD);
|
||||
RestAssured.authentication = RestAssured.preemptive().basic(TestConstants.ADMIN_USERNAME, TestConstants.ADMIN_PASSWORD);
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
RestAssured.reset();
|
||||
}
|
||||
|
||||
@Test
|
||||
void receivedPushNotifications() {
|
||||
// mock ntfy server
|
||||
HttpRequest ntfyPost = HttpRequest.request().withMethod("POST").withPath("/ntfy/integration-test");
|
||||
getMockServerClient().when(ntfyPost).respond(HttpResponse.response().withStatusCode(200));
|
||||
|
||||
// enable push notifications
|
||||
Settings settings = RestAssured.given().get("rest/user/settings").then().extract().as(Settings.class);
|
||||
settings.getPushNotificationSettings().setType(PushNotificationType.NTFY);
|
||||
settings.getPushNotificationSettings().setServerUrl("http://localhost:" + getMockServerClient().getPort() + "/ntfy");
|
||||
settings.getPushNotificationSettings().setTopic("integration-test");
|
||||
RestAssured.given().body(settings).contentType(ContentType.JSON).post("rest/user/settings").then().statusCode(200);
|
||||
|
||||
// subscribe with push notifications enabled
|
||||
subscribe(getFeedUrl(), null, true);
|
||||
|
||||
// await push notification for the two entries in the feed
|
||||
Awaitility.await()
|
||||
.atMost(Duration.ofSeconds(20))
|
||||
.untilAsserted(() -> getMockServerClient().verify(ntfyPost, VerificationTimes.exactly(2)));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,6 +23,7 @@ class ServerIT extends BaseIT {
|
||||
Assertions.assertEquals(30000, serverInfos.getTreeReloadInterval());
|
||||
Assertions.assertEquals(60000, serverInfos.getForceRefreshCooldownDuration());
|
||||
Assertions.assertEquals(4, serverInfos.getMinimumPasswordLength());
|
||||
Assertions.assertTrue(serverInfos.isPushNotificationsEnabled());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user