forked from postmanlabs/httpsnippet-fsless
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttpie.js
More file actions
94 lines (78 loc) · 2.93 KB
/
httpie.js
File metadata and controls
94 lines (78 loc) · 2.93 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
85
86
87
88
89
90
91
92
93
94
/* global it */
'use strict'
require('should')
module.exports = function (HTTPSnippet, fixtures) {
it('should ask for verbose output', function () {
var result = new HTTPSnippet(fixtures.requests.short).convert('shell', 'httpie', {
indent: false,
verbose: true
})
result.should.be.a.String
result.should.eql('http --verbose GET http://mockbin.com/har')
})
it('should use short flags', function () {
var result = new HTTPSnippet(fixtures.requests.short).convert('shell', 'httpie', {
body: true,
cert: 'foo',
headers: true,
indent: false,
pretty: 'x',
print: 'x',
short: true,
style: 'x',
timeout: 1,
verbose: true,
verify: 'x'
})
result.should.be.a.String
result.should.eql('http -h -b -v -p=x --verify=x --cert=foo --pretty=x --style=x --timeout=1 GET http://mockbin.com/har')
})
it('should use long flags', function () {
var result = new HTTPSnippet(fixtures.requests.short).convert('shell', 'httpie', {
body: true,
cert: 'foo',
headers: true,
indent: false,
pretty: 'x',
print: 'x',
style: 'x',
timeout: 1,
verbose: true,
verify: 'x'
})
result.should.be.a.String
result.should.eql('http --headers --body --verbose --print=x --verify=x --cert=foo --pretty=x --style=x --timeout=1 GET http://mockbin.com/har')
})
it('should use custom indentation', function () {
var result = new HTTPSnippet(fixtures.requests.full).convert('shell', 'httpie', {
indent: '@'
})
result.should.be.a.String
result.replace(/\\\n/g, '').should.eql("http --form POST 'http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value' @accept:application/json @content-type:application/x-www-form-urlencoded @cookie:'foo=bar; bar=baz' @foo=bar")
})
it('should use queryString parameters', function () {
var result = new HTTPSnippet(fixtures.requests.query).convert('shell', 'httpie', {
indent: false,
queryParams: true
})
result.should.be.a.String
result.replace(/\\\n/g, '').should.eql('http GET http://mockbin.com/har foo==bar foo==baz baz==abc key==value')
})
it('should build parameterized output of query string', function () {
var result = new HTTPSnippet(fixtures.requests.query).convert('shell', 'httpie', {
indent: false,
queryParams: true
})
result.should.be.a.String
result.replace(/\\\n/g, '').should.eql('http GET http://mockbin.com/har foo==bar foo==baz baz==abc key==value')
})
it('should build parameterized output of post data', function () {
var result = new HTTPSnippet(fixtures.requests['application-form-encoded']).convert('shell', 'httpie', {
short: true,
indent: false,
queryParams: true
})
result.should.be.a.String
result.replace(/\\\n/g, '').should.eql('http -f POST http://mockbin.com/har content-type:application/x-www-form-urlencoded foo=bar hello=world')
})
}