Skip to content

Commit

Permalink
using the new graphql feature for testing (#15)
Browse files Browse the repository at this point in the history
Co-authored-by: rick <[email protected]>
  • Loading branch information
LinuxSuRen and LinuxSuRen authored Dec 21, 2023
1 parent f145494 commit decfaaf
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 54 deletions.
1 change: 1 addition & 0 deletions e2e/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
61 changes: 61 additions & 0 deletions e2e/test-suite-graphql.yaml
Original file line number Diff line number Diff line change
@@ -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
)
}
54 changes: 0 additions & 54 deletions e2e/test-suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)}"
}

0 comments on commit decfaaf

Please sign in to comment.