This commit is contained in:
@@ -1,103 +0,0 @@
|
|||||||
package com.discdrop;
|
|
||||||
|
|
||||||
import com.discdrop.db.DatabaseService;
|
|
||||||
import com.discdrop.db.Record.TrackedArtist;
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
|
||||||
import jakarta.inject.Inject;
|
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
|
|
||||||
import static io.restassured.RestAssured.given;
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
@QuarkusTest
|
|
||||||
class ArtistControllerExtendedTest {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
DatabaseService db;
|
|
||||||
|
|
||||||
@BeforeEach
|
|
||||||
void cleanUp() {
|
|
||||||
for (var a : db.findAllArtists()) {
|
|
||||||
db.deleteArtistCascading(a.mbid());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testDeleteArtist() {
|
|
||||||
db.insertArtist(new TrackedArtist("del-1", "Delete", "", "",
|
|
||||||
true, false, false, false, false, Instant.now(), Instant.now()));
|
|
||||||
given().delete("/api/artists/del-1").then().statusCode(200);
|
|
||||||
assertFalse(db.exists("del-1"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testDeleteArtistFromSearch() {
|
|
||||||
db.insertArtist(new TrackedArtist("del-src", "SearchDel", "", "",
|
|
||||||
true, false, false, false, false, Instant.now(), Instant.now()));
|
|
||||||
given()
|
|
||||||
.queryParam("q", "")
|
|
||||||
.delete("/api/artists/del-src/from-search")
|
|
||||||
.then().statusCode(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testMonitoringToggleSingle() {
|
|
||||||
db.insertArtist(new TrackedArtist("mon-ts", "ToggleS", "", "",
|
|
||||||
true, false, false, false, false, Instant.now(), Instant.now()));
|
|
||||||
given().queryParam("type", "single").patch("/api/artists/mon-ts/monitor").then().statusCode(200);
|
|
||||||
var artist = db.findByMbid("mon-ts").orElseThrow();
|
|
||||||
assertTrue(artist.singleMonitored());
|
|
||||||
assertTrue(artist.albumMonitored());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testMonitoringToggleAlbum() {
|
|
||||||
db.insertArtist(new TrackedArtist("mon-ta", "ToggleA", "", "",
|
|
||||||
true, false, false, false, false, Instant.now(), Instant.now()));
|
|
||||||
given().queryParam("type", "album").patch("/api/artists/mon-ta/monitor").then().statusCode(200);
|
|
||||||
var artist = db.findByMbid("mon-ta").orElseThrow();
|
|
||||||
assertFalse(artist.albumMonitored());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testMonitoringNonexistent() {
|
|
||||||
given().queryParam("type", "album").patch("/api/artists/no-such/monitor").then().statusCode(404);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testMonitoringMissingType() {
|
|
||||||
db.insertArtist(new TrackedArtist("mon-mt", "MissType", "", "",
|
|
||||||
true, false, false, false, false, Instant.now(), Instant.now()));
|
|
||||||
given().patch("/api/artists/mon-mt/monitor").then().statusCode(400);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testTrackArtist() {
|
|
||||||
given()
|
|
||||||
.when().post("/api/artists/mock-mbid-1/track")
|
|
||||||
.then().statusCode(200);
|
|
||||||
|
|
||||||
assertTrue(db.exists("mock-mbid-1"));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testTrackArtistUpdatesFeed() {
|
|
||||||
given().post("/api/artists/mock-mbid-1/track").then().statusCode(200);
|
|
||||||
given().get("/api/artists/feed-table").then().statusCode(200);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void testDeleteTrackedArtistFromSearch() {
|
|
||||||
given().post("/api/artists/mock-mbid-1/track").then().statusCode(200);
|
|
||||||
|
|
||||||
given()
|
|
||||||
.queryParam("q", "Mock")
|
|
||||||
.delete("/api/artists/mock-mbid-1/from-search")
|
|
||||||
.then().statusCode(200);
|
|
||||||
|
|
||||||
assertFalse(db.exists("mock-mbid-1"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +1,18 @@
|
|||||||
package com.discdrop;
|
package com.discdrop;
|
||||||
|
|
||||||
import com.discdrop.db.DatabaseService;
|
import com.discdrop.db.DatabaseService;
|
||||||
|
import com.discdrop.db.Record.TrackedArtist;
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
import io.restassured.http.ContentType;
|
import io.restassured.http.ContentType;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
import static io.restassured.RestAssured.given;
|
import static io.restassured.RestAssured.given;
|
||||||
import static org.hamcrest.Matchers.*;
|
import static org.hamcrest.Matchers.*;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
@QuarkusTest
|
@QuarkusTest
|
||||||
class ArtistControllerTest {
|
class ArtistControllerTest {
|
||||||
@@ -25,102 +29,123 @@ class ArtistControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSearchEndpointEmpty() {
|
void testSearchEndpointEmpty() {
|
||||||
given()
|
given().queryParam("q", "").get("/api/artists/search")
|
||||||
.queryParam("q", "")
|
.then().statusCode(200).body(containsString("No artists found"));
|
||||||
.when().get("/api/artists/search")
|
|
||||||
.then()
|
|
||||||
.statusCode(200)
|
|
||||||
.body(containsString("No artists found"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testArtistListEndpoint() {
|
void testArtistListEndpoint() {
|
||||||
given()
|
given().get("/api/artists/list")
|
||||||
.when().get("/api/artists/list")
|
.then().statusCode(200).body(containsString("artist-list"));
|
||||||
.then()
|
|
||||||
.statusCode(200)
|
|
||||||
.body(containsString("artist-list"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSettingsForm() {
|
void testSettingsForm() {
|
||||||
given()
|
given().get("/api/settings/form")
|
||||||
.when().get("/api/settings/form")
|
.then().statusCode(200).body(containsString("cache_ttl_hours"));
|
||||||
.then()
|
|
||||||
.statusCode(200)
|
|
||||||
.body(containsString("cache_ttl_hours"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSaveSettings() {
|
void testSaveSettings() {
|
||||||
given()
|
given().formParam("cache_ttl_hours", "12").formParam("default_types", "Album", "Single")
|
||||||
.formParam("cache_ttl_hours", "12")
|
.patch("/api/settings").then().statusCode(200).body(containsString("Settings saved"));
|
||||||
.formParam("default_types", "Album", "Single")
|
|
||||||
.when().patch("/api/settings")
|
|
||||||
.then()
|
|
||||||
.statusCode(200)
|
|
||||||
.body(containsString("Settings saved"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testSaveSettingsInvalidTtl() {
|
void testSaveSettingsInvalidTtl() {
|
||||||
given()
|
given().formParam("cache_ttl_hours", "invalid").formParam("default_types", "Album")
|
||||||
.formParam("cache_ttl_hours", "invalid")
|
.patch("/api/settings").then().statusCode(400);
|
||||||
.formParam("default_types", "Album")
|
|
||||||
.when().patch("/api/settings")
|
|
||||||
.then()
|
|
||||||
.statusCode(400);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFeedTableEndpoint() {
|
void testFeedTableEndpoint() {
|
||||||
given()
|
given().get("/api/artists/feed-table").then().statusCode(200);
|
||||||
.when().get("/api/artists/feed-table")
|
|
||||||
.then()
|
|
||||||
.statusCode(200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testFeedTableWithPage() {
|
void testFeedTableWithPage() {
|
||||||
given()
|
given().queryParam("page", "1").get("/api/artists/feed-table").then().statusCode(200);
|
||||||
.queryParam("page", "1")
|
|
||||||
.when().get("/api/artists/feed-table")
|
|
||||||
.then()
|
|
||||||
.statusCode(200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testReleasesPage() {
|
void testReleasesPage() {
|
||||||
given()
|
given().get("/").then().statusCode(200).body(containsString("DiscDrop"));
|
||||||
.when().get("/")
|
|
||||||
.then()
|
|
||||||
.statusCode(200)
|
|
||||||
.body(containsString("DiscDrop"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testArtistsPage() {
|
void testArtistsPage() {
|
||||||
given()
|
given().get("/artists").then().statusCode(200);
|
||||||
.when().get("/artists")
|
|
||||||
.then()
|
|
||||||
.statusCode(200);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testRssFeed() {
|
void testRssFeed() {
|
||||||
given()
|
given().get("/feed/rss.xml").then().statusCode(200).contentType(ContentType.XML);
|
||||||
.when().get("/feed/rss.xml")
|
|
||||||
.then()
|
|
||||||
.statusCode(200)
|
|
||||||
.contentType(ContentType.XML);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testOpml() {
|
void testOpml() {
|
||||||
given()
|
given().get("/feed/opml").then().statusCode(200).contentType(ContentType.XML);
|
||||||
.when().get("/feed/opml")
|
}
|
||||||
.then()
|
|
||||||
.statusCode(200)
|
@Test
|
||||||
.contentType(ContentType.XML);
|
void testDeleteArtist() {
|
||||||
|
db.insertArtist(new TrackedArtist("del-1", "Delete", "", "",
|
||||||
|
true, false, false, false, false, Instant.now(), Instant.now()));
|
||||||
|
given().delete("/api/artists/del-1").then().statusCode(200);
|
||||||
|
assertFalse(db.exists("del-1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testDeleteArtistFromSearch() {
|
||||||
|
db.insertArtist(new TrackedArtist("del-src", "SearchDel", "", "",
|
||||||
|
true, false, false, false, false, Instant.now(), Instant.now()));
|
||||||
|
given().queryParam("q", "").delete("/api/artists/del-src/from-search").then().statusCode(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testMonitoringToggleSingle() {
|
||||||
|
db.insertArtist(new TrackedArtist("mon-ts", "ToggleS", "", "",
|
||||||
|
true, false, false, false, false, Instant.now(), Instant.now()));
|
||||||
|
given().queryParam("type", "single").patch("/api/artists/mon-ts/monitor").then().statusCode(200);
|
||||||
|
assertTrue(db.findByMbid("mon-ts").orElseThrow().singleMonitored());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testMonitoringToggleAlbum() {
|
||||||
|
db.insertArtist(new TrackedArtist("mon-ta", "ToggleA", "", "",
|
||||||
|
true, false, false, false, false, Instant.now(), Instant.now()));
|
||||||
|
given().queryParam("type", "album").patch("/api/artists/mon-ta/monitor").then().statusCode(200);
|
||||||
|
assertFalse(db.findByMbid("mon-ta").orElseThrow().albumMonitored());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testMonitoringNonexistent() {
|
||||||
|
given().queryParam("type", "album").patch("/api/artists/no-such/monitor").then().statusCode(404);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testMonitoringMissingType() {
|
||||||
|
db.insertArtist(new TrackedArtist("mon-mt", "MissType", "", "",
|
||||||
|
true, false, false, false, false, Instant.now(), Instant.now()));
|
||||||
|
given().patch("/api/artists/mon-mt/monitor").then().statusCode(400);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testTrackArtist() {
|
||||||
|
given().post("/api/artists/mock-mbid-1/track").then().statusCode(200);
|
||||||
|
assertTrue(db.exists("mock-mbid-1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testTrackArtistAndVerifyFeed() {
|
||||||
|
given().post("/api/artists/mock-mbid-1/track").then().statusCode(200);
|
||||||
|
given().get("/api/artists/feed-table").then().statusCode(200);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testDeleteTrackedArtistFromSearch() {
|
||||||
|
given().post("/api/artists/mock-mbid-1/track").then().statusCode(200);
|
||||||
|
given().queryParam("q", "Mock").delete("/api/artists/mock-mbid-1/from-search").then().statusCode(200);
|
||||||
|
assertFalse(db.exists("mock-mbid-1"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user