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;
|
||||
|
||||
import com.discdrop.db.DatabaseService;
|
||||
import com.discdrop.db.Record.TrackedArtist;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.http.ContentType;
|
||||
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.hamcrest.Matchers.*;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@QuarkusTest
|
||||
class ArtistControllerTest {
|
||||
@@ -25,102 +29,123 @@ class ArtistControllerTest {
|
||||
|
||||
@Test
|
||||
void testSearchEndpointEmpty() {
|
||||
given()
|
||||
.queryParam("q", "")
|
||||
.when().get("/api/artists/search")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("No artists found"));
|
||||
given().queryParam("q", "").get("/api/artists/search")
|
||||
.then().statusCode(200).body(containsString("No artists found"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testArtistListEndpoint() {
|
||||
given()
|
||||
.when().get("/api/artists/list")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("artist-list"));
|
||||
given().get("/api/artists/list")
|
||||
.then().statusCode(200).body(containsString("artist-list"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSettingsForm() {
|
||||
given()
|
||||
.when().get("/api/settings/form")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("cache_ttl_hours"));
|
||||
given().get("/api/settings/form")
|
||||
.then().statusCode(200).body(containsString("cache_ttl_hours"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSaveSettings() {
|
||||
given()
|
||||
.formParam("cache_ttl_hours", "12")
|
||||
.formParam("default_types", "Album", "Single")
|
||||
.when().patch("/api/settings")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("Settings saved"));
|
||||
given().formParam("cache_ttl_hours", "12").formParam("default_types", "Album", "Single")
|
||||
.patch("/api/settings").then().statusCode(200).body(containsString("Settings saved"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSaveSettingsInvalidTtl() {
|
||||
given()
|
||||
.formParam("cache_ttl_hours", "invalid")
|
||||
.formParam("default_types", "Album")
|
||||
.when().patch("/api/settings")
|
||||
.then()
|
||||
.statusCode(400);
|
||||
given().formParam("cache_ttl_hours", "invalid").formParam("default_types", "Album")
|
||||
.patch("/api/settings").then().statusCode(400);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFeedTableEndpoint() {
|
||||
given()
|
||||
.when().get("/api/artists/feed-table")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
given().get("/api/artists/feed-table").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFeedTableWithPage() {
|
||||
given()
|
||||
.queryParam("page", "1")
|
||||
.when().get("/api/artists/feed-table")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
given().queryParam("page", "1").get("/api/artists/feed-table").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testReleasesPage() {
|
||||
given()
|
||||
.when().get("/")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(containsString("DiscDrop"));
|
||||
given().get("/").then().statusCode(200).body(containsString("DiscDrop"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testArtistsPage() {
|
||||
given()
|
||||
.when().get("/artists")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
given().get("/artists").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRssFeed() {
|
||||
given()
|
||||
.when().get("/feed/rss.xml")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType(ContentType.XML);
|
||||
given().get("/feed/rss.xml").then().statusCode(200).contentType(ContentType.XML);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testOpml() {
|
||||
given()
|
||||
.when().get("/feed/opml")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.contentType(ContentType.XML);
|
||||
given().get("/feed/opml").then().statusCode(200).contentType(ContentType.XML);
|
||||
}
|
||||
|
||||
@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);
|
||||
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