forked from postmanlabs/httpsnippet-fsless
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequests.js
More file actions
69 lines (58 loc) · 1.99 KB
/
requests.js
File metadata and controls
69 lines (58 loc) · 1.99 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
/* global describe, it */
'use strict'
var async = require('async')
var fixtures = require('./fixtures')
var HTTPSnippet = require('../src')
var targets = require('../src/targets')
var shell = require('child_process')
var util = require('util')
require('should')
var base = './test/fixtures/output/'
var requests = [ 'application-form-encoded',
'application-json',
'cookies',
'custom-method',
'headers',
'https',
'multipart-data',
'multipart-form-data',
'short'
]
// test all the things!
async.each(fixtures.cli, function (cli) {
describe(targets[cli.target].info.title + ' Request Validation', function () {
async.each(cli.clients, function (client) {
async.each(requests, function (request) {
it(client + ' request should match mock for ' + request, function (done) {
var stdout = ''
var fixture = cli.target + '/' + client + '/' + request + HTTPSnippet.extname(cli.target)
var command = util.format(cli.run, base + fixture)
var ls = shell.exec(command)
ls.stdout.on('data', function (data) {
stdout += data
})
ls.on('exit', function (code) {
try {
var har = JSON.parse(stdout)
} catch (err) {
err.should.be.null
}
// make an exception for multipart/form-data
if (fixtures.requests[request].headers) {
fixtures.requests[request].headers.map(function (header, index) {
if (header.name === 'content-type' && header.value === 'multipart/form-data') {
delete fixtures.requests[request].headers[index]
}
})
}
har.should.have.property('log')
har.log.should.have.property('entries').and.be.Array
har.log.entries[0].should.have.property('request')
har.log.entries[0].request.should.containDeep(fixtures.requests[request])
done()
})
})
})
})
})
})