forked from Kong/httpsnippet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
103 lines (80 loc) · 2.41 KB
/
index.js
File metadata and controls
103 lines (80 loc) · 2.41 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
95
96
97
98
99
100
101
102
103
/* global describe, it */
'use strict'
var fixtures = require('./fixtures')
var HTTPSnippet = require('../src')
require('should')
describe('HTTPSnippet', function () {
var targets = HTTPSnippet.availableTargets()
targets.map(function (target) {
it('availableTargets should include ' + target.title, function (done) {
fixtures['available-targets'].should.containEql(target)
done()
})
})
it('should add "uriObj" to source object', function (done) {
var req = new HTTPSnippet(fixtures.requests.query).source
req.uriObj.should.be.an.Object
req.uriObj.should.eql({
auth: null,
hash: null,
host: 'mockbin.com',
hostname: 'mockbin.com',
href: 'http://mockbin.com/har?key=value',
path: '/har?foo=bar&foo=baz&baz=abc&key=value',
pathname: '/har',
port: null,
protocol: 'http:',
query: {
baz: 'abc',
key: 'value',
foo: [
'bar',
'baz'
]
},
search: 'foo=bar&foo=baz&baz=abc&key=value',
slashes: true
})
done()
})
it('should add "queryObj" to source object', function (done) {
var req = new HTTPSnippet(fixtures.requests.query).source
req.queryObj.should.be.an.Object
req.queryObj.should.eql({
baz: 'abc',
key: 'value',
foo: [
'bar',
'baz'
]
})
done()
})
it('should add "headersObj" to source object', function (done) {
var req = new HTTPSnippet(fixtures.requests.headers).source
req.headersObj.should.be.an.Object
req.headersObj.should.eql({
'accept': 'application/json',
'x-foo': 'Bar'
})
done()
})
it('should modify orignal url to strip query string', function (done) {
var req = new HTTPSnippet(fixtures.requests.query).source
req.url.should.be.a.String
req.url.should.eql('http://mockbin.com/har')
done()
})
it('should add "fullUrl" to source object', function (done) {
var req = new HTTPSnippet(fixtures.requests.query).source
req.fullUrl.should.be.a.String
req.fullUrl.should.eql('http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value')
done()
})
it('should fix "path" property of "uriObj" to match queryString', function (done) {
var req = new HTTPSnippet(fixtures.requests.query).source
req.uriObj.path.should.be.a.String
req.uriObj.path.should.eql('/har?foo=bar&foo=baz&baz=abc&key=value')
done()
})
})