Merge pull request #248 from strongloop/drop-node

chore: update node support and versions
This commit is contained in:
Taranveer Virk 2018-06-14 15:47:19 -04:00 committed by GitHub
commit 537e1158d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 132 additions and 57 deletions

View File

@ -1,5 +1,5 @@
language: node_js
node_js:
- "4"
- "6"
- "8"
- "10"

View File

@ -2,7 +2,7 @@
"name": "loopback-component-storage",
"description": "Loopback Storage Service",
"engines": {
"node": ">=4"
"node": ">=6"
},
"version": "3.3.1",
"main": "index.js",
@ -12,22 +12,22 @@
"posttest": "npm run lint"
},
"dependencies": {
"async": "^2.1.5",
"async": "^2.6.1",
"debug": "^3.1.0",
"formidable": "^1.0.16",
"pkgcloud": "^1.1.0",
"strong-globalize": "^2.6.2",
"uuid": "^3.0.1"
"formidable": "^1.2.1",
"pkgcloud": "^1.5.0",
"strong-globalize": "^4.1.1",
"uuid": "^3.2.1"
},
"devDependencies": {
"eslint": "^3.17.1",
"eslint-config-loopback": "^8.0.0",
"express": "^4.11.0",
"loopback": "^3.0.0",
"mkdirp": "^0.5.0",
"mocha": "^3.2.0",
"supertest": "^3.0.0",
"semver": "^5.3.0"
"eslint": "^4.19.1",
"eslint-config-loopback": "^10.0.0",
"express": "^4.16.3",
"loopback": "^3.20.0",
"mkdirp": "^0.5.1",
"mocha": "^5.2.0",
"supertest": "^3.1.0",
"semver": "^5.5.0"
},
"repository": {
"type": "git",

View File

@ -24,13 +24,17 @@ describe('FileSystem based storage provider', function() {
describe('container apis', function() {
var client = null;
it('should require an existing directory as the root', function(done) {
client = new FileSystemProvider({root: path.join(__dirname, 'storage')});
client = new FileSystemProvider({
root: path.join(__dirname, 'storage'),
});
process.nextTick(done);
});
it('should complain if the root directory doesn\'t exist', function(done) {
try {
client = new FileSystemProvider({root: path.join(__dirname, '_storage')});
client = new FileSystemProvider({
root: path.join(__dirname, '_storage'),
});
process.nextTick(done.bind(null, 'Error'));
} catch (err) {
// Should be here
@ -94,7 +98,9 @@ describe('FileSystem based storage provider', function() {
describe('file apis', function() {
var fs = require('fs');
var client = new FileSystemProvider({root: path.join(__dirname, 'storage')});
var client = new FileSystemProvider({
root: path.join(__dirname, 'storage'),
});
it('should create a new container', function(done) {
client.createContainer({name: 'c1'}, function(err, container) {
@ -110,6 +116,7 @@ describe('FileSystem based storage provider', function() {
writer.on('error', done);
});
/* eslint-disable mocha/handle-done-callback */
it('should fail to upload a file with invalid characters', function(done) {
var writer = client.upload({container: 'c1', remote: 'a/f1.txt'});
fs.createReadStream(path.join(__dirname, 'files/f1.txt')).pipe(writer);
@ -124,20 +131,26 @@ describe('FileSystem based storage provider', function() {
cb = clearCb;
});
});
/* eslint-enable mocha/handle-done-callback */
it('should download a file', function(done) {
var reader = client.download({
container: 'c1',
remote: 'f1.txt',
});
reader.pipe(fs.createWriteStream(path.join(__dirname, 'files/f1_downloaded.txt')));
reader.pipe(
fs.createWriteStream(path.join(__dirname, 'files/f1_downloaded.txt'))
);
reader.on('end', done);
reader.on('error', done);
});
/* eslint-disable mocha/handle-done-callback */
it('should fail to download a file with invalid characters', function(done) {
var reader = client.download({container: 'c1', remote: 'a/f1.txt'});
reader.pipe(fs.createWriteStream(path.join(__dirname, 'files/a-f1_downloaded.txt')));
reader.pipe(
fs.createWriteStream(path.join(__dirname, 'files/a-f1_downloaded.txt'))
);
var cb = done;
var clearCb = function() {};
reader.on('error', function() {
@ -149,6 +162,7 @@ describe('FileSystem based storage provider', function() {
cb = clearCb;
});
});
/* eslint-enable mocha/handle-done-callback */
it('should get files for a container', function(done) {
client.getFiles('c1', function(err, files) {

View File

@ -199,14 +199,27 @@ describe('storage service', function() {
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200, function(err, res) {
assert.deepEqual(res.body, {'result': {'files': {'image': [
{'container': 'album1', 'name': 'test.jpg', 'type': 'image/jpeg', 'field': 'image', 'size': 60475},
]}, 'fields': {}}});
assert.deepEqual(res.body, {
result: {
files: {
image: [
{
container: 'album1',
name: 'test.jpg',
type: 'image/jpeg',
field: 'image',
size: 60475,
},
],
},
fields: {},
},
});
done();
});
});
it('fails to upload using dotdot file path', function(done) {
it('fails to upload using dotdot file path (1)', function(done) {
request('http://localhost:' + app.get('port'))
.post('/containers/%2e%2e/upload')
.expect(200, function(err, res) {
@ -215,7 +228,7 @@ describe('storage service', function() {
});
});
it('fails to upload using dotdot file path', function(done) {
it('fails to upload using dotdot file path (2)', function(done) {
request('http://localhost:' + app.get('port'))
.post('%2e%2e/containers/upload')
.expect(200, function(err, res) {
@ -224,7 +237,7 @@ describe('storage service', function() {
});
});
it('fails to upload using dotdot file path', function(done) {
it('fails to upload using dotdot file path (3)', function(done) {
request('http://localhost:' + app.get('port'))
.post('%2e%2e')
.expect(200, function(err, res) {
@ -233,7 +246,7 @@ describe('storage service', function() {
});
});
it('fails to upload using dotdot file path', function(done) {
it('fails to upload using dotdot file path (4)', function(done) {
request('http://localhost:' + app.get('port'))
.post('/containers/upload/%2e%2e')
.expect(200, function(err, res) {
@ -249,9 +262,24 @@ describe('storage service', function() {
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200, function(err, res) {
assert.deepEqual(res.body, {'result': {'files': {'image': [
{'container': 'album1', 'name': 'image-test.jpg', 'originalFilename': 'test.jpg', 'type': 'image/jpeg', 'field': 'image', 'acl': 'public-read', 'size': 60475},
]}, 'fields': {}}});
assert.deepEqual(res.body, {
result: {
files: {
image: [
{
container: 'album1',
name: 'image-test.jpg',
originalFilename: 'test.jpg',
type: 'image/jpeg',
field: 'image',
acl: 'public-read',
size: 60475,
},
],
},
fields: {},
},
});
done();
});
});
@ -291,10 +319,14 @@ describe('storage service', function() {
.set('Connection', 'keep-alive')
.expect('Content-Type', /json/)
.expect(400, function(err, res) {
var indexOfMsg =
res.body.error.message.toLowerCase().indexOf('no file');
assert.notEqual(indexOfMsg, -1,
'Error message does not contain \"no file\"');
var indexOfMsg = res.body.error.message
.toLowerCase()
.indexOf('no file');
assert.notEqual(
indexOfMsg,
-1,
'Error message does not contain "no file"'
);
done(err);
});
} else {
@ -304,8 +336,10 @@ describe('storage service', function() {
.set('Connection', 'keep-alive')
.expect('Content-Type', /json/)
.expect(500, function(err, res) {
assert.equal(res.body.error.message,
'bad content-type header, no content-type');
assert.equal(
res.body.error.message,
'bad content-type header, no content-type'
);
done(err);
});
}
@ -421,22 +455,37 @@ describe('storage service', function() {
});
});
it('should upload a file with custom route accessing directly to the ' +
'storage connector with renamer', function(done) {
request('http://localhost:' + app.get('port'))
.post('/custom/upload')
.attach('customimagefield', path.join(__dirname, './fixtures/test.jpg'))
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200, function(err, res) {
assert.deepEqual(res.body, {'result': {'files': {'customimagefield': [
{'container': 'album1', 'name': 'customimagefield_test.jpg',
'originalFilename': 'test.jpg', 'type': 'image/jpeg',
'field': 'customimagefield', 'size': 60475},
]}, 'fields': {}}});
done();
});
});
it(
'should upload a file with custom route accessing directly to the ' +
'storage connector with renamer',
function(done) {
request('http://localhost:' + app.get('port'))
.post('/custom/upload')
.attach('customimagefield', path.join(__dirname, './fixtures/test.jpg'))
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200, function(err, res) {
assert.deepEqual(res.body, {
result: {
files: {
customimagefield: [
{
container: 'album1',
name: 'customimagefield_test.jpg',
originalFilename: 'test.jpg',
type: 'image/jpeg',
field: 'customimagefield',
size: 60475,
},
],
},
fields: {},
},
});
done();
});
}
);
it('should upload a file with container param', function(done) {
request('http://localhost:' + app.get('port'))
@ -445,11 +494,23 @@ describe('storage service', function() {
.set('Accept', 'application/json')
.expect('Content-Type', /json/)
.expect(200, function(err, res) {
assert.deepEqual(res.body, {'result': {'files': {'customimagefield1': [
{'container': 'album1', 'name': 'customimagefield1_test.jpg',
'originalFilename': 'test.jpg', 'type': 'image/jpeg',
'field': 'customimagefield1', 'size': 60475},
]}, 'fields': {}}});
assert.deepEqual(res.body, {
result: {
files: {
customimagefield1: [
{
container: 'album1',
name: 'customimagefield1_test.jpg',
originalFilename: 'test.jpg',
type: 'image/jpeg',
field: 'customimagefield1',
size: 60475,
},
],
},
fields: {},
},
});
done();
});
});