Skip to content
This repository has been archived by the owner on Nov 3, 2023. It is now read-only.

Commit

Permalink
fix: fix groupFileList error, fix #188, and add mockTests for groupFi…
Browse files Browse the repository at this point in the history
…leList
  • Loading branch information
Nambers committed Mar 4, 2023
1 parent 8e086f5 commit ac50361
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 19 deletions.
6 changes: 6 additions & 0 deletions cpp/mockTest/mockTestEntrance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ class Main : public CPPPlugin {
TEST(sendFile, sendFileTest, {
a.group.sendFile("/img/img.png", absolute(std::filesystem::path("./src/jvmTest/resources/img.png")).string());
})
TEST(groupFileListRoot, groupFileListRootTest, {
Logger::logger.info("fileList:", a.group.getFileListString("/"));
})
TEST(groupFileListFolder, groupFileListFolderTest, {
Logger::logger.info("fileList:", a.group.getFileListString("/a/"));
})
TEST_STARTWITH(remoteFileInfo, remoteFileInfoTest, {
Logger::logger.info("reId" + a.group.getFile("/mic.amr").id);
Logger::logger.info("reId" + a.group.getFileById(a.message[0]->content.substr(14)).id);
Expand Down
13 changes: 6 additions & 7 deletions kotlin/shared/src/commonMain/kotlin/PublicShared.kt
Original file line number Diff line number Diff line change
Expand Up @@ -496,13 +496,12 @@ object PublicShared {

private suspend fun remoteFileList(path: String, c: Packets.Contact): String = c.withBot { bot ->
c.withGroup(bot, "找不到对应群组,位置K-remoteFileInfo,gid:${c.id}") { group ->
var tmp = "["
group.files.root.resolveFiles(path).toList().forEach {
tmp += "[\"${it.absolutePath}\", \"${it.id}\"],"
}
tmp = tmp.substring(0, tmp.length - 1)
tmp += "]"
return tmp
return "[" +
(if (path == "/") group.files.root.files() else group.files.root.resolveFiles(path))
.toList().joinToString(",") {
"[\"${it.absolutePath}\", \"${it.id}\"]"
} +
"]"
}
}

Expand Down
77 changes: 65 additions & 12 deletions kotlin/shared/src/jvmTest/kotlin/events/OperationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ class OperationTest : TestBase() {
member.says("honorMember")
waitUntilEnd()
val logs = TestUtils.logList.filter { it.contains("honorMember:") }.map { it.substringAfter("honorMember:") }
assertEquals(1, logs.size)
assertEquals(member.id.toString(), logs[0])
assertContentEquals(listOf(member.id.toString()), logs)
}

@Test
Expand All @@ -67,11 +66,7 @@ class OperationTest : TestBase() {
member.says("botList")
waitUntilEnd()
val logs = TestUtils.logList.filter { it.contains("botList:") }.map { it.substringAfter("botList:") }
assertEquals(4, logs.size)
assertEquals(friend.id, logs[0].toLong())
assertEquals(group.id, logs[1].toLong())
assertEquals(member.id, logs[2].toLong())
assertEquals(bot.id, logs[3].toLong())
assertContentEquals(listOf(friend.id, group.id, member.id, bot.id), logs.map { it.toLong() })
}

@Test
Expand Down Expand Up @@ -104,9 +99,7 @@ class OperationTest : TestBase() {
}.map {
it.substringAfter("reId")
}
assertEquals(2, logs.size)
assertEquals(file.id, logs[0])
assertEquals(file.id, logs[1])
assertContentEquals(listOf(file.id, file.id), logs)
}

@Test
Expand Down Expand Up @@ -164,8 +157,7 @@ class OperationTest : TestBase() {
}.map {
it.substringAfter("reId")
}
assertEquals(1, logs.size)
assertEquals(group.owner.id.toString(), logs[0])
assertContentEquals(listOf(group.owner.id.toString()), logs)
}

@Test
Expand Down Expand Up @@ -265,4 +257,65 @@ class OperationTest : TestBase() {
waitUntilEnd()
assertEquals("test", member.specialTitle)
}

@Test
fun groupFileListRootEmpty() = runBlocking {
member.says("groupFileListRoot")
waitUntilEnd()
val logs = TestUtils.logList.filter {
it.contains("fileList:")
}.map {
it.substringAfter("fileList:")
}
assertContentEquals(listOf("[]"), logs)
}

@Test
fun groupFileListRoot() = runBlocking {
val file = this@OperationTest.javaClass.classLoader.getResourceAsStream("mic.amr")!!.use { res ->
res.toExternalResource().use {
group.files.root.uploadNewFile(
"/mic.amr",
it
)
}
}
member.says("groupFileListRoot")
waitUntilEnd()
val logs = TestUtils.logList.filter {
it.contains("fileList:")
}.map {
it.substringAfter("fileList:")
}
assertContentEquals(listOf("[[\"/mic.amr\", \"${file.id}\"]]"), logs)
}

@Test
fun groupFileListFolder() = runBlocking {
val file = this@OperationTest.javaClass.classLoader.getResourceAsStream("mic.amr")!!.use { res ->
res.toExternalResource().use {
listOf(
group.files.root.uploadNewFile(
"/a/mic.amr",
it
),
group.files.root.uploadNewFile(
"/a/micb.amr",
it
)
)
}
}
member.says("groupFileListFolder")
waitUntilEnd()
val logs = TestUtils.logList.filter {
it.contains("fileList:")
}.map {
it.substringAfter("fileList:")
}
assertContentEquals(
listOf("[[\"/a/mic.amr\", \"${file[0].id}\"], [\"/a/micb.amr\", \"${file[1].id}\"]]"),
logs
)
}
}

0 comments on commit ac50361

Please sign in to comment.