Added good tests
This commit is contained in:
@@ -126,24 +126,38 @@ Example code below:
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
### Events
|
## Session Events
|
||||||
|
|
||||||
#### connect
|
#### connect
|
||||||
|
|
||||||
Triggered when the socket is connected to a client
|
Triggered when the socket is connected to a client. This is server specific.
|
||||||
|
|
||||||
#### data
|
#### data
|
||||||
|
|
||||||
Triggered when data is comming in on the socket
|
Triggered when data is comming in on the socket.
|
||||||
|
|
||||||
#### close
|
#### close
|
||||||
|
|
||||||
Triggered when the socket is closed
|
Triggered when the socket is closed.
|
||||||
|
|
||||||
#### error
|
#### error
|
||||||
|
|
||||||
Generic error event
|
Generic error event.
|
||||||
|
|
||||||
#### sms
|
#### sms
|
||||||
|
|
||||||
Incoming SMS
|
Incoming SMS.
|
||||||
|
|
||||||
|
#### incomingPdu
|
||||||
|
|
||||||
|
Incoming PDU.
|
||||||
|
|
||||||
|
#### incomingPduObj
|
||||||
|
|
||||||
|
Incoming PDU Object. Same as incomingPdu, but it have been converted into an object instead of a buffer.
|
||||||
|
|
||||||
|
## Session commands
|
||||||
|
|
||||||
|
### send
|
||||||
|
|
||||||
|
Send a PDU to the remote.
|
||||||
+2
-2
@@ -51,7 +51,7 @@ function smsResp(status, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sms.pduObjs === undefined) {
|
if (sms.pduObjs === undefined) {
|
||||||
sms.pduObjs = [sms.pduObj];
|
sms.pduObjs = [{'pduObj': sms.pduObj}];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build async tasks to run the responses in parallel
|
// Build async tasks to run the responses in parallel
|
||||||
@@ -355,7 +355,7 @@ function session(sock) {
|
|||||||
* to - international format
|
* to - international format
|
||||||
* message - string
|
* message - string
|
||||||
* dlr - boolean defaults to false
|
* dlr - boolean defaults to false
|
||||||
* @param func callback(err, smsId, retPduObj)
|
* @param func callback(err, smsIds, retPduObj)
|
||||||
*/
|
*/
|
||||||
returnObj.sendSms = function(smsOptions, callback) {
|
returnObj.sendSms = function(smsOptions, callback) {
|
||||||
var pduObj = {};
|
var pduObj = {};
|
||||||
|
|||||||
+59
-14
@@ -17,12 +17,12 @@ describe('Sessions', function() {
|
|||||||
|
|
||||||
it('should setup a basic server and client and then directly unbinding again', function(done) {
|
it('should setup a basic server and client and then directly unbinding again', function(done) {
|
||||||
portfinder.getPort(function(err, freePort) {
|
portfinder.getPort(function(err, freePort) {
|
||||||
assert( ! err, 'Error should be negative');
|
assert( ! err, 'Error should not be negative');
|
||||||
|
|
||||||
larvitsmpp.server({
|
larvitsmpp.server({
|
||||||
'port': freePort
|
'port': freePort
|
||||||
}, function(err, serverSession) {
|
}, function(err, serverSession) {
|
||||||
assert( ! err, 'Error should be negative');
|
assert( ! err, 'Error should not be negative');
|
||||||
|
|
||||||
serverSession.on('close', function() {
|
serverSession.on('close', function() {
|
||||||
// Manually destroy the server socket
|
// Manually destroy the server socket
|
||||||
@@ -33,7 +33,7 @@ describe('Sessions', function() {
|
|||||||
larvitsmpp.client({
|
larvitsmpp.client({
|
||||||
'port': freePort
|
'port': freePort
|
||||||
}, function(err, clientSession) {
|
}, function(err, clientSession) {
|
||||||
assert( ! err, 'Error should be negative');
|
assert( ! err, 'Error should not be negative');
|
||||||
|
|
||||||
// Gracefully close connection
|
// Gracefully close connection
|
||||||
clientSession.unbind();
|
clientSession.unbind();
|
||||||
@@ -45,13 +45,13 @@ describe('Sessions', function() {
|
|||||||
|
|
||||||
it('should setup a server with auth and client trying to connect with wrong username and password', function(done) {
|
it('should setup a server with auth and client trying to connect with wrong username and password', function(done) {
|
||||||
portfinder.getPort(function(err, freePort) {
|
portfinder.getPort(function(err, freePort) {
|
||||||
assert( ! err, 'Error should be negative');
|
assert( ! err, 'Error should not be negative');
|
||||||
|
|
||||||
larvitsmpp.server({
|
larvitsmpp.server({
|
||||||
'port': freePort,
|
'port': freePort,
|
||||||
'checkuserpass': checkuserpass
|
'checkuserpass': checkuserpass
|
||||||
}, function(err, serverSession) {
|
}, function(err, serverSession) {
|
||||||
assert( ! err, 'Error should be negative');
|
assert( ! err, 'Error should not be negative');
|
||||||
|
|
||||||
serverSession.on('close', function() {
|
serverSession.on('close', function() {
|
||||||
// Manually destroy the server socket
|
// Manually destroy the server socket
|
||||||
@@ -71,13 +71,13 @@ describe('Sessions', function() {
|
|||||||
|
|
||||||
it('should setup a server with auth and client trying to connect with correct username and password', function(done) {
|
it('should setup a server with auth and client trying to connect with correct username and password', function(done) {
|
||||||
portfinder.getPort(function(err, freePort) {
|
portfinder.getPort(function(err, freePort) {
|
||||||
assert( ! err, 'Error should be negative');
|
assert( ! err, 'Error should not be negative');
|
||||||
|
|
||||||
larvitsmpp.server({
|
larvitsmpp.server({
|
||||||
'port': freePort,
|
'port': freePort,
|
||||||
'checkuserpass': checkuserpass
|
'checkuserpass': checkuserpass
|
||||||
}, function(err, serverSession) {
|
}, function(err, serverSession) {
|
||||||
assert( ! err, 'Error should be negative');
|
assert( ! err, 'Error should not be negative');
|
||||||
|
|
||||||
serverSession.on('close', function() {
|
serverSession.on('close', function() {
|
||||||
// Manually destroy the server socket
|
// Manually destroy the server socket
|
||||||
@@ -90,7 +90,7 @@ describe('Sessions', function() {
|
|||||||
'username': 'foo',
|
'username': 'foo',
|
||||||
'password': 'bar'
|
'password': 'bar'
|
||||||
}, function(err, clientSession) {
|
}, function(err, clientSession) {
|
||||||
assert( ! err, 'Error should be negative');
|
assert( ! err, 'Error should not be negative');
|
||||||
|
|
||||||
// Gracefully close connection
|
// Gracefully close connection
|
||||||
clientSession.unbind();
|
clientSession.unbind();
|
||||||
@@ -100,20 +100,65 @@ describe('Sessions', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
it('should try sending a simple sms', function(done) {
|
||||||
it('should try to send submit_sm while not logged in and get a failure return PDU back', function(done) {
|
portfinder.getPort(function(err, freePort) {
|
||||||
|
assert( ! err, 'Error should not be negative');
|
||||||
|
|
||||||
|
larvitsmpp.server({
|
||||||
|
'port': freePort
|
||||||
|
}, function(err, serverSession) {
|
||||||
|
assert( ! err, 'Error should not be negative');
|
||||||
|
|
||||||
|
serverSession.on('sms', function(sms) {
|
||||||
|
sms.smsId = 2343;
|
||||||
|
|
||||||
|
assert(sms.from === 'foo', 'SMS from should be "foo"');
|
||||||
|
assert(sms.to === '46709771337', 'SMS to should be "46709771337"');
|
||||||
|
assert(sms.message === 'hello world', 'SMS message should be "hello world"');
|
||||||
|
assert(sms.dlr === false, 'DLR should be boolean false');
|
||||||
|
assert(sms.pduObj.cmdId === 4, 'SMS pduObj cmdId should be 4');
|
||||||
|
|
||||||
|
sms.sendResp(function(err, retPdus) {
|
||||||
|
assert( ! err, 'Error should not be negative');
|
||||||
|
|
||||||
|
assert(retPdus[0].toString('hex') === '000000158000000400000000000000023233343300', 'The return PDU should be "000000158000000400000000000000023233343300"');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should send a bind_transceiver to a new session and get logged in', function(done) {
|
serverSession.on('close', function() {
|
||||||
|
// Manually destroy the server socket
|
||||||
|
serverSession.sock.destroy();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should send a bind_transceiver to a new session with a login-method and fail due to wrong username and password', function(done) {
|
larvitsmpp.client({
|
||||||
|
'port': freePort
|
||||||
|
}, function(err, clientSession) {
|
||||||
|
assert( ! err, 'Error should not be negative');
|
||||||
|
|
||||||
|
clientSession.sendSms({
|
||||||
|
'from': 'foo',
|
||||||
|
'to': '46709771337',
|
||||||
|
'message': 'hello world'
|
||||||
|
}, function(err, smsIds, retPduObj) {
|
||||||
|
assert( ! err, 'Error should not be negative');
|
||||||
|
|
||||||
|
assert(smsIds instanceof Array, 'smsIds should be an Array');
|
||||||
|
assert(smsIds[0] === '2343', 'Given smsId should be "2343"');
|
||||||
|
assert(retPduObj.cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
|
||||||
|
assert(retPduObj.cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
|
||||||
|
|
||||||
|
// Gracefully close connection
|
||||||
|
clientSession.unbind();
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should send a bind_transceiver to a new session with a login-method and succeed with correct username and password', function(done) {
|
/*it('should try sending a long sms', function(done) {
|
||||||
|
|
||||||
});*/
|
});*/
|
||||||
|
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user