|
| 1 | +/* |
| 2 | + * Copyright 2022 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.examples.server.spring.query |
| 18 | + |
| 19 | +import com.expediagroup.graphql.examples.server.spring.GRAPHQL_MEDIA_TYPE |
| 20 | +import com.expediagroup.graphql.examples.server.spring.verifyData |
| 21 | +import org.junit.jupiter.api.Test |
| 22 | +import org.junit.jupiter.api.TestInstance |
| 23 | +import org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS |
| 24 | +import org.springframework.beans.factory.annotation.Autowired |
| 25 | +import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient |
| 26 | +import org.springframework.boot.test.context.SpringBootTest |
| 27 | +import org.springframework.http.MediaType.APPLICATION_JSON |
| 28 | +import org.springframework.test.web.reactive.server.WebTestClient |
| 29 | + |
| 30 | +@SpringBootTest( |
| 31 | + properties = ["graphql.automaticPersistedQueries.enabled=true"] |
| 32 | +) |
| 33 | +@AutoConfigureWebTestClient |
| 34 | +@TestInstance(PER_CLASS) |
| 35 | +class APQQueryIT(@Autowired private val testClient: WebTestClient) { |
| 36 | + |
| 37 | + @Test |
| 38 | + fun `verify GET persisted query with hash only followed by POST with hash`() { |
| 39 | + val query = "simpleDeprecatedQuery" |
| 40 | + |
| 41 | + testClient.get() |
| 42 | + .uri { builder -> |
| 43 | + builder.path("/graphql") |
| 44 | + .queryParam("extensions", "{extension}") |
| 45 | + .build("""{"persistedQuery":{"version":1,"sha256Hash":"aee64e0a941589ff06b717d4930405f3eafb089e687bef6ece5719ea6a4e7f35"}}""") |
| 46 | + } |
| 47 | + .exchange() |
| 48 | + .expectBody().json( |
| 49 | + """ |
| 50 | + { |
| 51 | + errors: [ |
| 52 | + { |
| 53 | + message: "PersistedQueryNotFound" |
| 54 | + } |
| 55 | + ] |
| 56 | + } |
| 57 | + """.trimIndent() |
| 58 | + ) |
| 59 | + |
| 60 | + val expectedData = "false" |
| 61 | + |
| 62 | + testClient.post() |
| 63 | + .uri { builder -> |
| 64 | + builder.path("/graphql") |
| 65 | + .queryParam("extensions", "{extension}") |
| 66 | + .build("""{"persistedQuery":{"version":1,"sha256Hash":"aee64e0a941589ff06b717d4930405f3eafb089e687bef6ece5719ea6a4e7f35"}}""") |
| 67 | + } |
| 68 | + .accept(APPLICATION_JSON) |
| 69 | + .contentType(GRAPHQL_MEDIA_TYPE) |
| 70 | + .bodyValue("query { $query }") |
| 71 | + .exchange() |
| 72 | + .verifyData(query, expectedData) |
| 73 | + |
| 74 | + testClient.get() |
| 75 | + .uri { builder -> |
| 76 | + builder.path("/graphql") |
| 77 | + .queryParam("extensions", "{extension}") |
| 78 | + .build("""{"persistedQuery":{"version":1,"sha256Hash":"aee64e0a941589ff06b717d4930405f3eafb089e687bef6ece5719ea6a4e7f35"}}""") |
| 79 | + } |
| 80 | + .exchange() |
| 81 | + .verifyData(query, expectedData) |
| 82 | + } |
| 83 | +} |
0 commit comments