-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix of client events behavior (#1181)
* added ability to add to request http header within "request", "message" events; added accompanying test which test ability to add http header within "request" event; * fixed lint error
- Loading branch information
1 parent
c54e125
commit 52a280e
Showing
2 changed files
with
67 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
'use strict'; | ||
|
||
var soap = require('..'), | ||
http = require('http'), | ||
assert = require('assert'); | ||
|
||
|
||
describe('testing adding header rely on completed xml', () => { | ||
let server = null; | ||
let hostname = '127.0.0.1'; | ||
let port = 15099; | ||
let baseUrl = 'http://' + hostname + ':' + port; | ||
const envelope = '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' | ||
+ ' xmlns:xsd="http://www.w3.org/2001/XMLSchema"' | ||
+ ' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">' | ||
+ '<soap:Body><Response>Hello</Response></soap:Body></soap:Envelope>'; | ||
|
||
before(function (done) { | ||
server = http.createServer(function (req, res) { | ||
res.statusCode = 200; | ||
res.write(envelope, 'utf8'); | ||
res.end(); | ||
}).listen(port, hostname, done); | ||
}); | ||
|
||
after(function (done) { | ||
server.close(); | ||
server = null; | ||
done(); | ||
}); | ||
|
||
it('should add header to request, which created from xml before request', function (done) { | ||
soap.createClient(__dirname + '/wsdl/complex/registration-common.wsdl', function (err, client) { | ||
if (err) { | ||
return void done(err); | ||
} | ||
assert.ok(client); | ||
|
||
const testHeaderKey = 'testHeader'; | ||
let testHeaderValue; | ||
|
||
client.on('request', (xml) => { | ||
testHeaderValue = xml; | ||
client.addHttpHeader(testHeaderKey, xml); | ||
}); | ||
|
||
client.registerUser('', function (err, result) { | ||
|
||
const header = result.request._header; | ||
const headerKey = header.includes(testHeaderKey); | ||
const headerValue = header.includes(testHeaderValue); | ||
|
||
assert.equal(headerKey, true); | ||
assert.equal(headerValue, true); | ||
done(); | ||
}); | ||
}, baseUrl); | ||
}); | ||
}); |