-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathscanapi.yaml
More file actions
84 lines (79 loc) · 2.73 KB
/
scanapi.yaml
File metadata and controls
84 lines (79 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
endpoints:
# -------------------------------------------------------
# Health Check
# -------------------------------------------------------
- name: Health Check
path: ${BASE_URL}
requests:
- name: service_is_reachable
method: get
tests:
- name: returns_200
assert: ${{ response.status_code == 200 }}
# -------------------------------------------------------
# Posts API — Read operations
# -------------------------------------------------------
- name: Posts API
path: ${BASE_URL}/posts
headers:
Content-Type: application/json
requests:
- name: list_posts
method: get
params:
_limit: 2
tests:
- name: returns_200
assert: ${{ response.status_code == 200 }}
- name: response_is_list
assert: ${{ isinstance(response.json(), list) }}
- name: respects_limit
assert: ${{ len(response.json()) <= 2 }}
- name: get_single_post
path: /1
method: get
tests:
- name: returns_200
assert: ${{ response.status_code == 200 }}
- name: has_expected_fields
assert: ${{ all(k in response.json() for k in ("id", "title", "body", "userId")) }}
- name: get_nonexistent_post
path: /99999
method: get
tests:
- name: returns_404
assert: ${{ response.status_code == 404 }}
# -------------------------------------------------------
# Resource Lifecycle (request chaining)
# Demonstrates creating a resource and retrieving it
# using variables extracted from the previous response.
# -------------------------------------------------------
- name: Post Lifecycle
path: ${BASE_URL}/posts
headers:
Content-Type: application/json
requests:
- name: create_post
method: post
body:
title: "ScanAPI Smoke Test"
body: "This post was created by a CI smoke test."
userId: 1
tests:
- name: returns_201
assert: ${{ response.status_code == 201 }}
- name: has_id
assert: ${{ "id" in response.json() }}
- name: title_matches
assert: ${{ response.json()["title"] == "ScanAPI Smoke Test" }}
vars:
created_post_id: ${{ response.json()["id"] }}
- name: get_created_post
path: /${created_post_id}
method: get
tests:
- name: returns_200_or_404
# JSONPlaceholder doesn't persist new posts, so the
# created ID may return 404. In a real API this would
# be a strict 200 check. We keep it to show the pattern.
assert: ${{ response.status_code in (200, 404) }}