Added tests for long messages

This commit is contained in:
2015-06-04 00:27:42 +02:00
parent f15d89283d
commit 4d1d44ff55
2 changed files with 84 additions and 20 deletions
+69 -6
View File
@@ -116,7 +116,7 @@ describe('Sessions', function() {
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');
assert(sms.pduObjs[0].pduObj.cmdId === 4, 'SMS pduObj cmdId should be 4');
sms.sendResp(function(err, retPdus) {
assert( ! err, 'Error should not be negative');
@@ -140,13 +140,14 @@ describe('Sessions', function() {
'from': 'foo',
'to': '46709771337',
'message': 'hello world'
}, function(err, smsIds, retPduObj) {
}, function(err, smsIds, retPduObjs) {
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"');
assert(retPduObjs instanceof Array, 'retPduObjs should be an Array');
assert(retPduObjs[0].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
assert(retPduObjs[0].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
// Gracefully close connection
clientSession.unbind();
@@ -157,8 +158,70 @@ describe('Sessions', function() {
});
});
/*it('should try sending a long sms', function(done) {
it('should try sending a long sms', 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 === 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised.', 'SMS message should be correct');
assert(sms.dlr === false, 'DLR should be boolean false');
assert(sms.pduObjs[0].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') === '00000017800000040000000000000002323334332d3100', 'Return PDU 0 is wrong');
assert(retPdus[1].toString('hex') === '00000017800000040000000000000003323334332d3200', 'Return PDU 1 is wrong');
assert(retPdus[2].toString('hex') === '00000017800000040000000000000004323334332d3300', 'Return PDU 2 is wrong');
});
});
serverSession.on('close', function() {
// Manually destroy the server socket
serverSession.sock.destroy();
});
});
larvitsmpp.client({
'port': freePort
}, function(err, clientSession) {
assert( ! err, 'Error should not be negative');
clientSession.sendSms({
'from': 'foo',
'to': '46709771337',
'message': 'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised.'
}, function(err, smsIds, retPduObjs) {
assert( ! err, 'Error should not be negative');
assert(smsIds instanceof Array, 'smsIds should be an Array');
assert(smsIds[0] === '2343-1', 'First smsId should be "2343-1"');
assert(smsIds[1] === '2343-2', 'Second smsId should be "2343-2"');
assert(smsIds[2] === '2343-3', 'Third smsId should be "2343-3"');
assert(smsIds[3] === undefined, 'Fourth smsId should be undefined');
assert(retPduObjs[0].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
assert(retPduObjs[0].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
assert(retPduObjs[1].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
assert(retPduObjs[1].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
assert(retPduObjs[2].cmdStatus === 'ESME_ROK', 'Command status should be "ESME_ROK"');
assert(retPduObjs[2].cmdName === 'submit_sm_resp', 'Command name should be "submit_sm_resp"');
// Gracefully close connection
clientSession.unbind();
done();
});
});
});
});
});