This commit is contained in:
commit
99d94c0d51
36 files changed
+4061
No files matched your search
@@ -0,0 +1,131 @@
|
||||
--[[--
|
||||
拷贝漫画数据映射用例。
|
||||
|
||||
@module tests.moonsource_copymanga.mapper_spec
|
||||
--]]
|
||||
---@diagnostic disable: undefined-field, missing-fields, redundant-parameter, missing-parameter, inject-field, assign-type-mismatch, param-type-mismatch, cast-type-mismatch, return-type-mismatch, cast-local-type
|
||||
|
||||
local Assert = require("support.assert")
|
||||
local Mapper = require("moonsource_copymanga.mapper")
|
||||
|
||||
do
|
||||
local book = Mapper.book({
|
||||
name = "测试漫画",
|
||||
path_word = "test-comic",
|
||||
cover = "https://img.example/cover.jpg",
|
||||
author = { { name = "作者甲" }, { name = "作者乙" } },
|
||||
})
|
||||
Assert.eq(book.source_id, "copymanga")
|
||||
Assert.eq(book.stable_id, "test-comic")
|
||||
Assert.eq(book.authors, "作者甲, 作者乙")
|
||||
Assert.is_nil(Mapper.book({ name = "没有 path_word" }))
|
||||
end
|
||||
|
||||
do
|
||||
local wire = {
|
||||
results = {
|
||||
comic = {
|
||||
uuid = "comic-uuid-1",
|
||||
name = "测试漫画",
|
||||
path_word = "test-comic",
|
||||
cover = "https://img.example/cover.jpg",
|
||||
author = { { name = "作者甲" } },
|
||||
theme = { { name = "冒險" } },
|
||||
brief = "第一行第二行",
|
||||
},
|
||||
},
|
||||
}
|
||||
Assert.eq(Mapper.comicId(wire), "comic-uuid-1")
|
||||
Assert.is_nil(Mapper.comicId({ results = { comic = { name = "无id" } } }))
|
||||
local book = Mapper.detail(wire)
|
||||
Assert.eq(book.stable_id, "test-comic")
|
||||
Assert.eq(book.title, "测试漫画")
|
||||
Assert.eq(book.authors, "作者甲")
|
||||
Assert.eq(book.category, "冒險")
|
||||
Assert.eq(book.intro, "第一行第二行")
|
||||
Assert.eq(book.cover, "https://img.example/cover.jpg")
|
||||
end
|
||||
|
||||
do
|
||||
local groups = Mapper.groups({
|
||||
results = {
|
||||
groups = {
|
||||
extra = { name = "番外", path_word = "extra" },
|
||||
default = { name = "默认", path_word = "default" },
|
||||
},
|
||||
},
|
||||
})
|
||||
Assert.len(groups, 2)
|
||||
Assert.eq(groups[1].path_word, "default")
|
||||
Assert.eq(groups[2].path_word, "extra")
|
||||
end
|
||||
|
||||
do
|
||||
local groups = Mapper.groups({ results = {} })
|
||||
Assert.len(groups, 1)
|
||||
Assert.eq(groups[1].path_word, "default")
|
||||
end
|
||||
|
||||
do
|
||||
local chapters = Mapper.chapters({
|
||||
{ uuid = "uuid-1", name = "第一話", group_path = "default", group_name = "默认" },
|
||||
{ uuid = "uuid-2", name = "第二話", group_path = "default", group_name = "默认" },
|
||||
{ uuid = "uuid-1", name = "第一話", group_path = "default", group_name = "默认" },
|
||||
{ uuid = "uuid-x", name = "番外1", group_path = "extra", group_name = "番外" },
|
||||
})
|
||||
Assert.len(chapters, 3)
|
||||
Assert.eq(chapters[1].idx, 1)
|
||||
Assert.eq(chapters[1].uid, "uuid-1")
|
||||
Assert.eq(chapters[2].title, "第二話")
|
||||
Assert.eq(chapters[3].title, "番外 · 番外1")
|
||||
end
|
||||
|
||||
do
|
||||
local books = Mapper.collect({
|
||||
{
|
||||
comic = {
|
||||
name = "收藏漫画",
|
||||
path_word = "fav-comic",
|
||||
cover = "https://img.example/fav.jpg",
|
||||
author = { { name = "作者丙" } },
|
||||
},
|
||||
},
|
||||
})
|
||||
Assert.len(books, 1)
|
||||
Assert.eq(books[1].stable_id, "fav-comic")
|
||||
Assert.eq(books[1].title, "收藏漫画")
|
||||
Assert.eq(books[1].authors, "作者丙")
|
||||
Assert.eq(books[1].deleted, 0)
|
||||
local invalid, err = Mapper.collect({ { comic = { name = "坏行" } } })
|
||||
Assert.is_nil(invalid)
|
||||
Assert.eq(err, "响应无效")
|
||||
end
|
||||
|
||||
do
|
||||
local pos, uid = Mapper.progress({
|
||||
results = {
|
||||
browse = {
|
||||
chapter_uuid = "chap-uuid-9",
|
||||
chapter_name = "第九话",
|
||||
},
|
||||
},
|
||||
})
|
||||
Assert.eq(uid, "chap-uuid-9")
|
||||
Assert.eq(pos.chapter_title, "第九话")
|
||||
Assert.eq(pos.fraction, 0)
|
||||
end
|
||||
|
||||
do
|
||||
local pos, uid = Mapper.progress({
|
||||
results = { browse = { chapter_id = "fallback-id" } },
|
||||
})
|
||||
Assert.eq(uid, "fallback-id")
|
||||
Assert.is_nil(pos.chapter_title)
|
||||
end
|
||||
|
||||
do
|
||||
Assert.is_nil(Mapper.progress({ results = { browse = nil } }))
|
||||
Assert.is_nil(Mapper.progress({ results = { browse = { chapter_name = "无id" } } }))
|
||||
Assert.is_nil(Mapper.progress({ results = {} }))
|
||||
Assert.is_nil(Mapper.progress(nil))
|
||||
end
|
||||
Reference in new issue
Block a user