1
|
|
|
import { assert } from 'chai'; |
2
|
|
|
import chronicle from '../entry'; |
3
|
|
|
|
4
|
|
|
suite('Actions'); |
5
|
|
|
|
6
|
|
|
test('Manually setting required attributes', function () { |
7
|
|
|
const action = chronicle.action({ title: 'get users', group: 'Users' }); |
8
|
|
|
|
9
|
|
|
action.url = 'http://localhost:8080/api/users?status=ACTIVE'; |
10
|
|
|
|
11
|
|
|
action.response = { |
12
|
|
|
headers : { 'content-type': 'application/json' }, |
13
|
|
|
code : 200, |
14
|
|
|
body : [] |
15
|
|
|
}; |
16
|
|
|
|
17
|
|
|
const { |
18
|
|
|
request, |
19
|
|
|
response, |
20
|
|
|
context |
21
|
|
|
} = action.data; |
22
|
|
|
|
23
|
|
|
assert.equal(context.title, 'get users'); |
24
|
|
|
assert.equal(context.group, 'Users'); |
25
|
|
|
|
26
|
|
|
assert.deepEqual(request, { |
27
|
|
|
href : 'http://localhost:8080/api/users?status=ACTIVE', |
28
|
|
|
origin : 'http://localhost:8080', |
29
|
|
|
protocol : 'http:', |
30
|
|
|
hostname : 'localhost', |
31
|
|
|
port : '8080', |
32
|
|
|
path : '/api/users', |
33
|
|
|
query : { status: 'ACTIVE' }, |
34
|
|
|
method : 'GET', |
35
|
|
|
headers : null |
36
|
|
|
}); |
37
|
|
|
|
38
|
|
|
assert.deepOwnInclude(response, { |
39
|
|
|
headers : { 'content-type': 'application/json' }, |
40
|
|
|
'http' : { |
41
|
|
|
'version' : '1.1' |
42
|
|
|
}, |
43
|
|
|
'info' : { |
44
|
|
|
'charset' : 'utf-8', |
45
|
|
|
'type' : 'application/json' |
46
|
|
|
}, |
47
|
|
|
'status' : { |
48
|
|
|
'code' : 200, |
49
|
|
|
'message' : 'OK' |
50
|
|
|
}, |
51
|
|
|
body : [] |
52
|
|
|
}); |
53
|
|
|
}); |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
// import { Chronicle, axios, request } from 'rest-chronicle'; |
57
|
|
|
|
58
|
|
|
// const chronicle = new Chronicle({ |
59
|
|
|
// version : 'v1', |
60
|
|
|
// prefix : 'api/v1' |
61
|
|
|
// }); |
62
|
|
|
// // const axios = new Axios({ |
63
|
|
|
// // with : 'mocha', |
64
|
|
|
// // instance : chronicle |
65
|
|
|
// // }); |
66
|
|
|
|
67
|
|
|
// axios({ |
68
|
|
|
// with : this, |
69
|
|
|
// method : 'get', |
70
|
|
|
// url : 'http://bit.ly/2mTM3nY', |
71
|
|
|
// responseType : 'stream' |
72
|
|
|
// }); |
73
|
|
|
|
74
|
|
|
// { |
75
|
|
|
// const action = chronicle.action('get users', 'Users'); |
76
|
|
|
|
77
|
|
|
// action.url = 'http://localhost:8080/api/v1/users?status=ACTIVE'; |
78
|
|
|
// action.response = { |
79
|
|
|
// headers : { 'content-type': 'application/json' }, |
80
|
|
|
// code : 200, |
81
|
|
|
// body : [] |
82
|
|
|
// }; |
83
|
|
|
// // action.method = 'GET'; |
84
|
|
|
// } |
85
|
|
|
|
86
|
|
|
// // methods |
87
|
|
|
// // with |
88
|
|
|
// // desc |
89
|
|
|
// // comment |
90
|
|
|
// // tag |
91
|
|
|
|
92
|
|
|
// axios |
93
|
|
|
// .with(this) |
94
|
|
|
// .desc('additional descr') |
95
|
|
|
// .comment('some text') |
96
|
|
|
// .get('/user/12345'); |
97
|
|
|
|
98
|
|
|
// request |
99
|
|
|
// .with(this) |
100
|
|
|
// .get('/products') |
101
|
|
|
// .expect(200); |
102
|
|
|
|
103
|
|
|
// // const instane1 = axios.create({ |
104
|
|
|
// // baseURL : 'https://some-domain.com/api/', |
105
|
|
|
// // timeout : 1000, |
106
|
|
|
// // headers : { 'X-Custom-Header': 'foobar' } |
107
|
|
|
// // }); |
108
|
|
|
|
109
|
|
|
|
110
|
|
|
// chronicle.save('filePath', {}); |
111
|
|
|
// chronicle.saveMany('groups_to_files', {}); |
112
|
|
|
// chronicle.clear(); |
113
|
|
|
|
114
|
|
|
|