2016-02-21 23:47:07 -05:00
|
|
|
|
2018-02-17 09:55:30 -05:00
|
|
|
const loadAdapter = require("../src/Adapters/AdapterLoader").loadAdapter;
|
|
|
|
|
const FilesAdapter = require("@parse/fs-files-adapter").default;
|
|
|
|
|
const S3Adapter = require("@parse/s3-files-adapter").default;
|
|
|
|
|
const ParsePushAdapter = require("@parse/push-adapter").default;
|
2017-02-21 15:06:45 -05:00
|
|
|
const Config = require('../src/Config');
|
2016-02-21 23:47:07 -05:00
|
|
|
|
2016-02-23 21:05:27 -05:00
|
|
|
describe("AdapterLoader", ()=>{
|
2016-03-07 00:47:08 -08:00
|
|
|
|
2016-02-21 23:47:07 -05:00
|
|
|
it("should instantiate an adapter from string in object", (done) => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapterPath = require('path').resolve("./spec/MockAdapter");
|
2016-02-21 23:47:07 -05:00
|
|
|
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapter = loadAdapter({
|
2016-02-21 23:47:07 -05:00
|
|
|
adapter: adapterPath,
|
2016-02-23 21:05:27 -05:00
|
|
|
options: {
|
2016-03-07 00:47:08 -08:00
|
|
|
key: "value",
|
2016-02-23 21:05:27 -05:00
|
|
|
foo: "bar"
|
|
|
|
|
}
|
2016-02-21 23:47:07 -05:00
|
|
|
});
|
2016-03-07 00:47:08 -08:00
|
|
|
|
2016-02-21 23:47:07 -05:00
|
|
|
expect(adapter instanceof Object).toBe(true);
|
|
|
|
|
expect(adapter.options.key).toBe("value");
|
|
|
|
|
expect(adapter.options.foo).toBe("bar");
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-03-07 00:47:08 -08:00
|
|
|
|
2016-02-21 23:47:07 -05:00
|
|
|
it("should instantiate an adapter from string", (done) => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapterPath = require('path').resolve("./spec/MockAdapter");
|
|
|
|
|
const adapter = loadAdapter(adapterPath);
|
2016-03-07 00:47:08 -08:00
|
|
|
|
2016-02-21 23:47:07 -05:00
|
|
|
expect(adapter instanceof Object).toBe(true);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-03-07 00:47:08 -08:00
|
|
|
|
2016-02-21 23:47:07 -05:00
|
|
|
it("should instantiate an adapter from string that is module", (done) => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapterPath = require('path').resolve("./src/Adapters/Files/FilesAdapter");
|
|
|
|
|
const adapter = loadAdapter({
|
2016-02-21 23:47:07 -05:00
|
|
|
adapter: adapterPath
|
|
|
|
|
});
|
2016-03-07 00:47:08 -08:00
|
|
|
|
2016-03-24 00:57:49 -04:00
|
|
|
expect(typeof adapter).toBe('object');
|
|
|
|
|
expect(typeof adapter.createFile).toBe('function');
|
|
|
|
|
expect(typeof adapter.deleteFile).toBe('function');
|
|
|
|
|
expect(typeof adapter.getFileData).toBe('function');
|
|
|
|
|
expect(typeof adapter.getFileLocation).toBe('function');
|
2016-08-12 13:25:24 -04:00
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should instantiate an adapter from npm module", (done) => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapter = loadAdapter({
|
2017-11-17 08:32:58 -05:00
|
|
|
module: '@parse/fs-files-adapter'
|
2016-08-12 13:25:24 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
expect(typeof adapter).toBe('object');
|
|
|
|
|
expect(typeof adapter.createFile).toBe('function');
|
|
|
|
|
expect(typeof adapter.deleteFile).toBe('function');
|
|
|
|
|
expect(typeof adapter.getFileData).toBe('function');
|
|
|
|
|
expect(typeof adapter.getFileLocation).toBe('function');
|
2016-02-21 23:47:07 -05:00
|
|
|
done();
|
|
|
|
|
});
|
2016-03-07 00:47:08 -08:00
|
|
|
|
2016-02-21 23:47:07 -05:00
|
|
|
it("should instantiate an adapter from function/Class", (done) => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapter = loadAdapter({
|
2016-02-21 23:47:07 -05:00
|
|
|
adapter: FilesAdapter
|
|
|
|
|
});
|
|
|
|
|
expect(adapter instanceof FilesAdapter).toBe(true);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-03-07 00:47:08 -08:00
|
|
|
|
2016-02-21 23:47:07 -05:00
|
|
|
it("should instantiate the default adapter from Class", (done) => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapter = loadAdapter(null, FilesAdapter);
|
2016-02-21 23:47:07 -05:00
|
|
|
expect(adapter instanceof FilesAdapter).toBe(true);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-03-07 00:47:08 -08:00
|
|
|
|
2016-02-21 23:47:07 -05:00
|
|
|
it("should use the default adapter", (done) => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const defaultAdapter = new FilesAdapter();
|
|
|
|
|
const adapter = loadAdapter(null, defaultAdapter);
|
2016-02-21 23:47:07 -05:00
|
|
|
expect(adapter instanceof FilesAdapter).toBe(true);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-03-07 00:47:08 -08:00
|
|
|
|
2016-02-21 23:47:07 -05:00
|
|
|
it("should use the provided adapter", (done) => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const originalAdapter = new FilesAdapter();
|
|
|
|
|
const adapter = loadAdapter(originalAdapter);
|
2016-02-21 23:47:07 -05:00
|
|
|
expect(adapter).toBe(originalAdapter);
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-03-07 00:47:08 -08:00
|
|
|
|
2016-02-23 21:05:27 -05:00
|
|
|
it("should fail loading an improperly configured adapter", (done) => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const Adapter = function(options) {
|
2016-02-23 21:05:27 -05:00
|
|
|
if (!options.foo) {
|
|
|
|
|
throw "foo is required for that adapter";
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapterOptions = {
|
2016-02-23 21:05:27 -05:00
|
|
|
param: "key",
|
|
|
|
|
doSomething: function() {}
|
|
|
|
|
};
|
2016-03-07 00:47:08 -08:00
|
|
|
|
2016-02-23 21:05:27 -05:00
|
|
|
expect(() => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapter = loadAdapter(adapterOptions, Adapter);
|
2016-02-23 21:05:27 -05:00
|
|
|
expect(adapter).toEqual(adapterOptions);
|
|
|
|
|
}).not.toThrow("foo is required for that adapter");
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-03-07 00:47:08 -08:00
|
|
|
|
2016-03-04 12:04:41 -05:00
|
|
|
it("should load push adapter from options", (done) => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const options = {
|
2017-07-01 23:34:47 -04:00
|
|
|
android: {
|
|
|
|
|
senderId: 'yolo',
|
|
|
|
|
apiKey: 'yolo'
|
2016-03-04 12:04:41 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
expect(() => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapter = loadAdapter(undefined, ParsePushAdapter, options);
|
2016-03-04 12:04:41 -05:00
|
|
|
expect(adapter.constructor).toBe(ParsePushAdapter);
|
|
|
|
|
expect(adapter).not.toBe(undefined);
|
|
|
|
|
}).not.toThrow();
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-03-07 00:47:08 -08:00
|
|
|
|
2017-02-21 15:06:45 -05:00
|
|
|
it("should load custom push adapter from string (#3544)", (done) => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapterPath = require('path').resolve("./spec/MockPushAdapter");
|
|
|
|
|
const options = {
|
2017-02-21 15:06:45 -05:00
|
|
|
ios: {
|
|
|
|
|
bundleId: 'bundle.id'
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const pushAdapterOptions = {
|
|
|
|
|
adapter: adapterPath,
|
|
|
|
|
options
|
|
|
|
|
};
|
|
|
|
|
expect(() => {
|
|
|
|
|
reconfigureServer({
|
|
|
|
|
push: pushAdapterOptions,
|
|
|
|
|
}).then(() => {
|
2017-10-23 08:43:05 -04:00
|
|
|
const config = Config.get(Parse.applicationId);
|
2017-02-21 15:06:45 -05:00
|
|
|
const pushAdapter = config.pushWorker.adapter;
|
|
|
|
|
expect(pushAdapter.getValidPushTypes()).toEqual(['ios']);
|
|
|
|
|
expect(pushAdapter.options).toEqual(pushAdapterOptions);
|
|
|
|
|
done();
|
|
|
|
|
});
|
|
|
|
|
}).not.toThrow();
|
|
|
|
|
});
|
|
|
|
|
|
2016-03-04 12:04:41 -05:00
|
|
|
it("should load S3Adapter from direct passing", (done) => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const s3Adapter = new S3Adapter("key", "secret", "bucket")
|
2016-03-04 12:04:41 -05:00
|
|
|
expect(() => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapter = loadAdapter(s3Adapter, FilesAdapter);
|
2016-03-04 12:04:41 -05:00
|
|
|
expect(adapter).toBe(s3Adapter);
|
|
|
|
|
}).not.toThrow();
|
|
|
|
|
done();
|
|
|
|
|
})
|
2016-02-22 18:31:10 -05:00
|
|
|
});
|