mirror of
https://github.com/gotson/komga.git
synced 2025-12-06 08:32:25 +01:00
parent
4bab0c61c7
commit
b528b3d56d
4 changed files with 52 additions and 1 deletions
|
|
@ -26,3 +26,4 @@ ERR_1019 | Cannot import file that is part of an existing library
|
||||||
ERR_1020 | Book to upgrade does not belong to provided series
|
ERR_1020 | Book to upgrade does not belong to provided series
|
||||||
ERR_1021 | Destination file already exists
|
ERR_1021 | Destination file already exists
|
||||||
ERR_1022 | Newly imported book could not be scanned
|
ERR_1022 | Newly imported book could not be scanned
|
||||||
|
ERR_1023 | Book already present in ReadingList
|
||||||
|
|
|
||||||
|
|
@ -535,7 +535,8 @@
|
||||||
"ERR_1019": "Cannot import file that is part of an existing library",
|
"ERR_1019": "Cannot import file that is part of an existing library",
|
||||||
"ERR_1020": "Book to upgrade does not belong to provided series",
|
"ERR_1020": "Book to upgrade does not belong to provided series",
|
||||||
"ERR_1021": "Destination file already exists",
|
"ERR_1021": "Destination file already exists",
|
||||||
"ERR_1022": "Newly imported book could not be scanned"
|
"ERR_1022": "Newly imported book could not be scanned",
|
||||||
|
"ERR_1023": "Book already present in ReadingList"
|
||||||
},
|
},
|
||||||
"filter": {
|
"filter": {
|
||||||
"age_rating": "age rating",
|
"age_rating": "age rating",
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ class ReadListMatcher(
|
||||||
when {
|
when {
|
||||||
bookMatches.size > 1 -> unmatchedBooks += ReadListRequestResultBook(book, "ERR_1013")
|
bookMatches.size > 1 -> unmatchedBooks += ReadListRequestResultBook(book, "ERR_1013")
|
||||||
bookMatches.isEmpty() -> unmatchedBooks += ReadListRequestResultBook(book, "ERR_1014")
|
bookMatches.isEmpty() -> unmatchedBooks += ReadListRequestResultBook(book, "ERR_1014")
|
||||||
|
bookIds.contains(bookMatches.first()) -> unmatchedBooks += ReadListRequestResultBook(book, "ERR_1023")
|
||||||
else -> bookIds.add(bookMatches.first())
|
else -> bookIds.add(bookMatches.first())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -220,4 +220,52 @@ class ReadListMatcherTest(
|
||||||
assertThat(unmatchedBooks[3].errorCode).isEqualTo("ERR_1013")
|
assertThat(unmatchedBooks[3].errorCode).isEqualTo("ERR_1013")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given request with duplicate books when matching then returns result with appropriate error codes`() {
|
||||||
|
// given
|
||||||
|
val booksSeries1 = listOf(
|
||||||
|
makeBook("book1", libraryId = library.id),
|
||||||
|
makeBook("book2", libraryId = library.id),
|
||||||
|
)
|
||||||
|
makeSeries(name = "batman", libraryId = library.id).let { s ->
|
||||||
|
seriesLifecycle.createSeries(s)
|
||||||
|
seriesLifecycle.addBooks(s, booksSeries1)
|
||||||
|
seriesLifecycle.sortBooks(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
val request = ReadListRequest(
|
||||||
|
name = "readlist",
|
||||||
|
books = listOf(
|
||||||
|
ReadListRequestBook(series = "batman", number = "1"),
|
||||||
|
ReadListRequestBook(series = "batman", number = "2"),
|
||||||
|
ReadListRequestBook(series = "batman", number = "2"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
// when
|
||||||
|
val result = readListMatcher.matchReadListRequest(request)
|
||||||
|
|
||||||
|
// then
|
||||||
|
with(result) {
|
||||||
|
assertThat(readList).isNotNull
|
||||||
|
with(readList!!) {
|
||||||
|
assertThat(name).isEqualTo(request.name)
|
||||||
|
assertThat(bookIds).hasSize(2)
|
||||||
|
assertThat(bookIds).containsExactlyEntriesOf(
|
||||||
|
mapOf(
|
||||||
|
0 to booksSeries1[0].id,
|
||||||
|
1 to booksSeries1[1].id,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
assertThat(errorCode).isBlank
|
||||||
|
|
||||||
|
assertThat(unmatchedBooks).hasSize(1)
|
||||||
|
|
||||||
|
assertThat(unmatchedBooks[0].book).isEqualTo(request.books[2])
|
||||||
|
assertThat(unmatchedBooks[0].errorCode).isEqualTo("ERR_1023")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue