add tests to insight storage + remove used code
This commit is contained in:
parent
d511103081
commit
bd698257f9
6 changed files with 124 additions and 93 deletions
|
|
@ -46,41 +46,96 @@ describe('insight storage plugin', function() {
|
|||
});
|
||||
});
|
||||
|
||||
var setupForRetrieval = function() {
|
||||
var setupForRetrieval = function(code) {
|
||||
requestMock.get.onFirstCall().callsArgWith(1, null, {
|
||||
statusCode: 200,
|
||||
statusCode: code || 200,
|
||||
getAllResponseHeaders: sinon.stub().returns(headers),
|
||||
}, data);
|
||||
};
|
||||
|
||||
it('should be able to retrieve data in a namespace', function(done) {
|
||||
describe('#getItem', function() {
|
||||
it('should be able to retrieve data in a namespace', function(done) {
|
||||
setupForRetrieval();
|
||||
|
||||
setupForRetrieval();
|
||||
storage.getItem(namespace, function(err, retrieved) {
|
||||
assert(!err);
|
||||
assert(retrieved === data);
|
||||
var url = requestMock.get.getCall(0).args[0].url;
|
||||
url.should.contain('?key=' + querystring.encode(namespace));
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
storage.getItem(namespace, function(err, retrieved) {
|
||||
assert(!err);
|
||||
assert(retrieved === data);
|
||||
return done();
|
||||
it('should be able to retrieve headers', function(done) {
|
||||
|
||||
setupForRetrieval();
|
||||
|
||||
storage.getItem(namespace, function(err, retrieved, headers) {
|
||||
assert(!err);
|
||||
headers['X-test'].should.equal('12');
|
||||
headers['X-testb'].should.equal('32');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able handle 403', function(done) {
|
||||
setupForRetrieval(403);
|
||||
// old profile query
|
||||
requestMock.get.onSecondCall().callsArgWith(1, null, {
|
||||
statusCode: 403,
|
||||
getAllResponseHeaders: sinon.stub().returns(headers),
|
||||
}, data);
|
||||
storage.getItem(namespace, function(err) {
|
||||
err.should.contain('PNOTFOUND');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able handle other error', function(done) {
|
||||
setupForRetrieval(510);
|
||||
storage.getItem(namespace, function(err) {
|
||||
err.should.contain('Unable');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able to retrieve headers', function(done) {
|
||||
describe('#removeItem', function() {
|
||||
|
||||
setupForRetrieval();
|
||||
it('should be able to delete Items', function(done) {
|
||||
setupForRetrieval();
|
||||
storage.removeItem(namespace, function(err) {
|
||||
should.not.exist(err);
|
||||
var url = requestMock.get.getCall(0).args[0].url;
|
||||
url.should.contain('?key=' + querystring.encode(namespace));
|
||||
|
||||
storage.getItem(namespace, function(err, retrieved, headers) {
|
||||
assert(!err);
|
||||
headers['X-test'].should.equal('12');
|
||||
headers['X-testb'].should.equal('32');
|
||||
return done();
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able handle 406', function(done) {
|
||||
setupForRetrieval(409);
|
||||
storage.removeItem(namespace, function(err) {
|
||||
err.should.contain('BADCREDENTIALS');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should be able handle other error', function(done) {
|
||||
setupForRetrieval(510);
|
||||
storage.removeItem(namespace, function(err) {
|
||||
err.should.contain('Unable');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
var setupForSave = function() {
|
||||
|
||||
var setupForSave = function(code) {
|
||||
requestMock.post.onFirstCall().callsArgWith(1, null, {
|
||||
statusCode: 200
|
||||
statusCode: code || 200
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -94,6 +149,33 @@ describe('insight storage plugin', function() {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
it('should handle 406 (quota)', function(done) {
|
||||
setupForSave(406);
|
||||
storage.setItem(namespace, data, function(err) {
|
||||
err.should.contain('OVERQUOTA');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle other error ', function(done) {
|
||||
setupForSave(505);
|
||||
storage.setItem(namespace, data, function(err) {
|
||||
err.should.contain('Unable');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle 409 (unauthorized)', function(done) {
|
||||
setupForSave(409);
|
||||
|
||||
storage.setItem(namespace, data, function(err) {
|
||||
err.should.contain('BADCREDENTIALS');
|
||||
return done();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
it('won\'t make an unnecessary request if old password can\'t work', function(done) {
|
||||
storage.setCredentials(email, '!');
|
||||
setupForRetrieval();
|
||||
|
|
@ -152,7 +234,7 @@ describe('insight storage plugin', function() {
|
|||
var url = requestMock.post.firstCall.args[0].url;
|
||||
var args = querystring.decode(receivedArgs);
|
||||
url.indexOf('change_passphrase').should.not.be.equal(-1);
|
||||
requestMock.post.firstCall.args[0].headers.Authorization.should.be.equal( new Buffer(email + ':' + oldSecret).toString('base64'));
|
||||
requestMock.post.firstCall.args[0].headers.Authorization.should.be.equal(new Buffer(email + ':' + oldSecret).toString('base64'));
|
||||
args.newPassphrase.should.be.equal(newSecret);
|
||||
done();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ describe('log utils', function() {
|
|||
log.setLevel('info');
|
||||
});
|
||||
|
||||
it('should log fatal', function() {
|
||||
it('should log .warn', function() {
|
||||
if (console.warn.restore)
|
||||
console.warn.restore();
|
||||
|
||||
|
|
@ -26,6 +26,23 @@ describe('log utils', function() {
|
|||
console.warn.restore();
|
||||
});
|
||||
|
||||
|
||||
it('should log .fatal', function() {
|
||||
if (console.log.restore)
|
||||
console.log.restore();
|
||||
|
||||
sinon.stub(console,'log');
|
||||
|
||||
log.setLevel('debug');
|
||||
log.fatal('hola',"que",'tal');
|
||||
|
||||
var arg = console.log.getCall(0).args[0];
|
||||
//arg.should.contain('util.log.js'); /* Firefox does not include the stack track */
|
||||
arg.should.contain('que');
|
||||
console.log.restore();
|
||||
});
|
||||
|
||||
|
||||
it('should not log debug', function() {
|
||||
sinon.stub(console,'log');
|
||||
log.setLevel('info');
|
||||
|
|
@ -38,4 +55,6 @@ describe('log utils', function() {
|
|||
log.getLevels().debug.should.equal(0);
|
||||
log.getLevels().fatal.should.equal(5);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue