55var fixtures = require ( './fixtures' )
66var HTTPSnippet = require ( '../src' )
77
8- require ( 'should' )
8+ var should = require ( 'should' )
99
1010describe ( 'HTTPSnippet' , function ( ) {
11+ it ( 'should return false if no matching target' , function ( done ) {
12+ var snippet = new HTTPSnippet ( fixtures . requests . short )
13+
14+ snippet . convert ( null ) . should . eql ( false )
15+
16+ done ( )
17+ } )
18+
19+ it ( 'should fail validation' , function ( done ) {
20+ var snippet ;
21+
22+ /*eslint-disable no-wrap-func */
23+ ( function ( ) {
24+ snippet = new HTTPSnippet ( { yolo : 'foo' } )
25+ } ) . should . throw ( Array )
26+
27+ should . not . exist ( snippet )
28+
29+ done ( )
30+ } )
31+
32+ it ( 'should parse HAR file with multiple entries' , function ( done ) {
33+ var snippet = new HTTPSnippet ( fixtures . har )
34+
35+ snippet . should . have . property ( 'requests' ) . and . be . an . Array
36+ snippet . requests . length . should . equal ( 2 )
37+
38+ var results = snippet . convert ( 'shell' )
39+
40+ results . should . be . an . Array
41+ results . length . should . equal ( 2 )
42+
43+ done ( )
44+ } )
45+
46+ it ( 'should convert multipart/mixed to multipart/form-data' , function ( done ) {
47+ var req = new HTTPSnippet ( fixtures . mimetypes [ 'multipart/mixed' ] ) . requests [ 0 ]
48+
49+ req . postData . mimeType . should . eql ( 'multipart/form-data' )
50+
51+ done ( )
52+ } )
53+
54+ it ( 'should convert multipart/related to multipart/form-data' , function ( done ) {
55+ var req = new HTTPSnippet ( fixtures . mimetypes [ 'multipart/related' ] ) . requests [ 0 ]
56+
57+ req . postData . mimeType . should . eql ( 'multipart/form-data' )
58+
59+ done ( )
60+ } )
61+
62+ it ( 'should convert multipart/alternative to multipart/form-data' , function ( done ) {
63+ var req = new HTTPSnippet ( fixtures . mimetypes [ 'multipart/alternative' ] ) . requests [ 0 ]
64+
65+ req . postData . mimeType . should . eql ( 'multipart/form-data' )
66+
67+ done ( )
68+ } )
69+
70+ it ( 'should convert text/json to application/json' , function ( done ) {
71+ var req = new HTTPSnippet ( fixtures . mimetypes [ 'text/json' ] ) . requests [ 0 ]
72+
73+ req . postData . mimeType . should . eql ( 'application/json' )
74+
75+ done ( )
76+ } )
77+
78+ it ( 'should convert text/x-json to application/json' , function ( done ) {
79+ var req = new HTTPSnippet ( fixtures . mimetypes [ 'text/x-json' ] ) . requests [ 0 ]
80+
81+ req . postData . mimeType . should . eql ( 'application/json' )
82+
83+ done ( )
84+ } )
85+
86+ it ( 'should convert application/x-json to application/json' , function ( done ) {
87+ var req = new HTTPSnippet ( fixtures . mimetypes [ 'application/x-json' ] ) . requests [ 0 ]
88+
89+ req . postData . mimeType . should . eql ( 'application/json' )
90+
91+ done ( )
92+ } )
93+
94+ it ( 'should gracefully fallback if not able to parse JSON' , function ( done ) {
95+ var req = new HTTPSnippet ( fixtures . mimetypes [ 'invalid-json' ] ) . requests [ 0 ]
96+
97+ req . postData . mimeType . should . eql ( 'text/plain' )
98+
99+ done ( )
100+ } )
101+
102+ it ( 'should set postData.text = empty string when postData.params === undefined in application/x-www-form-urlencoded' , function ( done ) {
103+ var req = new HTTPSnippet ( fixtures . mimetypes [ 'application/x-www-form-urlencoded' ] ) . requests [ 0 ]
104+
105+ req . postData . text . should . eql ( '' )
106+
107+ done ( )
108+ } )
109+
11110 it ( 'should add "uriObj" to source object' , function ( done ) {
12- var req = new HTTPSnippet ( fixtures . requests . query ) . source
111+ var req = new HTTPSnippet ( fixtures . requests . query ) . requests [ 0 ]
13112
14113 req . uriObj . should . be . an . Object
15114 req . uriObj . should . eql ( {
@@ -38,7 +137,7 @@ describe('HTTPSnippet', function () {
38137 } )
39138
40139 it ( 'should add "queryObj" to source object' , function ( done ) {
41- var req = new HTTPSnippet ( fixtures . requests . query ) . source
140+ var req = new HTTPSnippet ( fixtures . requests . query ) . requests [ 0 ]
42141
43142 req . queryObj . should . be . an . Object
44143 req . queryObj . should . eql ( {
@@ -54,7 +153,7 @@ describe('HTTPSnippet', function () {
54153 } )
55154
56155 it ( 'should add "headersObj" to source object' , function ( done ) {
57- var req = new HTTPSnippet ( fixtures . requests . headers ) . source
156+ var req = new HTTPSnippet ( fixtures . requests . headers ) . requests [ 0 ]
58157
59158 req . headersObj . should . be . an . Object
60159 req . headersObj . should . eql ( {
@@ -66,7 +165,7 @@ describe('HTTPSnippet', function () {
66165 } )
67166
68167 it ( 'should modify orignal url to strip query string' , function ( done ) {
69- var req = new HTTPSnippet ( fixtures . requests . query ) . source
168+ var req = new HTTPSnippet ( fixtures . requests . query ) . requests [ 0 ]
70169
71170 req . url . should . be . a . String
72171 req . url . should . eql ( 'http://mockbin.com/har' )
@@ -75,7 +174,7 @@ describe('HTTPSnippet', function () {
75174 } )
76175
77176 it ( 'should add "fullUrl" to source object' , function ( done ) {
78- var req = new HTTPSnippet ( fixtures . requests . query ) . source
177+ var req = new HTTPSnippet ( fixtures . requests . query ) . requests [ 0 ]
79178
80179 req . fullUrl . should . be . a . String
81180 req . fullUrl . should . eql ( 'http://mockbin.com/har?foo=bar&foo=baz&baz=abc&key=value' )
@@ -84,7 +183,7 @@ describe('HTTPSnippet', function () {
84183 } )
85184
86185 it ( 'should fix "path" property of "uriObj" to match queryString' , function ( done ) {
87- var req = new HTTPSnippet ( fixtures . requests . query ) . source
186+ var req = new HTTPSnippet ( fixtures . requests . query ) . requests [ 0 ]
88187
89188 req . uriObj . path . should . be . a . String
90189 req . uriObj . path . should . eql ( '/har?foo=bar&foo=baz&baz=abc&key=value' )
0 commit comments