2016-02-21 12:02:18 -05:00
|
|
|
|
2018-02-17 09:55:30 -05:00
|
|
|
const AdaptableController = require("../src/Controllers/AdaptableController").AdaptableController;
|
|
|
|
|
const FilesAdapter = require("../src/Adapters/Files/FilesAdapter").default;
|
|
|
|
|
const FilesController = require("../src/Controllers/FilesController").FilesController;
|
2016-02-21 23:47:07 -05:00
|
|
|
|
2018-02-17 09:55:30 -05:00
|
|
|
const MockController = function(options) {
|
2016-02-21 23:47:07 -05:00
|
|
|
AdaptableController.call(this, options);
|
|
|
|
|
}
|
|
|
|
|
MockController.prototype = Object.create(AdaptableController.prototype);
|
|
|
|
|
MockController.prototype.constructor = AdaptableController;
|
2016-02-21 12:02:18 -05:00
|
|
|
|
|
|
|
|
describe("AdaptableController", ()=>{
|
2016-02-21 23:47:07 -05:00
|
|
|
it("should use the provided adapter", (done) => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapter = new FilesAdapter();
|
|
|
|
|
const controller = new FilesController(adapter);
|
2016-02-21 23:47:07 -05:00
|
|
|
expect(controller.adapter).toBe(adapter);
|
2016-02-22 14:12:51 -05:00
|
|
|
// make sure _adapter is private
|
|
|
|
|
expect(controller._adapter).toBe(undefined);
|
|
|
|
|
// Override _adapter is not doing anything
|
|
|
|
|
controller._adapter = "Hello";
|
|
|
|
|
expect(controller.adapter).toBe(adapter);
|
2016-02-21 12:02:18 -05:00
|
|
|
done();
|
|
|
|
|
});
|
2016-04-05 21:16:39 -07:00
|
|
|
|
2016-02-21 23:47:07 -05:00
|
|
|
it("should throw when creating a new mock controller", (done) => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapter = new FilesAdapter();
|
2016-02-21 23:47:07 -05:00
|
|
|
expect(() => {
|
|
|
|
|
new MockController(adapter);
|
|
|
|
|
}).toThrow();
|
2016-02-21 12:02:18 -05:00
|
|
|
done();
|
|
|
|
|
});
|
2016-04-05 21:16:39 -07:00
|
|
|
|
2016-02-22 14:12:51 -05:00
|
|
|
it("should fail setting the wrong adapter to the controller", (done) => {
|
2016-11-24 15:47:41 -05:00
|
|
|
function WrongAdapter() {}
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapter = new FilesAdapter();
|
|
|
|
|
const controller = new FilesController(adapter);
|
|
|
|
|
const otherAdapter = new WrongAdapter();
|
2016-02-22 14:12:51 -05:00
|
|
|
expect(() => {
|
|
|
|
|
controller.adapter = otherAdapter;
|
|
|
|
|
}).toThrow();
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-04-05 21:16:39 -07:00
|
|
|
|
2016-02-21 23:47:07 -05:00
|
|
|
it("should fail to instantiate a controller with wrong adapter", (done) => {
|
2016-11-24 15:47:41 -05:00
|
|
|
function WrongAdapter() {}
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapter = new WrongAdapter();
|
2016-02-21 23:47:07 -05:00
|
|
|
expect(() => {
|
|
|
|
|
new FilesController(adapter);
|
|
|
|
|
}).toThrow();
|
2016-02-21 12:02:18 -05:00
|
|
|
done();
|
|
|
|
|
});
|
2016-04-05 21:16:39 -07:00
|
|
|
|
2016-02-21 23:47:07 -05:00
|
|
|
it("should fail to instantiate a controller without an adapter", (done) => {
|
|
|
|
|
expect(() => {
|
|
|
|
|
new FilesController();
|
|
|
|
|
}).toThrow();
|
2016-02-21 12:02:18 -05:00
|
|
|
done();
|
|
|
|
|
});
|
2016-04-05 21:16:39 -07:00
|
|
|
|
2016-02-22 14:12:51 -05:00
|
|
|
it("should accept an object adapter", (done) => {
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapter = {
|
2016-11-24 15:47:41 -05:00
|
|
|
createFile: function() { },
|
|
|
|
|
deleteFile: function() { },
|
|
|
|
|
getFileData: function() { },
|
|
|
|
|
getFileLocation: function() { },
|
2016-02-22 14:12:51 -05:00
|
|
|
}
|
|
|
|
|
expect(() => {
|
|
|
|
|
new FilesController(adapter);
|
|
|
|
|
}).not.toThrow();
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-04-05 21:16:39 -07:00
|
|
|
|
2018-07-01 00:00:37 -04:00
|
|
|
it("should accept an prototype based object adapter", (done) => {
|
2016-11-24 15:47:41 -05:00
|
|
|
function AGoodAdapter() {}
|
|
|
|
|
AGoodAdapter.prototype.createFile = function() { };
|
|
|
|
|
AGoodAdapter.prototype.deleteFile = function() { };
|
|
|
|
|
AGoodAdapter.prototype.getFileData = function() { };
|
|
|
|
|
AGoodAdapter.prototype.getFileLocation = function() { };
|
2016-04-05 21:16:39 -07:00
|
|
|
|
2018-02-17 09:55:30 -05:00
|
|
|
const adapter = new AGoodAdapter();
|
2016-02-22 14:12:51 -05:00
|
|
|
expect(() => {
|
|
|
|
|
new FilesController(adapter);
|
|
|
|
|
}).not.toThrow();
|
|
|
|
|
done();
|
|
|
|
|
});
|
2016-04-05 21:16:39 -07:00
|
|
|
});
|