BVB Source Codes

parse-server Show FilesController.spec.js Source code

Return Download parse-server: download FilesController.spec.js Source code - Download parse-server Source code - Type:.js
  1. const LoggerController = require('../src/Controllers/LoggerController').LoggerController;
  2. const WinstonLoggerAdapter = require('../src/Adapters/Logger/WinstonLoggerAdapter').WinstonLoggerAdapter;
  3. const GridStoreAdapter = require("../src/Adapters/Files/GridStoreAdapter").GridStoreAdapter;
  4. const Config = require("../src/Config");
  5. const FilesController = require('../src/Controllers/FilesController').default;
  6.  
  7. const mockAdapter = {
  8.   createFile: () => {
  9.     return Parse.Promise.reject(new Error('it failed'));
  10.   },
  11.   deleteFile: () => { },
  12.   getFileData: () => { },
  13.   getFileLocation: () => 'xyz'
  14. }
  15.  
  16. // Small additional tests to improve overall coverage
  17. describe("FilesController",() =>{
  18.   it("should properly expand objects", (done) => {
  19.  
  20.     var config = new Config(Parse.applicationId);
  21.     var gridStoreAdapter = new GridStoreAdapter('mongodb://localhost:27017/parse');
  22.     var filesController = new FilesController(gridStoreAdapter)
  23.     var result = filesController.expandFilesInObject(config, function(){});
  24.  
  25.     expect(result).toBeUndefined();
  26.  
  27.     var fullFile = {
  28.       type: '__type',
  29.       url: "http://an.url"
  30.     }
  31.  
  32.     var anObject = {
  33.       aFile: fullFile
  34.     }
  35.     filesController.expandFilesInObject(config, anObject);
  36.     expect(anObject.aFile.url).toEqual("http://an.url");
  37.  
  38.     done();
  39.   });
  40.  
  41.   it('should create a server log on failure', done => {
  42.     const logController = new LoggerController(new WinstonLoggerAdapter());
  43.  
  44.     reconfigureServer({ filesAdapter: mockAdapter })
  45.       .then(() => new Promise(resolve => setTimeout(resolve, 1000)))
  46.       .then(() => new Parse.File("yolo.txt", [1,2,3], "text/plain").save())
  47.       .then(
  48.         () => done.fail('should not succeed'),
  49.         () => setImmediate(() => Parse.Promise.as('done'))
  50.       )
  51.       .then(() => logController.getLogs({ from: Date.now() - 500, size: 1000 }))
  52.       .then((logs) => {
  53.         // we get two logs here: 1. the source of the failure to save the file
  54.         // and 2 the message that will be sent back to the client.
  55.         const log1 = logs.pop();
  56.         expect(log1.level).toBe('error');
  57.         expect(log1.message).toBe('it failed');
  58.         const log2 = logs.pop();
  59.         expect(log2.level).toBe('error');
  60.         expect(log2.code).toBe(130);
  61.         expect(log2.message).toBe('Could not store file.');
  62.         done();
  63.       });
  64.   });
  65. });
  66.  
downloadFilesController.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