aerogear-sender-client
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -27,5 +27,4 @@ /* AeroGear JavaScript Library | ||
// Otherwise the 'http' module is stashed | ||
var caller = (serverSettings.protocol === "https:") ? https : http; | ||
var that = this, | ||
var caller = (serverSettings.protocol === "https:") ? https : http, | ||
that = this, | ||
req = caller.request( serverSettings, function( res ) { | ||
@@ -35,2 +34,17 @@ | ||
that.emit( "error", res.statusCode ); | ||
} else if( res.statusCode === 301 || res.statusCode === 302 || res.statusCode === 303 ) { | ||
//Moved Status, Need to resend | ||
if( !res.headers.location ) { | ||
that.emit( "error", "redirect url is not available" ); | ||
} else { | ||
var url = urlParser.parse( res.headers.location ); | ||
//Better way i think | ||
serverSettings.protocol = url.protocol; | ||
serverSettings.hostname = url.hostname; | ||
serverSettings.port = url.port; | ||
serverSettings.path = url.pathname; | ||
send.call( that, serverSettings, message ); | ||
} | ||
} else { | ||
@@ -68,3 +82,2 @@ res.setEncoding('utf8'); | ||
var AeroGear = {}; | ||
@@ -71,0 +84,0 @@ |
{ | ||
"name": "aerogear-sender-client", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Sender api for the AeroGear Unified Push server", | ||
@@ -5,0 +5,0 @@ "homepage": "https://github.com/aerogear/aerogear-unifiedpush-nodejs-client", |
@@ -134,1 +134,151 @@ var chai = require( "chai" ), | ||
}); | ||
describe( "Sender - Handle Moved Status Codes", function() { | ||
var sender = AeroGear.Sender( "http://localhost:8080/ag-push" ), | ||
applicationID = "12345", | ||
masterSecret = "54321", | ||
settings = {}, | ||
message = {}; | ||
beforeEach( function() { | ||
settings = {}; | ||
message = {}; | ||
}); | ||
describe( "Endpoint returns moved", function() { | ||
it( "broadcast should be called with success", function( done ) { | ||
nock( "http://localhost:8080" ) | ||
.matchHeader('Accept', 'application/json') | ||
.matchHeader('Content-type', 'application/json') | ||
.post( "/ag-push/rest/sender/broadcast" ) | ||
.reply( 302,{},{'location': "http://localhost:8080/rest/new/sender"} ) | ||
.post( "/rest/new/sender" ) | ||
.reply( 200, {} ); | ||
settings.applicationID = applicationID; | ||
settings.masterSecret = masterSecret; | ||
sender.broadcast( message, settings ).on( "success", function( response ) { | ||
expect( response ).to.be.ok; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe( "Endpoint returns moved, with no new location", function() { | ||
it( "broadcast should be called with error", function( done ) { | ||
nock( "http://localhost:8080" ) | ||
.matchHeader('Accept', 'application/json') | ||
.matchHeader('Content-type', 'application/json') | ||
.post( "/ag-push/rest/sender/broadcast" ) | ||
.reply( 302,{},{} ); | ||
settings.applicationID = applicationID; | ||
settings.masterSecret = masterSecret; | ||
sender.broadcast( message, settings ).on( "error", function( error ) { | ||
expect( error ).to.be.ok; | ||
expect( error ).to.equal( "redirect url is not available" ); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
// describe( "Endpoint returns moved", function() { | ||
// it( "sendTo should be called with success", function( done ) { | ||
// nock( "http://localhost:8080" ) | ||
// .matchHeader('Accept', 'application/json') | ||
// .matchHeader('Content-type', 'application/json') | ||
// .post( "/ag-push/rest/sender/selected" ) | ||
// .reply( 302,{},{'location': "http://localhost:8080/rest/new/sender"} ) | ||
// .post( "/rest/new/sender" ) | ||
// .reply( 200, {} ); | ||
// settings.applicationID = applicationID; | ||
// settings.masterSecret = masterSecret; | ||
// sender.sendTo( message, settings ).on( "success", function( response ) { | ||
// expect( response ).to.be.ok; | ||
// done(); | ||
// }); | ||
// }); | ||
// }); | ||
// describe( "Endpoint returns moved, with no new location", function() { | ||
// it( "sendTo should be called with error", function( done ) { | ||
// nock( "http://localhost:8080" ) | ||
// .matchHeader('Accept', 'application/json') | ||
// .matchHeader('Content-type', 'application/json') | ||
// .post( "/ag-push/rest/sender/selected" ) | ||
// .reply( 302,{},{} ); | ||
// settings.applicationID = applicationID; | ||
// settings.masterSecret = masterSecret; | ||
// sender.sendTo( message, settings ).on( "error", function( error ) { | ||
// expect( error ).to.be.ok; | ||
// expect( error ).to.equal( "redirect url is not available" ); | ||
// done(); | ||
// }); | ||
// }); | ||
// }); | ||
}); | ||
describe( "Sender - Handle Moved Status Codes", function() { | ||
var sender = AeroGear.Sender( "http://localhost:8080/ag-push" ), | ||
applicationID = "12345", | ||
masterSecret = "54321", | ||
settings = {}, | ||
message = {}; | ||
beforeEach( function() { | ||
settings = {}; | ||
message = {}; | ||
}); | ||
describe( "Endpoint returns moved", function() { | ||
it( "sendTo should be called with success", function( done ) { | ||
nock( "http://localhost:8080" ) | ||
.matchHeader('Accept', 'application/json') | ||
.matchHeader('Content-type', 'application/json') | ||
.post( "/ag-push/rest/sender/selected" ) | ||
.reply( 302,{},{'location': "http://localhost:8080/rest/new/sender"} ) | ||
.post( "/rest/new/sender" ) | ||
.reply( 200, {} ); | ||
settings.applicationID = applicationID; | ||
settings.masterSecret = masterSecret; | ||
sender.sendTo( message, settings ).on( "success", function( response ) { | ||
expect( response ).to.be.ok; | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe( "Endpoint returns moved, with no new location", function() { | ||
it( "sendTo should be called with error", function( done ) { | ||
nock( "http://localhost:8080" ) | ||
.matchHeader('Accept', 'application/json') | ||
.matchHeader('Content-type', 'application/json') | ||
.post( "/ag-push/rest/sender/selected" ) | ||
.reply( 302,{},{} ); | ||
settings.applicationID = applicationID; | ||
settings.masterSecret = masterSecret; | ||
sender.sendTo( message, settings ).on( "error", function( error ) { | ||
expect( error ).to.be.ok; | ||
expect( error ).to.equal( "redirect url is not available" ); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
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
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
131243
4837