BVB Source Codes

parse-server Show index.spec.js Source code

Return Download parse-server: download index.spec.js Source code - Download parse-server Source code - Type:.js
  1. "use strict"
  2. var request = require('request');
  3. var parseServerPackage = require('../package.json');
  4. var MockEmailAdapterWithOptions = require('./MockEmailAdapterWithOptions');
  5. var ParseServer = require("../src/index");
  6. var Config = require('../src/Config');
  7. var express = require('express');
  8.  
  9. const MongoStorageAdapter = require('../src/Adapters/Storage/Mongo/MongoStorageAdapter');
  10.  
  11. describe('server', () => {
  12.   it('requires a master key and app id', done => {
  13.     reconfigureServer({ appId: undefined })
  14.     .catch(error => {
  15.       expect(error).toEqual('You must provide an appId!');
  16.       return reconfigureServer({ masterKey: undefined });
  17.     })
  18.     .catch(error => {
  19.       expect(error).toEqual('You must provide a masterKey!');
  20.       return reconfigureServer({ serverURL: undefined });
  21.     })
  22.     .catch(error => {
  23.       expect(error).toEqual('You must provide a serverURL!');
  24.       done();
  25.     });
  26.   });
  27.  
  28.   it('support http basic authentication with masterkey', done => {
  29.     reconfigureServer({ appId: 'test' }).then(() => {
  30.       request.get({
  31.         url: 'http://localhost:8378/1/classes/TestObject',
  32.         headers: {
  33.           'Authorization': 'Basic ' + new Buffer('test:' + 'test').toString('base64')
  34.         }
  35.       }, (error, response) => {
  36.         expect(response.statusCode).toEqual(200);
  37.         done();
  38.       });
  39.     })
  40.   });
  41.  
  42.   it('support http basic authentication with javascriptKey', done => {
  43.     reconfigureServer({ appId: 'test' }).then(() => {
  44.       request.get({
  45.         url: 'http://localhost:8378/1/classes/TestObject',
  46.         headers: {
  47.           'Authorization': 'Basic ' + new Buffer('test:javascript-key=' + 'test').toString('base64')
  48.         }
  49.       }, (error, response) => {
  50.         expect(response.statusCode).toEqual(200);
  51.         done();
  52.       });
  53.     })
  54.   });
  55.  
  56.   it('fails if database is unreachable', done => {
  57.     reconfigureServer({ databaseAdapter: new MongoStorageAdapter({ uri: 'mongodb://fake:fake@localhost:43605/drew3' }) })
  58.     .catch(() => {
  59.       //Need to use rest api because saving via JS SDK results in fail() not getting called
  60.       request.post({
  61.         url: 'http://localhost:8378/1/classes/NewClass',
  62.         headers: {
  63.           'X-Parse-Application-Id': 'test',
  64.           'X-Parse-REST-API-Key': 'rest',
  65.         },
  66.         body: {},
  67.         json: true,
  68.       }, (error, response, body) => {
  69.         expect(response.statusCode).toEqual(500);
  70.         expect(body.code).toEqual(1);
  71.         expect(body.message).toEqual('Internal server error.');
  72.         reconfigureServer().then(done, done);
  73.       });
  74.     });
  75.   });
  76.  
  77.   it('can load email adapter via object', done => {
  78.     reconfigureServer({
  79.       appName: 'unused',
  80.       verifyUserEmails: true,
  81.       emailAdapter: MockEmailAdapterWithOptions({
  82.         fromAddress: 'parse@example.com',
  83.         apiKey: 'k',
  84.         domain: 'd',
  85.       }),
  86.       publicServerURL: 'http://localhost:8378/1'
  87.     }).then(done, fail);
  88.   });
  89.  
  90.   it('can load email adapter via class', done => {
  91.     reconfigureServer({
  92.       appName: 'unused',
  93.       verifyUserEmails: true,
  94.       emailAdapter: {
  95.         class: MockEmailAdapterWithOptions,
  96.         options: {
  97.           fromAddress: 'parse@example.com',
  98.           apiKey: 'k',
  99.           domain: 'd',
  100.         }
  101.       },
  102.       publicServerURL: 'http://localhost:8378/1'
  103.     }).then(done, fail);
  104.   });
  105.  
  106.   it('can load email adapter via module name', done => {
  107.     reconfigureServer({
  108.       appName: 'unused',
  109.       verifyUserEmails: true,
  110.       emailAdapter: {
  111.         module: 'parse-server-simple-mailgun-adapter',
  112.         options: {
  113.           fromAddress: 'parse@example.com',
  114.           apiKey: 'k',
  115.           domain: 'd',
  116.         }
  117.       },
  118.       publicServerURL: 'http://localhost:8378/1'
  119.     }).then(done, fail);
  120.   });
  121.  
  122.   it('can load email adapter via only module name', done => {
  123.     reconfigureServer({
  124.       appName: 'unused',
  125.       verifyUserEmails: true,
  126.       emailAdapter: 'parse-server-simple-mailgun-adapter',
  127.       publicServerURL: 'http://localhost:8378/1'
  128.     })
  129.     .catch(error => {
  130.       expect(error).toEqual('SimpleMailgunAdapter requires an API Key, domain, and fromAddress.');
  131.       done();
  132.     });
  133.   });
  134.  
  135.   it('throws if you initialize email adapter incorrecly', done => {
  136.     reconfigureServer({
  137.       appName: 'unused',
  138.       verifyUserEmails: true,
  139.       emailAdapter: {
  140.         module: 'parse-server-simple-mailgun-adapter',
  141.         options: {
  142.           domain: 'd',
  143.         }
  144.       },
  145.       publicServerURL: 'http://localhost:8378/1'
  146.     })
  147.     .catch(error => {
  148.       expect(error).toEqual('SimpleMailgunAdapter requires an API Key, domain, and fromAddress.');
  149.       done();
  150.     });
  151.   });
  152.  
  153.   it('can report the server version', done => {
  154.     request.get({
  155.       url: 'http://localhost:8378/1/serverInfo',
  156.       headers: {
  157.         'X-Parse-Application-Id': 'test',
  158.         'X-Parse-Master-Key': 'test',
  159.       },
  160.       json: true,
  161.     }, (error, response, body) => {
  162.       expect(body.parseServerVersion).toEqual(parseServerPackage.version);
  163.       done();
  164.     })
  165.   });
  166.  
  167.   it('can respond 200 on path health', done => {
  168.     request.get({
  169.       url: 'http://localhost:8378/1/health',
  170.     }, (error, response) => {
  171.       expect(response.statusCode).toBe(200);
  172.       done();
  173.     });
  174.   });
  175.  
  176.   it('can create a parse-server v1', done => {
  177.     var parseServer = new ParseServer.default(Object.assign({},
  178.       defaultConfiguration, {
  179.         appId: "aTestApp",
  180.         masterKey: "aTestMasterKey",
  181.         serverURL: "http://localhost:12666/parse",
  182.         __indexBuildCompletionCallbackForTests: promise => {
  183.           promise
  184.         .then(() => {
  185.           expect(Parse.applicationId).toEqual("aTestApp");
  186.           var app = express();
  187.           app.use('/parse', parseServer.app);
  188.  
  189.           var server = app.listen(12666);
  190.           var obj  = new Parse.Object("AnObject");
  191.           var objId;
  192.           obj.save().then((obj) => {
  193.             objId = obj.id;
  194.             var q = new Parse.Query("AnObject");
  195.             return q.first();
  196.           }).then((obj) => {
  197.             expect(obj.id).toEqual(objId);
  198.             server.close(done);
  199.           }).fail(() => {
  200.             server.close(done);
  201.           })
  202.         });
  203.         }})
  204.     );
  205.   });
  206.  
  207.   it('can create a parse-server v2', done => {
  208.     let objId;
  209.     let server
  210.     const parseServer = ParseServer.ParseServer(Object.assign({},
  211.       defaultConfiguration, {
  212.         appId: "anOtherTestApp",
  213.         masterKey: "anOtherTestMasterKey",
  214.         serverURL: "http://localhost:12667/parse",
  215.         __indexBuildCompletionCallbackForTests: promise => {
  216.           promise
  217.         .then(() => {
  218.           expect(Parse.applicationId).toEqual("anOtherTestApp");
  219.           const app = express();
  220.           app.use('/parse', parseServer);
  221.  
  222.           server = app.listen(12667);
  223.           const obj = new Parse.Object("AnObject");
  224.           return obj.save()
  225.         })
  226.         .then(obj => {
  227.           objId = obj.id;
  228.           const q = new Parse.Query("AnObject");
  229.           return q.first();
  230.         })
  231.         .then(obj => {
  232.           expect(obj.id).toEqual(objId);
  233.           server.close(done);
  234.         })
  235.         .catch(error => {
  236.           fail(JSON.stringify(error))
  237.           if (server) {
  238.             server.close(done);
  239.           } else {
  240.             done();
  241.           }
  242.         });
  243.         }}
  244.     ));
  245.   });
  246.  
  247.   it('has createLiveQueryServer', done => {
  248.     // original implementation through the factory
  249.     expect(typeof ParseServer.ParseServer.createLiveQueryServer).toEqual('function');
  250.     // For import calls
  251.     expect(typeof ParseServer.default.createLiveQueryServer).toEqual('function');
  252.     done();
  253.   });
  254.  
  255.   it('exposes correct adapters', done => {
  256.     expect(ParseServer.S3Adapter).toThrow();
  257.     expect(ParseServer.GCSAdapter).toThrow('GCSAdapter is not provided by parse-server anymore; please install parse-server-gcs-adapter');
  258.     expect(ParseServer.FileSystemAdapter).toThrow();
  259.     expect(ParseServer.InMemoryCacheAdapter).toThrow();
  260.     expect(ParseServer.NullCacheAdapter).toThrow();
  261.     done();
  262.   });
  263.  
  264.   it('properly gives publicServerURL when set', done => {
  265.     reconfigureServer({ publicServerURL: 'https://myserver.com/1' })
  266.     .then(() => {
  267.       var config = new Config('test', 'http://localhost:8378/1');
  268.       expect(config.mount).toEqual('https://myserver.com/1');
  269.       done();
  270.     });
  271.   });
  272.  
  273.   it('properly removes trailing slash in mount', done => {
  274.     reconfigureServer({})
  275.     .then(() => {
  276.       var config = new Config('test', 'http://localhost:8378/1/');
  277.       expect(config.mount).toEqual('http://localhost:8378/1');
  278.       done();
  279.     });
  280.   });
  281.  
  282.   it('should throw when getting invalid mount', done => {
  283.     reconfigureServer({ publicServerURL: 'blabla:/some' })
  284.     .catch(error => {
  285.       expect(error).toEqual('publicServerURL should be a valid HTTPS URL starting with https://')
  286.       done();
  287.     })
  288.   });
  289.  
  290.   it('fails if the session length is not a number', done => {
  291.     reconfigureServer({ sessionLength: 'test' })
  292.     .catch(error => {
  293.       expect(error).toEqual('Session length must be a valid number.');
  294.       done();
  295.     });
  296.   });
  297.  
  298.   it('fails if the session length is less than or equal to 0', done => {
  299.     reconfigureServer({ sessionLength: '-33' })
  300.     .catch(error => {
  301.       expect(error).toEqual('Session length must be a value greater than 0.');
  302.       return reconfigureServer({ sessionLength: '0' })
  303.     })
  304.     .catch(error => {
  305.       expect(error).toEqual('Session length must be a value greater than 0.');
  306.       done();
  307.     });
  308.   });
  309.  
  310.   it('ignores the session length when expireInactiveSessions set to false', (done) => {
  311.     reconfigureServer({
  312.       sessionLength: '-33',
  313.       expireInactiveSessions: false
  314.     })
  315.     .then(() => reconfigureServer({
  316.       sessionLength: '0',
  317.       expireInactiveSessions: false
  318.     }))
  319.     .then(done);
  320.   })
  321.  
  322.   it('fails if you try to set revokeSessionOnPasswordReset to non-boolean', done => {
  323.     reconfigureServer({ revokeSessionOnPasswordReset: 'non-bool' })
  324.     .catch(done);
  325.   });
  326. });
  327.  
downloadindex.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