-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.mjs
88 lines (69 loc) · 1.9 KB
/
test.mjs
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
85
86
87
import assert from 'assert';
import API from './demo.mjs';
// Some more tests needed
// Feel free to contribute
// I don't like writing automated tests
describe('Rests API Main', function () {
it('Basic Request Test', async function () {
const res = await API.user.login({
username: 'testusername',
password: 'testpassword'
});
assert.deepStrictEqual(res?.json?.json, {
username: 'testusername',
password: 'testpassword'
})
});
it('Should allow endpoints without params & request method', async function () {
let res = await API.empty()
assert.strictEqual(res.json.url, 'https://postman-echo.com/get');
});
const profile = new API.user.profile({
authorization: 'tokentest'
});
it('Should not inherit sibling options', async function () {
const res = await API.user.overview();
assert.strictEqual(res.json.args.o, "1");
});
it('Should throw error for double initialization of root', async function () {
try{
const profile_two = new profile({
authorization: 'tokentwo'
});
}
catch(e){
assert.match(e.message, /^This is already initialized/);
}
});
it('Should throw error for required parameters', async function () {
try{
await API.user.profile.info();
}
catch(e){
assert.strictEqual(e.field, 'authorization');
}
});
it('Subcategories should inherit updated values', async function () {
let res = await profile.about.me();
assert.strictEqual(res.json.headers?.['x-auth'], 'tokentest');
});
it('Subcategories should inherit updated options', async function () {
profile.set({
$options: {
params: {
secure: {
name: 'x-secure',
required: true,
location: 'headers',
}
}
}
});
let res = await profile.about.me({
authorization: 'tokencool',
secure: 'yes'
});
assert.strictEqual(res.json.headers?.['x-auth'], 'tokencool');
assert.strictEqual(res.json.headers?.['x-secure'], 'yes');
});
});