|
| 1 | +/* |
| 2 | + * Copyright 2020 Expedia, Inc |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.expediagroup.graphql.generator.test.integration |
| 18 | + |
| 19 | +import com.expediagroup.graphql.generator.TopLevelObject |
| 20 | +import com.expediagroup.graphql.generator.internal.types.GenerateEnumTest |
| 21 | +import com.expediagroup.graphql.generator.testSchemaConfig |
| 22 | +import com.expediagroup.graphql.generator.toSchema |
| 23 | +import graphql.GraphQL |
| 24 | +import org.junit.jupiter.api.Test |
| 25 | +import kotlin.test.assertEquals |
| 26 | + |
| 27 | +@Suppress( |
| 28 | + "Detekt.UnusedPrivateMember", |
| 29 | +) |
| 30 | +class CustomEnumExecutionTest { |
| 31 | + |
| 32 | + private val schema = toSchema( |
| 33 | + queries = listOf(TopLevelObject(QueryObject())), |
| 34 | + config = testSchemaConfig() |
| 35 | + ) |
| 36 | + private val graphQL: GraphQL = GraphQL.newGraphQL(schema).build() |
| 37 | + |
| 38 | + @Test |
| 39 | + fun `a custom enum name can be used as output`() { |
| 40 | + val result = graphQL.execute("{ enumOutputs }") |
| 41 | + val data: Map<String, List<String>>? = result.getData() |
| 42 | + |
| 43 | + assertEquals(emptyList(), result.errors) |
| 44 | + assertEquals(listOf("ONE", "TWO", "THREE", "customFour"), data?.get("enumOutputs")) |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + fun `an implicit enum name be used as input`() { |
| 49 | + val result = graphQL.execute("{ enumInput(value: THREE) }") |
| 50 | + val data: Map<String, String>? = result.getData() |
| 51 | + |
| 52 | + assertEquals(emptyList(), result.errors) |
| 53 | + assertEquals("hello, THREE", data?.get("enumInput")) |
| 54 | + } |
| 55 | + |
| 56 | + @Test |
| 57 | + fun `a custom enum name be used as input`() { |
| 58 | + val result = graphQL.execute("{ enumInput(value: customFour) }") |
| 59 | + val data: Map<String, String>? = result.getData() |
| 60 | + |
| 61 | + assertEquals(emptyList(), result.errors) |
| 62 | + assertEquals("hello, FOUR", data?.get("enumInput")) |
| 63 | + } |
| 64 | + |
| 65 | + class QueryObject { |
| 66 | + fun enumOutputs(): List<GenerateEnumTest.MyTestEnum> = GenerateEnumTest.MyTestEnum.entries |
| 67 | + fun enumInput(value: GenerateEnumTest.MyTestEnum) = "hello, $value" |
| 68 | + } |
| 69 | +} |
0 commit comments