2018-03-26 20:50:43 +00:00
|
|
|
/* global describe, it */
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
'use strict';
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
var fixtures = require('./fixtures');
|
|
|
|
var HTTPSnippet = require('../src');
|
|
|
|
var targets = require('../src/targets');
|
|
|
|
var shell = require('child_process');
|
|
|
|
var util = require('util');
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
require('should');
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
var base = './test/fixtures/output/';
|
|
|
|
var requests = [
|
|
|
|
'application-form-encoded',
|
2018-03-26 20:50:43 +00:00
|
|
|
'application-json',
|
|
|
|
'cookies',
|
|
|
|
'custom-method',
|
|
|
|
'headers',
|
|
|
|
'https',
|
|
|
|
'multipart-data',
|
|
|
|
'multipart-form-data',
|
|
|
|
'short'
|
2018-06-25 17:42:50 +00:00
|
|
|
];
|
2018-03-26 20:50:43 +00:00
|
|
|
|
|
|
|
// test all the things!
|
2018-06-25 17:42:50 +00:00
|
|
|
fixtures.cli.forEach(function(cli) {
|
|
|
|
describe(targets[cli.target].info.title + ' Request Validation', function() {
|
|
|
|
cli.clients.forEach(function(client) {
|
|
|
|
requests.forEach(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);
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
var ls = shell.exec(command);
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
ls.stdout.on('data', function(data) {
|
|
|
|
stdout += data;
|
|
|
|
});
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
ls.on('exit', function(code) {
|
2018-03-26 20:50:43 +00:00
|
|
|
try {
|
2018-06-25 17:42:50 +00:00
|
|
|
var har = JSON.parse(stdout);
|
2018-03-26 20:50:43 +00:00
|
|
|
} catch (err) {
|
2018-06-25 17:42:50 +00:00
|
|
|
err.should.be.null;
|
2018-03-26 20:50:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// make an exception for multipart/form-data
|
|
|
|
if (fixtures.requests[request].headers) {
|
2018-06-25 17:42:50 +00:00
|
|
|
fixtures.requests[request].headers.forEach(function(
|
|
|
|
header,
|
|
|
|
index
|
|
|
|
) {
|
|
|
|
if (
|
|
|
|
header.name === 'content-type' &&
|
|
|
|
header.value === 'multipart/form-data'
|
|
|
|
) {
|
|
|
|
delete fixtures.requests[request].headers[index];
|
2018-03-26 20:50:43 +00:00
|
|
|
}
|
2018-06-25 17:42:50 +00:00
|
|
|
});
|
2018-03-26 20:50:43 +00:00
|
|
|
}
|
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
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]
|
|
|
|
);
|
2018-03-26 20:50:43 +00:00
|
|
|
|
2018-06-25 17:42:50 +00:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|