Skip to content

Commit

Permalink
Moves Files adapters to external packages
Browse files Browse the repository at this point in the history
  • Loading branch information
flovilmart committed Mar 24, 2016
1 parent ee8f85b commit 00f2aac
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 536 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"license": "BSD-3-Clause",
"dependencies": {
"apn": "^1.7.5",
"aws-sdk": "~2.2.33",
"babel-polyfill": "^6.5.0",
"babel-runtime": "^6.5.0",
"bcrypt-nodejs": "0.0.3",
Expand All @@ -28,14 +27,16 @@
"commander": "^2.9.0",
"deepcopy": "^0.6.1",
"express": "^4.13.4",
"gcloud": "^0.28.0",
"lru-cache": "^4.0.0",
"mailgun-js": "^0.7.7",
"mime": "^1.3.4",
"mongodb": "~2.1.0",
"multer": "^1.1.0",
"node-gcm": "^0.14.0",
"parse": "^1.8.0",
"parse-server-fs-adapter": "^1.0.0",
"parse-server-gcs-adapter": "^1.0.0",
"parse-server-s3-adapter": "^1.0.0",
"redis": "^2.5.0-1",
"request": "^2.65.0",
"tv4": "^1.2.7",
Expand Down
6 changes: 3 additions & 3 deletions spec/AdapterLoader.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

var loadAdapter = require("../src/Adapters/AdapterLoader").loadAdapter;
var FilesAdapter = require("../src/Adapters/Files/FilesAdapter").default;
var FilesAdapter = require("parse-server-fs-adapter").default;
var S3Adapter = require("parse-server-s3-adapter").default;
var GCSAdapter = require("parse-server-gcs-adapter").default;
var ParsePushAdapter = require("../src/Adapters/Push/ParsePushAdapter");
var S3Adapter = require("../src/Adapters/Files/S3Adapter").default;
var GCSAdapter = require("../src/Adapters/Files/GCSAdapter").default;

describe("AdapterLoader", ()=>{

Expand Down
72 changes: 19 additions & 53 deletions spec/FilesController.spec.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,30 @@
var FilesController = require('../src/Controllers/FilesController').FilesController;
var GridStoreAdapter = require("../src/Adapters/Files/GridStoreAdapter").GridStoreAdapter;
var S3Adapter = require("../src/Adapters/Files/S3Adapter").S3Adapter;
var GCSAdapter = require("../src/Adapters/Files/GCSAdapter").GCSAdapter;
var FileSystemAdapter = require("../src/Adapters/Files/FileSystemAdapter").FileSystemAdapter;
var Config = require("../src/Config");

var FCTestFactory = require("./FilesControllerTestFactory");
var FilesController = require('../src/Controllers/FilesController').default;


// Small additional tests to improve overall coverage
describe("FilesController",()=>{

// Test the grid store adapter
var gridStoreAdapter = new GridStoreAdapter('mongodb://localhost:27017/parse');
FCTestFactory.testAdapter("GridStoreAdapter", gridStoreAdapter);

if (process.env.S3_ACCESS_KEY && process.env.S3_SECRET_KEY) {

// Test the S3 Adapter
var s3Adapter = new S3Adapter(process.env.S3_ACCESS_KEY, process.env.S3_SECRET_KEY, 'parse.server.tests');

FCTestFactory.testAdapter("S3Adapter",s3Adapter);

// Test S3 with direct access
var s3DirectAccessAdapter = new S3Adapter(process.env.S3_ACCESS_KEY, process.env.S3_SECRET_KEY, 'parse.server.tests', {
directAccess: true
});

FCTestFactory.testAdapter("S3AdapterDirect", s3DirectAccessAdapter);

} else if (!process.env.TRAVIS) {
console.log("set S3_ACCESS_KEY and S3_SECRET_KEY to test S3Adapter")
}

if (process.env.GCP_PROJECT_ID && process.env.GCP_KEYFILE_PATH && process.env.GCS_BUCKET) {

// Test the GCS Adapter
var gcsAdapter = new GCSAdapter(process.env.GCP_PROJECT_ID, process.env.GCP_KEYFILE_PATH, process.env.GCS_BUCKET);

FCTestFactory.testAdapter("GCSAdapter", gcsAdapter);
describe("FilesController",() =>{
it("should properly expand objects", (done) => {

// Test GCS with direct access
var gcsDirectAccessAdapter = new GCSAdapter(process.env.GCP_PROJECT_ID, process.env.GCP_KEYFILE_PATH, process.env.GCS_BUCKET, {
directAccess: true
});
var config = new Config(Parse.applicationId);
var gridStoreAdapter = new GridStoreAdapter('mongodb://localhost:27017/parse');
let filesController = new FilesController(gridStoreAdapter)
var result = filesController.expandFilesInObject(config, function(){});

FCTestFactory.testAdapter("GCSAdapterDirect", gcsDirectAccessAdapter);
expect(result).toBeUndefined();

} else if (!process.env.TRAVIS) {
console.log("set GCP_PROJECT_ID, GCP_KEYFILE_PATH, and GCS_BUCKET to test GCSAdapter")
}
var fullFile = {
type: '__type',
url: "http://an.url"
}

try {
// Test the file system adapter
var fsAdapter = new FileSystemAdapter({
filesSubDirectory: 'sub1/sub2'
});
var anObject = {
aFile: fullFile
}
filesController.expandFilesInObject(config, anObject);
expect(anObject.aFile.url).toEqual("http://an.url");

FCTestFactory.testAdapter("FileSystemAdapter", fsAdapter);
} catch (e) {
console.log("Give write access to the file system to test the FileSystemAdapter. Error: " + e);
}
done();
})
});
72 changes: 0 additions & 72 deletions spec/FilesControllerTestFactory.js

This file was deleted.

120 changes: 0 additions & 120 deletions src/Adapters/Files/FileSystemAdapter.js

This file was deleted.

16 changes: 8 additions & 8 deletions src/Adapters/Files/FilesAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@

export class FilesAdapter {
/* this method is responsible to store the file in order to be retrived later by it's file name
*
*
*
*
* @param config the current config
* @param filename the filename to save
* @param data the buffer of data from the file
* @param contentType the supposed contentType
* @discussion the contentType can be undefined if the controller was not able to determine it
*
* @discussion the contentType can be undefined if the controller was not able to determine it
*
* @return a promise that should fail if the storage didn't succeed
*
*
*/
createFile(config, filename: string, data, contentType: string) { }
createFile(filename: string, data, contentType: string) { }

deleteFile(config, filename) { }
deleteFile(filename) { }

getFileData(config, filename) { }
getFileData(filename) { }

getFileLocation(config, filename) { }
}
Expand Down
Loading

0 comments on commit 00f2aac

Please sign in to comment.