Skip to content

Commit 8a919d5

Browse files
committed
Add test cases
1 parent fc0de75 commit 8a919d5

File tree

2 files changed

+231
-0
lines changed

2 files changed

+231
-0
lines changed

test.json

Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
{
2+
"name": "Performance api test",
3+
"testCases": {
4+
"missing_required": {
5+
"path": "/app-signals/workstreams/work_stream_1/targets/focus",
6+
"method": "post",
7+
"description": "When start_date and end date is missing",
8+
"body": {
9+
"page": 1,
10+
"per_page": 1
11+
},
12+
"expect": {
13+
"header": {
14+
"contains": {
15+
"Content-Type": "application/json; charset=utf-8",
16+
"http_response": "HTTP/1.1 422 Unprocessable Entity"
17+
},
18+
"hasKey": ["http_status", "Date"]
19+
},
20+
"body": {
21+
"eq": {
22+
"ByField": {
23+
"EndDate": [
24+
{
25+
"Code": "C-INVALID_END_DATE",
26+
"Message": "end_date is a required field and should follow ISO8601 format."
27+
}
28+
],
29+
"StartDate": [
30+
{
31+
"Code": "C-INVALID_START_DATE",
32+
"Message": "start_date is a required field and should follow ISO8601 format."
33+
}
34+
]
35+
}
36+
},
37+
"hasKey": ["", "ByField"],
38+
"contains": {
39+
"ByField": {
40+
"EndDate": [
41+
{
42+
"Code": "C-INVALID_END_DATE"
43+
}
44+
]
45+
}
46+
}
47+
}
48+
}
49+
},
50+
"invalid_params": {
51+
"path": "/app-signals/workstreams/work_stream_1/targets/focus",
52+
"method": "post",
53+
"description": "When params are invalid",
54+
"body": {
55+
"start_date": "2020-0-01",
56+
"end_date": "2020-3-30",
57+
"target_ids": ["1", "2"],
58+
"page": 1,
59+
"per_page": 100
60+
},
61+
"expect": {
62+
"header": {
63+
"contains": {
64+
"Content-Type": "application/json; charset=utf-8",
65+
"http_response": "HTTP/1.1 422 Unprocessable Entity"
66+
},
67+
"hasKey": ["http_status", "Date"]
68+
},
69+
"body": {
70+
"eq": {
71+
"ByField": {
72+
"EndDate": [
73+
{
74+
"Code": "C-INVALID_END_DATE",
75+
"Message": "end_date is a required field and should follow ISO8601 format."
76+
}
77+
],
78+
"StartDate": [
79+
{
80+
"Code": "C-INVALID_START_DATE",
81+
"Message": "start_date is a required field and should follow ISO8601 format."
82+
}
83+
],
84+
"TargetIDs[0]": [
85+
{
86+
"Code": "C-INVALID_ID_FORMAT",
87+
"Message": "The provided ID should be valid ID with length 36."
88+
}
89+
],
90+
"TargetIDs[1]": [
91+
{
92+
"Code": "C-INVALID_ID_FORMAT",
93+
"Message": "The provided ID should be valid ID with length 36."
94+
}
95+
]
96+
}
97+
},
98+
"hasKey": ["", "ByField"],
99+
"contains": {
100+
"ByField": {
101+
"EndDate": [
102+
{
103+
"Code": "C-INVALID_END_DATE"
104+
}
105+
]
106+
}
107+
}
108+
}
109+
}
110+
},
111+
"per_page": {
112+
"path": "/app-signals/workstreams/work_stream_1/targets/focus",
113+
"method": "post",
114+
"description": "When per page is 2",
115+
"body": {
116+
"start_date": "2020-01-01",
117+
"end_date": "2020-03-30",
118+
"page": 1,
119+
"per_page": 2
120+
},
121+
"header": {},
122+
"expect": {
123+
"body": {
124+
"path_eq": {
125+
"data[0]": {
126+
"target_id": "1164",
127+
"mode": "focused",
128+
"duration": 1994,
129+
"target_name": "http://website1164.com"
130+
},
131+
"data[1].target_id": 11738
132+
},
133+
"path_contains": {
134+
"data[0]": {
135+
"target_id": "1164"
136+
},
137+
"data[1].target_id": 11738
138+
}
139+
140+
}
141+
}
142+
},
143+
"parse_error": {
144+
"path": "/app-signals/workstreams/work_stream_1/targets/focus",
145+
"method": "post",
146+
"description": "When per page is 2",
147+
"body": {
148+
"start_date": "2020-01-01",
149+
"end_date": "2020-03-30",
150+
"page": "1",
151+
"per_page": 2
152+
}
153+
},
154+
"all_valid_test": {
155+
"path": "/app-signals/workstreams/work_stream_1/targets/focus",
156+
"method": "post",
157+
"description": "When params are invalid",
158+
"body": {
159+
"start_date": "2020-01-01",
160+
"end_date": "2020-03-30",
161+
"page": 1,
162+
"per_page": 100
163+
},
164+
"header": {},
165+
"expect": {
166+
"header": {
167+
"contains": {
168+
"Content-Type": "application/json; charset=utf-8",
169+
"http_response": "HTTP/1.1 200 OK"
170+
},
171+
"hasKey": ["Content-Type"]
172+
},
173+
"body": {
174+
"hasKey": ["meta.total_duration", "data.99"],
175+
"contains": { "data": [], "meta": {} }
176+
}
177+
}
178+
}
179+
},
180+
"url": "localhost:3304",
181+
"header": {
182+
"Authorization": "Bearer ACCESS_TOKEN : ID_TOKEN"
183+
}
184+
}

test/test.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { exec } from "https://deno.land/x/exec/mod.ts";
2+
import { expect } from "https://deno.land/x/expect/mod.ts";
3+
async function run(testCase: string) {
4+
const cmd = Deno.run({
5+
cmd: [
6+
"../api-test.sh",
7+
"-f",
8+
"test.json",
9+
"run",
10+
testCase,
11+
],
12+
stdout: "piped",
13+
stderr: "piped",
14+
});
15+
const output = await cmd.output();
16+
cmd.close();
17+
const outStr = new TextDecoder().decode(output).replace(/META:\n(.*\n){4}/, "").split("\n").filter((x) =>
18+
x !== ""
19+
).map((x) =>
20+
x.replace(
21+
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
22+
"",
23+
)
24+
);
25+
return outStr;
26+
}
27+
28+
Deno.test({
29+
name: "Get APIs ",
30+
async fn() {
31+
let expected = `
32+
Running Case: get_api
33+
Response:
34+
200 OK
35+
BODY:
36+
{
37+
"id": "1",
38+
"author": "Robin Wieruch",
39+
"title": "The Road to React"
40+
}
41+
`.split("\n").filter((x) => x !== "");
42+
const response = await run("get_api");
43+
expect(response.map((x, i) => expected[i] === x).filter(x => !x).length).toEqual(0);
44+
},
45+
sanitizeResources: false,
46+
sanitizeOps: false,
47+
});

0 commit comments

Comments
 (0)