|
| 1 | +package graphql.scalars.id |
| 2 | + |
| 3 | +import graphql.language.StringValue |
| 4 | +import graphql.scalars.ExtendedScalars |
| 5 | +import graphql.schema.CoercingParseLiteralException |
| 6 | +import graphql.schema.CoercingParseValueException |
| 7 | +import graphql.schema.CoercingSerializeException |
| 8 | +import spock.lang.Specification |
| 9 | +import spock.lang.Unroll |
| 10 | + |
| 11 | +import static graphql.scalars.util.TestKit.mkStringValue |
| 12 | +import static graphql.scalars.util.TestKit.mkUUIDValue |
| 13 | + |
| 14 | +class UUIDScalarTest extends Specification { |
| 15 | + |
| 16 | + def coercing = ExtendedScalars.UUID.getCoercing() |
| 17 | + |
| 18 | + @Unroll |
| 19 | + def "UUID parseValue"() { |
| 20 | + |
| 21 | + when: |
| 22 | + def result = coercing.parseValue(input) |
| 23 | + then: |
| 24 | + result == expectedValue |
| 25 | + where: |
| 26 | + input | expectedValue |
| 27 | + "43f20307-603c-4ad1-83c6-6010d224fabf" | mkUUIDValue("43f20307-603c-4ad1-83c6-6010d224fabf") |
| 28 | + "787dbc2b-3ddb-4098-ad1d-63d026bac111" | mkUUIDValue("787dbc2b-3ddb-4098-ad1d-63d026bac111") |
| 29 | + } |
| 30 | + |
| 31 | + @Unroll |
| 32 | + def "UUID parseValue bad inputs"() { |
| 33 | + |
| 34 | + when: |
| 35 | + coercing.parseValue(input) |
| 36 | + then: |
| 37 | + thrown(expectedValue) |
| 38 | + where: |
| 39 | + input | expectedValue |
| 40 | + "a-string-that-is-not-uuid" | CoercingParseValueException |
| 41 | + 100 | CoercingParseValueException |
| 42 | + "1985-04-12" | CoercingParseValueException |
| 43 | + } |
| 44 | + |
| 45 | + def "UUID AST literal"() { |
| 46 | + |
| 47 | + when: |
| 48 | + def result = coercing.parseLiteral(input) |
| 49 | + then: |
| 50 | + result == expectedValue |
| 51 | + where: |
| 52 | + input | expectedValue |
| 53 | + new StringValue("6972117d-3963-4214-ab2c-fa973d7e996b") | mkUUIDValue("6972117d-3963-4214-ab2c-fa973d7e996b") |
| 54 | + } |
| 55 | + |
| 56 | + def "UUID AST literal bad inputs"() { |
| 57 | + |
| 58 | + when: |
| 59 | + coercing.parseLiteral(input) |
| 60 | + then: |
| 61 | + thrown(expectedValue) |
| 62 | + where: |
| 63 | + input | expectedValue |
| 64 | + new StringValue("a-string-that-us-not-uuid") | CoercingParseLiteralException |
| 65 | + } |
| 66 | + |
| 67 | + def "UUID serialization"() { |
| 68 | + |
| 69 | + when: |
| 70 | + def result = coercing.serialize(input) |
| 71 | + then: |
| 72 | + result == expectedValue |
| 73 | + where: |
| 74 | + input | expectedValue |
| 75 | + "42287d47-c5bd-45e4-b470-53e426d3d503" | "42287d47-c5bd-45e4-b470-53e426d3d503" |
| 76 | + "423df0f3-cf05-4eb5-b708-ae2f4b4a052d" | "423df0f3-cf05-4eb5-b708-ae2f4b4a052d" |
| 77 | + mkUUIDValue("6a90b1e6-20f3-43e5-a7ba-34db8010c071") | "6a90b1e6-20f3-43e5-a7ba-34db8010c071" |
| 78 | + } |
| 79 | + |
| 80 | + def "UUID serialization bad inputs"() { |
| 81 | + |
| 82 | + when: |
| 83 | + coercing.serialize(input) |
| 84 | + then: |
| 85 | + thrown(expectedValue) |
| 86 | + where: |
| 87 | + input | expectedValue |
| 88 | + "1985-04-12" | CoercingSerializeException |
| 89 | + 100 | CoercingSerializeException |
| 90 | + } |
| 91 | + |
| 92 | + @Unroll |
| 93 | + def "UUID valueToLiteral"() { |
| 94 | + |
| 95 | + when: |
| 96 | + def result = coercing.valueToLiteral(input) |
| 97 | + then: |
| 98 | + result.isEqualTo(expectedValue) |
| 99 | + where: |
| 100 | + input | expectedValue |
| 101 | + "42287d47-c5bd-45e4-b470-53e426d3d503" | mkStringValue("42287d47-c5bd-45e4-b470-53e426d3d503") |
| 102 | + "423df0f3-cf05-4eb5-b708-ae2f4b4a052d" | mkStringValue("423df0f3-cf05-4eb5-b708-ae2f4b4a052d") |
| 103 | + mkUUIDValue("6a90b1e6-20f3-43e5-a7ba-34db8010c071") | mkStringValue("6a90b1e6-20f3-43e5-a7ba-34db8010c071") |
| 104 | + } |
| 105 | +} |
0 commit comments