-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0b85a42
commit 85ce507
Showing
5 changed files
with
89 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
simbot-component-qq-guild-api/src/commonTest/kotlin/ApiResultSerializationCheckTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package test | ||
|
||
import io.ktor.client.* | ||
import io.ktor.client.engine.mock.* | ||
import io.ktor.client.statement.* | ||
import io.ktor.http.* | ||
import io.ktor.utils.io.* | ||
import kotlinx.coroutines.test.runTest | ||
import kotlinx.serialization.SerializationException | ||
import love.forte.simbot.qguild.QQGuild | ||
import love.forte.simbot.qguild.QQGuildResultSerializationException | ||
import love.forte.simbot.qguild.api.GatewayApis | ||
import love.forte.simbot.qguild.api.channel.GetChannelApi | ||
import love.forte.simbot.qguild.api.checkStatus | ||
import love.forte.simbot.qguild.api.request | ||
import love.forte.simbot.qguild.api.requestData | ||
import kotlin.test.Test | ||
import kotlin.test.assertFails | ||
import kotlin.test.assertIs | ||
|
||
|
||
/** | ||
* | ||
* @author ForteScarlet | ||
*/ | ||
class ApiResultSerializationCheckTests { | ||
|
||
@Test | ||
fun statusDeserializationHtmlBadResultTest() = runTest { | ||
val client = HttpClient( | ||
MockEngine.invoke { // request -> | ||
respond( | ||
content = ByteReadChannel("""<html></html>"""), | ||
status = HttpStatusCode.BadRequest, | ||
// headers = headersOf(HttpHeaders.ContentType, "application/json") | ||
) | ||
}) { | ||
|
||
} | ||
|
||
val resp = GatewayApis.Normal.request(client, "test") | ||
val ex = assertFails { checkStatus(resp.bodyAsText(), QQGuild.DefaultJson, resp.status, resp) } | ||
assertIs<QQGuildResultSerializationException>(ex) | ||
assertIs<SerializationException>(ex.cause ?: ex.suppressedExceptions.firstOrNull()) | ||
} | ||
|
||
@Test | ||
fun statusDeserializationHtmlOKResultTest() = runTest { | ||
val client = HttpClient( | ||
MockEngine.invoke { // request -> | ||
respond( | ||
content = ByteReadChannel("""<html></html>"""), | ||
status = HttpStatusCode.OK, | ||
) | ||
}) { | ||
|
||
} | ||
|
||
val ex = assertFails { GetChannelApi.create("test").requestData(client, "test") } | ||
assertIs<QQGuildResultSerializationException>(ex) | ||
assertIs<SerializationException>(ex.cause ?: ex.suppressedExceptions.firstOrNull()) | ||
} | ||
|
||
} |