Comparing version 0.1.6 to 0.1.7
@@ -9,2 +9,3 @@ export declare class EsendexFake { | ||
private MessageDispatcherEndpoint(req, res); | ||
private MessageHeaderEndpoint(req, res); | ||
private MessageHeadersEndpoint(req, res); | ||
@@ -11,0 +12,0 @@ private AccountEndpoint(req, res); |
@@ -43,5 +43,7 @@ var http = require('http'); | ||
}; | ||
var dataBuf; | ||
if (isPost) { | ||
dataBuf = data ? new Buffer(data, 'utf8') : null; | ||
headers['Content-Type'] = 'application/xml'; | ||
headers['Content-Length'] = data ? data.length : 0; | ||
headers['Content-Length'] = data ? dataBuf.length : 0; | ||
} | ||
@@ -65,3 +67,3 @@ var proto = this.options.https ? https : http; | ||
if (isPost && data) | ||
req.write(data); | ||
req.write(dataBuf); | ||
req.end(); | ||
@@ -68,0 +70,0 @@ }; |
@@ -10,3 +10,4 @@ var xml2js_1 = require('xml2js'); | ||
encoding: 'UTF-8' | ||
} | ||
}, | ||
allowSurrogateChars: true | ||
}); | ||
@@ -13,0 +14,0 @@ } |
@@ -23,2 +23,3 @@ var express = require('express'); | ||
this.app.get('/v1.0/messageheaders', this.MessageHeadersEndpoint.bind(this)); | ||
this.app.get('/v1.0/messageheaders/CDEB3533-1F76-46D7-A2A9-0DAF8290F7FC', this.MessageHeaderEndpoint.bind(this)); | ||
this.app.post('/v1.0/messagedispatcher', textBodyParser, this.MessageDispatcherEndpoint.bind(this)); | ||
@@ -41,2 +42,7 @@ } | ||
}; | ||
EsendexFake.prototype.MessageHeaderEndpoint = function (req, res) { | ||
res.status(200); | ||
res.set('Content-Type', 'application/xml'); | ||
fs_1.createReadStream(path_1.join(__dirname, '..', '..', 'responses', 'messageheaders-get-single.xml')).pipe(res); | ||
}; | ||
EsendexFake.prototype.MessageHeadersEndpoint = function (req, res) { | ||
@@ -43,0 +49,0 @@ res.status(200); |
@@ -44,2 +44,29 @@ var assert = require('assert'); | ||
}); | ||
describe('get single message', function () { | ||
var message; | ||
before(function (done) { | ||
var options = { id: 'CDEB3533-1F76-46D7-A2A9-0DAF8290F7FC' }; | ||
esendex.messages.get(options, function (err, messageheader) { | ||
if (err) | ||
return done(err); | ||
message = messageheader; | ||
done(); | ||
}); | ||
}); | ||
it('should return the expected messageheader', function () { | ||
assert.strictEqual(message.id, 'CDEB3533-1F76-46D7-A2A9-0DAF8290F7FC'); | ||
assert.strictEqual(message.uri, 'http://api.esendex.com/v1.0/messageheaders/CDEB3533-1F76-46D7-A2A9-0DAF8290F7FC/'); | ||
assert.strictEqual(message.status, 'Delivered'); | ||
assert.strictEqual(message.laststatusat, '2010-01-01T12:00:05.000'); | ||
assert.strictEqual(message.submittedat, '2010-01-01T12:00:02.000'); | ||
assert.strictEqual(message.type, 'SMS'); | ||
assert.strictEqual(message.to.phonenumber, '447700900123'); | ||
assert.strictEqual(message.from.phonenumber, '447700900654'); | ||
assert.strictEqual(message.summary, 'Testing REST API'); | ||
assert.strictEqual(message.body.uri, 'http://api.esendex.com/v1.0/messageheaders/CDEB3533-1F76-46D7-A2A9-0DAF8290F7FC/body'); | ||
assert.strictEqual(message.direction, 'Outbound'); | ||
assert.strictEqual(message.parts, '1'); | ||
assert.strictEqual(message.username, 'user@example.com'); | ||
}); | ||
}); | ||
describe('send a message', function () { | ||
@@ -53,3 +80,3 @@ var response; | ||
to: '447000000000', | ||
body: "Every message matters!" | ||
body: 'Every message matters!' | ||
}] | ||
@@ -79,4 +106,38 @@ }; | ||
}); | ||
describe('send a unicode message', function () { | ||
var response; | ||
var loggedRequest; | ||
before(function (done) { | ||
var messages = { | ||
accountreference: 'EX0123456', | ||
characterset: 'Unicode', | ||
message: [{ | ||
to: '447000000000', | ||
body: 'Every 🐳 matters!' | ||
}] | ||
}; | ||
esendex.messages.send(messages, function (err, res) { | ||
if (err) | ||
return done(err); | ||
response = res; | ||
loggedRequest = esendexFake.dispatcherRequests.length === 0 ? null : esendexFake.dispatcherRequests[0]; | ||
done(); | ||
}); | ||
}); | ||
it('should return the batch ID of the sent message', function () { | ||
assert.strictEqual(response.batchid, 'F8BF9867-FF81-49E4-ACC5-774DE793B776'); | ||
}); | ||
it('should return the messageheader ID and uri of the sent message', function () { | ||
assert.strictEqual(response.messageheader[0].id, '1183C73D-2E62-4F60-B610-30F160BDFBD5'); | ||
assert.strictEqual(response.messageheader[0].uri, 'https://api.esendex.com/v1.0/messageheaders/1183C73D-2E62-4F60-B610-30F160BDFBD5'); | ||
}); | ||
it('should return an array of sent message headers', function () { | ||
assert.ok(util_1.isArray(response.messageheader)); | ||
}); | ||
it('should return one sent message header', function () { | ||
assert.strictEqual(response.messageheader.length, 1); | ||
}); | ||
}); | ||
}); | ||
//# sourceMappingURL=messages.integration.test.js.map |
@@ -162,2 +162,3 @@ var assert = require('assert'); | ||
var body; | ||
var bodyLength; | ||
var responseBody; | ||
@@ -169,5 +170,6 @@ var requestFake; | ||
path = '1/2/3/4'; | ||
body = 'some xml body'; | ||
body = 'some unicode xml 🐳 body'; | ||
bodyLength = 26; | ||
responseBody = 'This is the response body content'; | ||
requestFake = { on: sinon.stub(), end: sinon.stub(), write: sinon.expectation.create().once() }; | ||
requestFake = { on: sinon.stub(), end: sinon.stub(), write: sinon.spy() }; | ||
requestStub = sinon.stub().callsArg(1).returns(requestFake); | ||
@@ -196,7 +198,8 @@ var responseHandlerHandle = sinon.stub().callsArgWith(2, null, responseBody); | ||
'Content-Type': 'application/xml', | ||
'Content-Length': body.length | ||
'Content-Length': bodyLength | ||
} })); | ||
}); | ||
it('should write the request body to the request', function () { | ||
sinon.assert.calledWith(requestFake.write, body); | ||
it('should write the request body buffer to the request', function () { | ||
sinon.assert.calledOnce(requestFake.write); | ||
assert.equal(requestFake.write.args[0].toString('utf8'), body); | ||
}); | ||
@@ -288,4 +291,5 @@ it('should have called the callback', function () { | ||
}); | ||
it('should write the request body to the request', function () { | ||
sinon.assert.calledWith(requestFake.write, body); | ||
it('should write the request body buffer to the request', function () { | ||
sinon.assert.calledOnce(requestFake.write); | ||
assert.equal(requestFake.write.args[0].toString('utf8'), body); | ||
}); | ||
@@ -292,0 +296,0 @@ it('should have called the callback', function () { |
@@ -32,3 +32,4 @@ var assert = require('assert'); | ||
encoding: 'UTF-8' | ||
} | ||
}, | ||
allowSurrogateChars: true | ||
})); | ||
@@ -35,0 +36,0 @@ }); |
{ | ||
"name": "esendex", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "Esendex Node.js client library.", | ||
@@ -33,3 +33,3 @@ "main": "build/lib/index.js", | ||
"dependencies": { | ||
"xml2js": "^0.4.15" | ||
"xml2js": "codesleuth/node-xml2js#62554a7" | ||
}, | ||
@@ -46,8 +46,8 @@ "devDependencies": { | ||
"proxyquire": "^1.7.3", | ||
"rimraf": "^2.4.3", | ||
"rimraf": "^2.4.4", | ||
"sinon": "^1.17.2", | ||
"source-map-support": "^0.3.3", | ||
"source-map-support": "^0.4.0", | ||
"tsd": "^0.6.5", | ||
"typescript": "^1.6.2" | ||
"typescript": "^1.7.3" | ||
} | ||
} |
@@ -59,6 +59,9 @@ import * as http from 'http' | ||
}; | ||
var dataBuf: Buffer; | ||
if (isPost) { | ||
dataBuf = data ? new Buffer(data, 'utf8') : null; | ||
headers['Content-Type'] = 'application/xml'; | ||
headers['Content-Length'] = data ? data.length : 0; | ||
headers['Content-Length'] = data ? dataBuf.length : 0; | ||
} | ||
@@ -85,3 +88,3 @@ | ||
if (isPost && data) req.write(data); | ||
if (isPost && data) req.write(dataBuf); | ||
req.end(); | ||
@@ -88,0 +91,0 @@ } |
@@ -13,3 +13,4 @@ import {Builder} from 'xml2js'; | ||
encoding: 'UTF-8' | ||
} | ||
}, | ||
allowSurrogateChars: true | ||
}); | ||
@@ -16,0 +17,0 @@ } |
@@ -36,2 +36,3 @@ import * as express from 'express' | ||
this.app.get('/v1.0/messageheaders', this.MessageHeadersEndpoint.bind(this)); | ||
this.app.get('/v1.0/messageheaders/CDEB3533-1F76-46D7-A2A9-0DAF8290F7FC', this.MessageHeaderEndpoint.bind(this)); | ||
this.app.post('/v1.0/messagedispatcher', textBodyParser, this.MessageDispatcherEndpoint.bind(this)); | ||
@@ -58,2 +59,8 @@ } | ||
private MessageHeaderEndpoint(req: express.Request, res: express.Response) { | ||
res.status(200); | ||
res.set('Content-Type', 'application/xml'); | ||
createReadStream(joinPath(__dirname, '..', '..', 'responses', 'messageheaders-get-single.xml')).pipe(res); | ||
} | ||
private MessageHeadersEndpoint(req: express.Request, res: express.Response) { | ||
@@ -60,0 +67,0 @@ res.status(200); |
@@ -56,2 +56,33 @@ import * as assert from 'assert' | ||
describe('get single message', function () { | ||
var message; | ||
before(function (done) { | ||
var options = { id: 'CDEB3533-1F76-46D7-A2A9-0DAF8290F7FC' }; | ||
esendex.messages.get(options, function (err, messageheader) { | ||
if (err) return done(err); | ||
message = messageheader; | ||
done(); | ||
}); | ||
}); | ||
it('should return the expected messageheader', function () { | ||
assert.strictEqual(message.id, 'CDEB3533-1F76-46D7-A2A9-0DAF8290F7FC'); | ||
assert.strictEqual(message.uri, 'http://api.esendex.com/v1.0/messageheaders/CDEB3533-1F76-46D7-A2A9-0DAF8290F7FC/'); | ||
assert.strictEqual(message.status, 'Delivered'); | ||
assert.strictEqual(message.laststatusat, '2010-01-01T12:00:05.000'); | ||
assert.strictEqual(message.submittedat, '2010-01-01T12:00:02.000'); | ||
assert.strictEqual(message.type, 'SMS'); | ||
assert.strictEqual(message.to.phonenumber, '447700900123'); | ||
assert.strictEqual(message.from.phonenumber, '447700900654'); | ||
assert.strictEqual(message.summary, 'Testing REST API'); | ||
assert.strictEqual(message.body.uri, 'http://api.esendex.com/v1.0/messageheaders/CDEB3533-1F76-46D7-A2A9-0DAF8290F7FC/body'); | ||
assert.strictEqual(message.direction, 'Outbound'); | ||
assert.strictEqual(message.parts, '1'); | ||
assert.strictEqual(message.username, 'user@example.com'); | ||
}); | ||
}); | ||
describe('send a message', function () { | ||
@@ -67,3 +98,3 @@ | ||
to: '447000000000', | ||
body: "Every message matters!" | ||
body: 'Every message matters!' | ||
}] | ||
@@ -98,2 +129,43 @@ }; | ||
describe('send a unicode message', function () { | ||
var response; | ||
var loggedRequest; | ||
before(function (done) { | ||
var messages = { | ||
accountreference: 'EX0123456', | ||
characterset: 'Unicode', | ||
message: [{ | ||
to: '447000000000', | ||
body: 'Every 🐳 matters!' | ||
}] | ||
}; | ||
esendex.messages.send(messages, function (err, res) { | ||
if (err) return done(err); | ||
response = res; | ||
loggedRequest = esendexFake.dispatcherRequests.length === 0 ? null : esendexFake.dispatcherRequests[0]; | ||
done(); | ||
}); | ||
}); | ||
it('should return the batch ID of the sent message', function () { | ||
assert.strictEqual(response.batchid, 'F8BF9867-FF81-49E4-ACC5-774DE793B776'); | ||
}); | ||
it('should return the messageheader ID and uri of the sent message', function () { | ||
assert.strictEqual(response.messageheader[0].id, '1183C73D-2E62-4F60-B610-30F160BDFBD5'); | ||
assert.strictEqual(response.messageheader[0].uri, 'https://api.esendex.com/v1.0/messageheaders/1183C73D-2E62-4F60-B610-30F160BDFBD5'); | ||
}); | ||
it('should return an array of sent message headers', function () { | ||
assert.ok(isArray(response.messageheader)); | ||
}); | ||
it('should return one sent message header', function () { | ||
assert.strictEqual(response.messageheader.length, 1); | ||
}); | ||
}); | ||
}); |
@@ -205,2 +205,3 @@ import assert = require('assert') | ||
var body; | ||
var bodyLength; | ||
var responseBody; | ||
@@ -213,6 +214,7 @@ var requestFake; | ||
path = '1/2/3/4'; | ||
body = 'some xml body'; | ||
body = 'some unicode xml 🐳 body'; | ||
bodyLength = 26; | ||
responseBody = 'This is the response body content'; | ||
requestFake = { on: sinon.stub(), end: sinon.stub(), write: sinon.expectation.create().once() }; | ||
requestFake = { on: sinon.stub(), end: sinon.stub(), write: sinon.spy() }; | ||
@@ -249,8 +251,9 @@ requestStub = sinon.stub().callsArg(1).returns(requestFake); | ||
'Content-Type': 'application/xml', | ||
'Content-Length': body.length | ||
'Content-Length': bodyLength | ||
}})); | ||
}); | ||
it('should write the request body to the request', function () { | ||
sinon.assert.calledWith(requestFake.write, body); | ||
it('should write the request body buffer to the request', function () { | ||
sinon.assert.calledOnce(requestFake.write); | ||
assert.equal(requestFake.write.args[0].toString('utf8'), body); | ||
}); | ||
@@ -372,4 +375,5 @@ | ||
it('should write the request body to the request', function () { | ||
sinon.assert.calledWith(requestFake.write, body); | ||
it('should write the request body buffer to the request', function () { | ||
sinon.assert.calledOnce(requestFake.write); | ||
assert.equal(requestFake.write.args[0].toString('utf8'), body); | ||
}); | ||
@@ -376,0 +380,0 @@ |
@@ -41,3 +41,4 @@ import * as assert from 'assert' | ||
encoding: 'UTF-8' | ||
} | ||
}, | ||
allowSurrogateChars: true | ||
})); | ||
@@ -44,0 +45,0 @@ }); |
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"sourceMaps": true | ||
"sourceMap": true | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
GitHub dependency
Supply chain riskContains a dependency which resolves to a GitHub URL. Dependencies fetched from GitHub specifiers are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
389856
122
4749
1
3
- Removedsax@1.4.1(transitive)
- Removedxml2js@0.4.23(transitive)
- Removedxmlbuilder@11.0.1(transitive)