From decfaafcd9af443e89b3769321c7a3920f24b6a7 Mon Sep 17 00:00:00 2001 From: Rick <1450685+LinuxSuRen@users.noreply.github.com> Date: Thu, 21 Dec 2023 19:08:39 +0800 Subject: [PATCH] using the new graphql feature for testing (#15) Co-authored-by: rick --- e2e/entrypoint.sh | 1 + e2e/test-suite-graphql.yaml | 61 +++++++++++++++++++++++++++++++++++++ e2e/test-suite.yaml | 54 -------------------------------- 3 files changed, 62 insertions(+), 54 deletions(-) create mode 100644 e2e/test-suite-graphql.yaml diff --git a/e2e/entrypoint.sh b/e2e/entrypoint.sh index e95b878..4d44b61 100755 --- a/e2e/entrypoint.sh +++ b/e2e/entrypoint.sh @@ -3,6 +3,7 @@ set -e mkdir -p /var/data +atest run -p test-suite-graphql.yaml atest run -p test-suite.yaml --report md --swagger-url "${SERVER}/v3/api-docs" --level debug # cannot get the token in a pr diff --git a/e2e/test-suite-graphql.yaml b/e2e/test-suite-graphql.yaml new file mode 100644 index 0000000..f636508 --- /dev/null +++ b/e2e/test-suite-graphql.yaml @@ -0,0 +1,61 @@ +#!api-testing +# yaml-language-server: $schema=https://linuxsuren.github.io/api-testing/api-testing-schema.json +name: SpringBoot +api: | + {{default "http://localhost:8080" (env "SERVER")}} +spec: + kind: GraphQL +items: +- name: queryBookById + request: + api: /graphql + body: + query: | + query xxx($id: ID) { + bookById(id: $id) { + name + } + } + operationName: xxx + variables: + id: book-1 + expect: + bodyFieldsExpect: + data.bookById.name: Effective Java +- name: allBooks + request: + api: /graphql + body: + query: | + query xxx { + books { + name + } + } + expect: + verify: + - len(data.data.books) >= 3 +- name: queryBookById-not-found + request: + api: /graphql + body: + query: | + query xxx { + bookById(id: "book") { + name + } + } + expect: + verify: + - data.bookById == nil +- name: addBook + request: + api: /graphql + body: + query: | + mutation size { + addBook( + name: "name" + pageCount: 1 + ) + } diff --git a/e2e/test-suite.yaml b/e2e/test-suite.yaml index 2037b98..87c05e9 100644 --- a/e2e/test-suite.yaml +++ b/e2e/test-suite.yaml @@ -34,57 +34,3 @@ items: Authorization: "{{ .param.auth }}" expect: body: cookies are empty - -## GraphQL -- name: queryBookById - request: - api: /graphql - method: POST - header: - Content-Type: application/json - body: | - { - "query": "query xxx($id: ID) {\n bookById(id: $id) {\n id\n name\n }\n}", - "operationName": "xxx", - "variables": {"id": "book-1"} - } - expect: - bodyFieldsExpect: - data.bookById.name: Effective Java -- name: allBooks - request: - api: /graphql - method: POST - header: - Content-Type: application/json - body: | - { - "query": "query xxx { books { name } }" - } - expect: - verify: - - len(data.data.books) >= 3 -- name: queryBookById-not-found - request: - api: /graphql - method: POST - header: - Content-Type: application/json - body: | - { - "query": "query xxx {\n bookById(id: \"book\") {\n id\n name\n }\n}", - "operationName": "xxx" - } - expect: - verify: - - data.bookById == nil -- name: addBook - request: - api: /graphql - method: POST - header: - Content-Type: application/json - body: | - { - "query": "mutation size { addBook(name: \"name\"\n pageCount: 1)}" - }