-
Notifications
You must be signed in to change notification settings - Fork 115
/
tests-open.js
82 lines (69 loc) · 2.28 KB
/
tests-open.js
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
import { check, group } from 'k6';
import { Httpx } from 'https://jslib.k6.io/httpx/0.0.3/index.js';
let session = new Httpx({
baseURL: `${__ENV.API_BASE}api`,
headers: { 'Content-Type': 'application/json' },
});
const responseToJson = (request) => {
try {
return JSON.parse(request.body);
} catch (error) {
return {};
}
};
const shallowObjectCompare = (expected, received) => {
return Object.keys(expected).every(k => expected[k] === received[k]);
}
export default () => {
group("Cria projeto titan", () => {
session.delete("/projects/titan/"); // <- limpa o ambiente antes do teste
const titanData = {
name: "titan",
packages: [
{name: "django-rest-swagger"},
{name: "Django", version: "2.2.24"},
{name: "psycopg2-binary", version: "2.9.1"}
]
};
const titan = session.post("/projects/", JSON.stringify(titanData));
check(titan, {
"Cria o projeto com sucesso": (r) => r.status === 201,
});
check(titan, {
"O pacote Django continua com a versão especificada": (r) => {
const data = responseToJson(r);
const django = data.packages.find((p) => p.name === "Django");
return django.version === "2.2.24";
},
});
check(titan, {
"O pacote django-rest-swagger usa a última versão disponível": (r) => {
const data = responseToJson(r);
const django = data.packages.find((p) => p.name === "django-rest-swagger");
return django.version === "2.2.0";
},
});
});
group("Cria projeto com pacote inexistente", () => {
session.delete("/projects/machine-head/"); // <- limpa o ambiente antes do teste
const mhdData = {
name: "machine-head",
packages: [
{name: "keras"},
{name: "matplotlib"},
{name: "pypypypypypypypypypypypypy"}
]
};
const mh = session.post("/projects/", JSON.stringify(mhdData));
check(mh, {
"Tentativa resulta em erro BAD REQUEST": (r) => r.status === 400,
});
check(mh, {
"Apresenta mensagem de erro": (r) => {
const data = responseToJson(r);
const expected = {"error": "One or more packages doesn't exist"};
return shallowObjectCompare(expected, data);
},
});
});
};