-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix File Upload * Use operations instead of operation * Fix tests
- Loading branch information
Showing
2 changed files
with
63 additions
and
10 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
60 changes: 60 additions & 0 deletions
60
server/src/test/kotlin/suwayomi/tachidesk/graphql/RequestParserTest.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,60 @@ | ||
package suwayomi.tachidesk.graphql | ||
|
||
import com.expediagroup.graphql.server.types.GraphQLRequest | ||
import io.javalin.http.Context | ||
import io.javalin.http.UploadedFile | ||
import io.javalin.plugin.json.JSON_MAPPER_KEY | ||
import io.javalin.plugin.json.JavalinJackson | ||
import io.javalin.plugin.json.JsonMapper | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.jupiter.api.Test | ||
import suwayomi.tachidesk.graphql.server.JavalinGraphQLRequestParser | ||
import java.io.ByteArrayInputStream | ||
import kotlin.test.assertIs | ||
import kotlin.test.assertNotNull | ||
|
||
class RequestParserTest { | ||
private val ctx = mockk<Context>(relaxed = true) | ||
private val requestParser = JavalinGraphQLRequestParser() | ||
|
||
@Test | ||
fun testZero() = runTest { | ||
every { ctx.appAttribute<JsonMapper>(JSON_MAPPER_KEY) } returns (JavalinJackson(JavalinJackson.defaultMapper())) | ||
every { ctx.formParam("operations") } returns """{ "query": "mutation (${'$'}file: Upload!) { singleUpload(file: ${'$'}file) { id } }", "variables": { "file": null } }""" | ||
every { ctx.formParam("map") } returns """{ "0": ["variables.file"] }""" | ||
every { ctx.uploadedFile("0") } returns UploadedFile(ByteArrayInputStream(byteArrayOf()), "", "", "", 0) | ||
val test = requestParser.parseRequest(ctx) | ||
assertIs<GraphQLRequest>(test) | ||
assertNotNull(test.variables?.get("file")) | ||
println("File: " + test.variables?.get("file")) | ||
} | ||
|
||
@Test | ||
fun testTest() = runTest { | ||
every { ctx.appAttribute<JsonMapper>(JSON_MAPPER_KEY) } returns (JavalinJackson(JavalinJackson.defaultMapper())) | ||
every { ctx.formParam("operations") } returns """{ "query": "mutation (${'$'}file: Upload!) { singleUpload(file: ${'$'}file) { id } }", "variables": { "file": null } }""" | ||
every { ctx.formParam("map") } returns """{ "test": ["variables.file"] }""" | ||
every { ctx.uploadedFile("test") } returns UploadedFile(ByteArrayInputStream(byteArrayOf()), "", "", "", 0) | ||
val test = requestParser.parseRequest(ctx) | ||
assertIs<GraphQLRequest>(test) | ||
assertNotNull(test.variables?.get("file")) | ||
println("File: " + test.variables?.get("file")) | ||
} | ||
|
||
@Test | ||
fun testList() = runTest { | ||
every { ctx.appAttribute<JsonMapper>(JSON_MAPPER_KEY) } returns (JavalinJackson(JavalinJackson.defaultMapper())) | ||
every { ctx.formParam("operations") } returns """{ "query": "mutation (${'$'}files: [Upload!]!) { singleUpload(files: ${'$'}files) { id } }", "variables": { "files": [null, null] } }""" | ||
every { ctx.formParam("map") } returns """{ "test": ["variables.files.0"], "test2": ["variables.files.1"] }""" | ||
every { ctx.uploadedFile("test") } returns UploadedFile(ByteArrayInputStream(byteArrayOf()), "", "", "", 0) | ||
every { ctx.uploadedFile("test2") } returns UploadedFile(ByteArrayInputStream(byteArrayOf()), "", "", "", 0) | ||
val test = requestParser.parseRequest(ctx) | ||
assertIs<GraphQLRequest>(test) | ||
val files = test.variables?.get("files") | ||
assertIs<List<*>>(files) | ||
assert(files.all { it is UploadedFile }) | ||
println("Files: $files") | ||
} | ||
} |