BVB Source Codes

parse-server Show AdapterLoader.spec.js Source code

Return Download parse-server: download AdapterLoader.spec.js Source code - Download parse-server Source code - Type:.js
  1.  
  2. var loadAdapter = require("../src/Adapters/AdapterLoader").loadAdapter;
  3. var FilesAdapter = require("parse-server-fs-adapter").default;
  4. var S3Adapter = require("parse-server-s3-adapter").default;
  5. var ParsePushAdapter = require("parse-server-push-adapter").default;
  6. const Config = require('../src/Config');
  7.  
  8. describe("AdapterLoader", ()=>{
  9.  
  10.   it("should instantiate an adapter from string in object", (done) => {
  11.     var adapterPath = require('path').resolve("./spec/MockAdapter");
  12.  
  13.     var adapter = loadAdapter({
  14.       adapter: adapterPath,
  15.       options: {
  16.         key: "value",
  17.         foo: "bar"
  18.       }
  19.     });
  20.  
  21.     expect(adapter instanceof Object).toBe(true);
  22.     expect(adapter.options.key).toBe("value");
  23.     expect(adapter.options.foo).toBe("bar");
  24.     done();
  25.   });
  26.  
  27.   it("should instantiate an adapter from string", (done) => {
  28.     var adapterPath = require('path').resolve("./spec/MockAdapter");
  29.     var adapter = loadAdapter(adapterPath);
  30.  
  31.     expect(adapter instanceof Object).toBe(true);
  32.     done();
  33.   });
  34.  
  35.   it("should instantiate an adapter from string that is module", (done) => {
  36.     var adapterPath = require('path').resolve("./src/Adapters/Files/FilesAdapter");
  37.     var adapter = loadAdapter({
  38.       adapter: adapterPath
  39.     });
  40.  
  41.     expect(typeof adapter).toBe('object');
  42.     expect(typeof adapter.createFile).toBe('function');
  43.     expect(typeof adapter.deleteFile).toBe('function');
  44.     expect(typeof adapter.getFileData).toBe('function');
  45.     expect(typeof adapter.getFileLocation).toBe('function');
  46.     done();
  47.   });
  48.  
  49.   it("should instantiate an adapter from npm module", (done) => {
  50.     var adapter = loadAdapter({
  51.       module: 'parse-server-fs-adapter'
  52.     });
  53.  
  54.     expect(typeof adapter).toBe('object');
  55.     expect(typeof adapter.createFile).toBe('function');
  56.     expect(typeof adapter.deleteFile).toBe('function');
  57.     expect(typeof adapter.getFileData).toBe('function');
  58.     expect(typeof adapter.getFileLocation).toBe('function');
  59.     done();
  60.   });
  61.  
  62.   it("should instantiate an adapter from function/Class", (done) => {
  63.     var adapter = loadAdapter({
  64.       adapter: FilesAdapter
  65.     });
  66.     expect(adapter instanceof FilesAdapter).toBe(true);
  67.     done();
  68.   });
  69.  
  70.   it("should instantiate the default adapter from Class", (done) => {
  71.     var adapter = loadAdapter(null, FilesAdapter);
  72.     expect(adapter instanceof FilesAdapter).toBe(true);
  73.     done();
  74.   });
  75.  
  76.   it("should use the default adapter", (done) => {
  77.     var defaultAdapter = new FilesAdapter();
  78.     var adapter = loadAdapter(null, defaultAdapter);
  79.     expect(adapter instanceof FilesAdapter).toBe(true);
  80.     done();
  81.   });
  82.  
  83.   it("should use the provided adapter", (done) => {
  84.     var originalAdapter = new FilesAdapter();
  85.     var adapter = loadAdapter(originalAdapter);
  86.     expect(adapter).toBe(originalAdapter);
  87.     done();
  88.   });
  89.  
  90.   it("should fail loading an improperly configured adapter", (done) => {
  91.     var Adapter = function(options) {
  92.       if (!options.foo) {
  93.         throw "foo is required for that adapter";
  94.       }
  95.     }
  96.     var adapterOptions = {
  97.       param: "key",
  98.       doSomething: function() {}
  99.     };
  100.  
  101.     expect(() => {
  102.       var adapter = loadAdapter(adapterOptions, Adapter);
  103.       expect(adapter).toEqual(adapterOptions);
  104.     }).not.toThrow("foo is required for that adapter");
  105.     done();
  106.   });
  107.  
  108.   it("should load push adapter from options", (done) => {
  109.     var options = {
  110.       ios: {
  111.         bundleId: 'bundle.id'
  112.       }
  113.     }
  114.     expect(() => {
  115.       var adapter = loadAdapter(undefined, ParsePushAdapter, options);
  116.       expect(adapter.constructor).toBe(ParsePushAdapter);
  117.       expect(adapter).not.toBe(undefined);
  118.     }).not.toThrow();
  119.     done();
  120.   });
  121.  
  122.   it("should load custom push adapter from string (#3544)", (done) => {
  123.     var adapterPath = require('path').resolve("./spec/MockPushAdapter");
  124.     var options = {
  125.       ios: {
  126.         bundleId: 'bundle.id'
  127.       }
  128.     }
  129.     const pushAdapterOptions = {
  130.       adapter: adapterPath,
  131.       options
  132.     };
  133.     expect(() => {
  134.       reconfigureServer({
  135.         push: pushAdapterOptions,
  136.       }).then(() => {
  137.         const config = new Config(Parse.applicationId);
  138.         const pushAdapter = config.pushWorker.adapter;
  139.         expect(pushAdapter.getValidPushTypes()).toEqual(['ios']);
  140.         expect(pushAdapter.options).toEqual(pushAdapterOptions);
  141.         done();
  142.       });
  143.     }).not.toThrow();
  144.   });
  145.  
  146.   it("should load S3Adapter from direct passing", (done) => {
  147.     var s3Adapter = new S3Adapter("key", "secret", "bucket")
  148.     expect(() => {
  149.       var adapter = loadAdapter(s3Adapter, FilesAdapter);
  150.       expect(adapter).toBe(s3Adapter);
  151.     }).not.toThrow();
  152.     done();
  153.   })
  154. });
  155.  
downloadAdapterLoader.spec.js Source code - Download parse-server Source code
Related Source Codes/Software:
react-boilerplate - 2017-06-07
webtorrent - Streaming torrent client for the web ... 2017-06-06
machine-learning-for-software-engineers - A complete daily plan for studying to become a mac... 2017-06-06
upterm - A terminal emulator for the 21st century. 2017-06-06
lottie-android - Render After Effects animations natively on Androi... 2017-06-07
AsyncDisplayKit - Smooth asynchronous user interfaces for iOS apps. ... 2017-06-07
ionicons - The premium icon font for Ionic ... 2017-06-07
storybook - 2017-06-07
prettier - Prettier is an opinionated JavaScript formatter. ... 2017-06-08
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top