pr changes
This commit is contained in:
parent
6e38446f1e
commit
1c49181acb
4 changed files with 46 additions and 15 deletions
|
@ -2,6 +2,7 @@ env:
|
|||
browser: true
|
||||
es6: true
|
||||
jquery: true
|
||||
mocha: true
|
||||
node: true
|
||||
|
||||
extends:
|
||||
|
|
|
@ -17,9 +17,7 @@
|
|||
"mozlog": "^2.1.1",
|
||||
"node-fetch": "^1.7.1",
|
||||
"path": "^0.12.7",
|
||||
"proxyquire": "^1.8.0",
|
||||
"redis": "^2.7.1",
|
||||
"sinon": "^2.3.2"
|
||||
"redis": "^2.7.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "^14.4.0",
|
||||
|
@ -29,11 +27,13 @@
|
|||
"eslint-plugin-node": "5.0.0",
|
||||
"eslint-plugin-security": "1.3.0",
|
||||
"htmllint-cli": "0.0.6",
|
||||
"mocha": "^3.4.2",
|
||||
"npm-run-all": "4.0.2",
|
||||
"prettier": "1.4.4",
|
||||
"proxyquire": "^1.8.0",
|
||||
"sinon": "^2.3.5",
|
||||
"stylelint": "7.11.0",
|
||||
"stylelint-config-standard": "16.0.0",
|
||||
"mocha": "^3.4.2",
|
||||
"watchify": "^3.9.0"
|
||||
},
|
||||
"engines": {
|
||||
|
|
|
@ -143,7 +143,12 @@ function awsGet(id) {
|
|||
Key: id
|
||||
};
|
||||
|
||||
try {
|
||||
return s3.getObject(params).createReadStream();
|
||||
} catch(err) {
|
||||
log.info('GetFailed', 'Get Object from s3 failed.');
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function awsSet(id, file, filename, url) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
const assert = require('assert');
|
||||
const sinon = require('sinon');
|
||||
const proxyquire = require('proxyquire');
|
||||
const crypto = require('crypto');
|
||||
|
||||
const conf = require('../server/config.js');
|
||||
conf.notLocalHost = true;
|
||||
|
@ -9,7 +10,7 @@ let redisStub = {};
|
|||
let exists = sinon.stub();
|
||||
let hget = sinon.stub();
|
||||
let hmset = sinon.stub();
|
||||
let expire = sinon.stub();
|
||||
let expire = sinon.spy();
|
||||
let del = sinon.stub();
|
||||
|
||||
redisStub.createClient = function() {
|
||||
|
@ -56,7 +57,7 @@ describe('Testing Length using aws', function() {
|
|||
it('Filesize returns properly if id exists', function() {
|
||||
s3Stub.headObject.callsArgWith(1, null, {ContentLength: 1});
|
||||
return storage.length('123')
|
||||
.then(reply => assert(reply === 1))
|
||||
.then(reply => assert.equal(reply, 1))
|
||||
.catch(err => assert.fail())
|
||||
})
|
||||
|
||||
|
@ -69,27 +70,51 @@ describe('Testing Length using aws', function() {
|
|||
});
|
||||
|
||||
describe('Testing Get using aws', function() {
|
||||
|
||||
it('Should not error out when the file exists', function() {
|
||||
let spy = sinon.spy();
|
||||
s3Stub.getObject.returns({
|
||||
createReadStream: function() { return 1; }
|
||||
createReadStream: spy
|
||||
});
|
||||
assert(storage.get('123') === 1);
|
||||
|
||||
storage.get('123');
|
||||
assert(spy.calledOnce);
|
||||
})
|
||||
|
||||
it('Should error when the file does not exist', function() {
|
||||
let err = function() { throw new Error(); }
|
||||
let spy = sinon.spy(err);
|
||||
s3Stub.getObject.returns({
|
||||
createReadStream: function() { return null; }
|
||||
createReadStream: spy
|
||||
});
|
||||
assert(storage.get('123') === null);
|
||||
|
||||
assert.equal(storage.get('123'), null);
|
||||
assert(spy.threw());
|
||||
})
|
||||
});
|
||||
|
||||
describe('Testing Set using aws', function() {
|
||||
beforeEach(function() {
|
||||
expire.reset();
|
||||
})
|
||||
|
||||
after(function() {
|
||||
crypto.randomBytes.restore();
|
||||
})
|
||||
|
||||
it('Should pass when the file is successfully uploaded and no bitly key', function() {
|
||||
conf.bitly_key = null;
|
||||
const buf = new Buffer(10);
|
||||
sinon.stub(crypto, 'randomBytes').returns(buf);
|
||||
s3Stub.upload.callsArgWith(1, null, {});
|
||||
return storage.set('123', {}, 'Filename.moz', 'url.com')
|
||||
.then(reply => assert(reply.url === 'url.com' && reply.uuid !== null))
|
||||
.then(reply => {
|
||||
assert.equal(reply.uuid, buf.toString('hex'));
|
||||
assert.equal(reply.url, 'url.com');
|
||||
assert.notEqual(reply.uuid, null);
|
||||
assert(expire.calledOnce);
|
||||
assert(expire.calledWith('123', 86400000));
|
||||
})
|
||||
.catch(err => assert.fail());
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue