Skip to content

Commit decfaaf

Browse files
authored
using the new graphql feature for testing (#15)
Co-authored-by: rick <LinuxSuRen@users.noreply.github.com>
1 parent f145494 commit decfaaf

3 files changed

Lines changed: 62 additions & 54 deletions

File tree

e2e/entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ set -e
33

44
mkdir -p /var/data
55

6+
atest run -p test-suite-graphql.yaml
67
atest run -p test-suite.yaml --report md --swagger-url "${SERVER}/v3/api-docs" --level debug
78

89
# cannot get the token in a pr

e2e/test-suite-graphql.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!api-testing
2+
# yaml-language-server: $schema=https://linuxsuren.github.io/api-testing/api-testing-schema.json
3+
name: SpringBoot
4+
api: |
5+
{{default "http://localhost:8080" (env "SERVER")}}
6+
spec:
7+
kind: GraphQL
8+
items:
9+
- name: queryBookById
10+
request:
11+
api: /graphql
12+
body:
13+
query: |
14+
query xxx($id: ID) {
15+
bookById(id: $id) {
16+
name
17+
}
18+
}
19+
operationName: xxx
20+
variables:
21+
id: book-1
22+
expect:
23+
bodyFieldsExpect:
24+
data.bookById.name: Effective Java
25+
- name: allBooks
26+
request:
27+
api: /graphql
28+
body:
29+
query: |
30+
query xxx {
31+
books {
32+
name
33+
}
34+
}
35+
expect:
36+
verify:
37+
- len(data.data.books) >= 3
38+
- name: queryBookById-not-found
39+
request:
40+
api: /graphql
41+
body:
42+
query: |
43+
query xxx {
44+
bookById(id: "book") {
45+
name
46+
}
47+
}
48+
expect:
49+
verify:
50+
- data.bookById == nil
51+
- name: addBook
52+
request:
53+
api: /graphql
54+
body:
55+
query: |
56+
mutation size {
57+
addBook(
58+
name: "name"
59+
pageCount: 1
60+
)
61+
}

e2e/test-suite.yaml

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -34,57 +34,3 @@ items:
3434
Authorization: "{{ .param.auth }}"
3535
expect:
3636
body: cookies are empty
37-
38-
## GraphQL
39-
- name: queryBookById
40-
request:
41-
api: /graphql
42-
method: POST
43-
header:
44-
Content-Type: application/json
45-
body: |
46-
{
47-
"query": "query xxx($id: ID) {\n bookById(id: $id) {\n id\n name\n }\n}",
48-
"operationName": "xxx",
49-
"variables": {"id": "book-1"}
50-
}
51-
expect:
52-
bodyFieldsExpect:
53-
data.bookById.name: Effective Java
54-
- name: allBooks
55-
request:
56-
api: /graphql
57-
method: POST
58-
header:
59-
Content-Type: application/json
60-
body: |
61-
{
62-
"query": "query xxx { books { name } }"
63-
}
64-
expect:
65-
verify:
66-
- len(data.data.books) >= 3
67-
- name: queryBookById-not-found
68-
request:
69-
api: /graphql
70-
method: POST
71-
header:
72-
Content-Type: application/json
73-
body: |
74-
{
75-
"query": "query xxx {\n bookById(id: \"book\") {\n id\n name\n }\n}",
76-
"operationName": "xxx"
77-
}
78-
expect:
79-
verify:
80-
- data.bookById == nil
81-
- name: addBook
82-
request:
83-
api: /graphql
84-
method: POST
85-
header:
86-
Content-Type: application/json
87-
body: |
88-
{
89-
"query": "mutation size { addBook(name: \"name\"\n pageCount: 1)}"
90-
}

0 commit comments

Comments
 (0)