|
| 1 | +package com.intuit.graphql.orchestrator.authorization |
| 2 | + |
| 3 | +import com.intuit.graphql.orchestrator.stitching.InvalidDirectivePairingException |
| 4 | +import spock.lang.Specification; |
| 5 | +import com.intuit.graphql.graphQL.Directive |
| 6 | + |
| 7 | +import com.intuit.graphql.graphQL.DirectiveDefinition |
| 8 | +import static com.intuit.graphql.orchestrator.XtextObjectCreationUtil.buildDirective |
| 9 | +import static com.intuit.graphql.orchestrator.XtextObjectCreationUtil.buildDirectiveDefinition; |
| 10 | + |
| 11 | +class ValidateMultipleDirectiveCoexistSpec extends Specification { |
| 12 | + private Directive resolverDirective |
| 13 | + |
| 14 | + private Directive providesDirective |
| 15 | + |
| 16 | + private Directive externalDirective |
| 17 | + |
| 18 | + private Directive requiresDirective |
| 19 | + |
| 20 | + private Directive skipDirective |
| 21 | + |
| 22 | + private Directive includesDirective |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | + def setup() { |
| 27 | + DirectiveDefinition resolverDirectiveDefinition = buildDirectiveDefinition("resolver") |
| 28 | + DirectiveDefinition externalDirectiveDefinition = buildDirectiveDefinition("external") |
| 29 | + DirectiveDefinition requiresDirectiveDefinition = buildDirectiveDefinition("requires") |
| 30 | + DirectiveDefinition providesDirectiveDefinition = buildDirectiveDefinition("provides") |
| 31 | + DirectiveDefinition skipDirectiveDefinition = buildDirectiveDefinition("skip") |
| 32 | + DirectiveDefinition includesDirectiveDefinition = buildDirectiveDefinition("include") |
| 33 | + resolverDirective = buildDirective(resolverDirectiveDefinition, Collections.emptyList()) |
| 34 | + providesDirective = buildDirective(providesDirectiveDefinition, Collections.emptyList()) |
| 35 | + externalDirective = buildDirective(externalDirectiveDefinition, Collections.emptyList()) |
| 36 | + requiresDirective = buildDirective(requiresDirectiveDefinition, Collections.emptyList()) |
| 37 | + skipDirective = buildDirective(skipDirectiveDefinition, Collections.emptyList()) |
| 38 | + includesDirective = buildDirective(includesDirectiveDefinition, Collections.emptyList()) |
| 39 | + } |
| 40 | + |
| 41 | + def "should throw exception for invalid directive pairing: resolver and external"() { |
| 42 | + given: |
| 43 | + def directives = [ |
| 44 | + resolverDirective, |
| 45 | + externalDirective |
| 46 | + ] |
| 47 | + |
| 48 | + when: |
| 49 | + new ValidateMultipleDirectivesCoexist().validate(directives) |
| 50 | + |
| 51 | + then: |
| 52 | + thrown InvalidDirectivePairingException.class |
| 53 | + } |
| 54 | + |
| 55 | + def "should throw exception for invalid directive pairing: resolver and provides"() { |
| 56 | + given: |
| 57 | + def directives = [ |
| 58 | + resolverDirective, |
| 59 | + providesDirective |
| 60 | + ] |
| 61 | + |
| 62 | + when: |
| 63 | + new ValidateMultipleDirectivesCoexist().validate(directives) |
| 64 | + |
| 65 | + then: |
| 66 | + thrown InvalidDirectivePairingException.class |
| 67 | + } |
| 68 | + |
| 69 | + def "should throw exception for invalid directive pairing: resolver and requires"() { |
| 70 | + given: |
| 71 | + def directives = [ |
| 72 | + resolverDirective, |
| 73 | + requiresDirective |
| 74 | + ] |
| 75 | + |
| 76 | + when: |
| 77 | + new ValidateMultipleDirectivesCoexist().validate(directives) |
| 78 | + |
| 79 | + then: |
| 80 | + thrown InvalidDirectivePairingException.class |
| 81 | + } |
| 82 | + |
| 83 | + def "should not throw exception for valid directives"() { |
| 84 | + given: |
| 85 | + def directives = [ |
| 86 | + requiresDirective, |
| 87 | + skipDirective, |
| 88 | + includesDirective |
| 89 | + ] |
| 90 | + |
| 91 | + when: |
| 92 | + new ValidateMultipleDirectivesCoexist().validate(directives) |
| 93 | + |
| 94 | + then: |
| 95 | + noExceptionThrown() |
| 96 | + } |
| 97 | +} |
| 98 | + |
| 99 | + |
0 commit comments