BVB Source Codes

parse-server Show ParseServerRESTController.spec.js Source code

Return Download parse-server: download ParseServerRESTController.spec.js Source code - Download parse-server Source code - Type:.js
  1. const ParseServerRESTController = require('../src/ParseServerRESTController').ParseServerRESTController;
  2. const ParseServer = require('../src/ParseServer').default;
  3. const Parse = require('parse/node').Parse;
  4.  
  5. let RESTController;
  6.  
  7. describe('ParseServerRESTController', () => {
  8.  
  9.   beforeEach(() => {
  10.     RESTController = ParseServerRESTController(Parse.applicationId, ParseServer.promiseRouter({appId: Parse.applicationId}));
  11.   })
  12.  
  13.   it('should handle a get request', (done) => {
  14.     RESTController.request("GET", "/classes/MyObject").then((res) => {
  15.       expect(res.results.length).toBe(0);
  16.       done();
  17.     }, (err) => {
  18.       console.log(err);
  19.       jfail(err);
  20.       done();
  21.     });
  22.   });
  23.  
  24.   it('should handle a get request with full serverURL mount path', (done) => {
  25.     RESTController.request("GET", "/1/classes/MyObject").then((res) => {
  26.       expect(res.results.length).toBe(0);
  27.       done();
  28.     }, (err) => {
  29.       jfail(err);
  30.       done();
  31.     });
  32.   });
  33.  
  34.   it('should handle a POST batch', (done) => {
  35.     RESTController.request("POST", "batch", {
  36.       requests: [
  37.         {
  38.           method: 'GET',
  39.           path: '/classes/MyObject'
  40.         },
  41.         {
  42.           method: 'POST',
  43.           path: '/classes/MyObject',
  44.           body: {"key": "value"}
  45.         },
  46.         {
  47.           method: 'GET',
  48.           path: '/classes/MyObject'
  49.         }
  50.       ]
  51.     }).then((res) => {
  52.       expect(res.length).toBe(3);
  53.       done();
  54.     }, (err) => {
  55.       jfail(err);
  56.       done();
  57.     });
  58.   });
  59.  
  60.   it('should handle a POST request', (done) => {
  61.     RESTController.request("POST", "/classes/MyObject", {"key": "value"}).then(() => {
  62.       return RESTController.request("GET", "/classes/MyObject");
  63.     }).then((res) => {
  64.       expect(res.results.length).toBe(1);
  65.       expect(res.results[0].key).toEqual("value");
  66.       done();
  67.     }).fail((err) => {
  68.       console.log(err);
  69.       jfail(err);
  70.       done();
  71.     });
  72.   });
  73.  
  74.   it('ensures sessionTokens are properly handled', (done) => {
  75.     let userId;
  76.     Parse.User.signUp('user', 'pass').then((user) => {
  77.       userId = user.id;
  78.       const sessionToken = user.getSessionToken();
  79.       return RESTController.request("GET", "/users/me", undefined, {sessionToken});
  80.     }).then((res) => {
  81.       // Result is in JSON format
  82.       expect(res.objectId).toEqual(userId);
  83.       done();
  84.     }).fail((err) => {
  85.       console.log(err);
  86.       jfail(err);
  87.       done();
  88.     });
  89.   });
  90.  
  91.   it('ensures masterKey is properly handled', (done) => {
  92.     let userId;
  93.     Parse.User.signUp('user', 'pass').then((user) => {
  94.       userId = user.id;
  95.       return Parse.User.logOut().then(() => {
  96.         return RESTController.request("GET", "/classes/_User", undefined, {useMasterKey: true});
  97.       });
  98.     }).then((res) => {
  99.       expect(res.results.length).toBe(1);
  100.       expect(res.results[0].objectId).toEqual(userId);
  101.       done();
  102.     }, (err) => {
  103.       jfail(err);
  104.       done();
  105.     });
  106.   });
  107.  
  108.   it('ensures no user is created when passing an empty username', (done) => {
  109.     RESTController.request("POST", "/classes/_User", {username: "", password: "world"}).then(() => {
  110.       jfail(new Error('Success callback should not be called when passing an empty username.'));
  111.       done();
  112.     }, (err) => {
  113.       expect(err.code).toBe(Parse.Error.USERNAME_MISSING);
  114.       expect(err.message).toBe('bad or missing username');
  115.       done();
  116.     });
  117.   });
  118.  
  119.   it('ensures no user is created when passing an empty password', (done) => {
  120.     RESTController.request("POST", "/classes/_User", {username: "hello", password: ""}).then(() => {
  121.       jfail(new Error('Success callback should not be called when passing an empty password.'));
  122.       done();
  123.     }, (err) => {
  124.       expect(err.code).toBe(Parse.Error.PASSWORD_MISSING);
  125.       expect(err.message).toBe('password is required');
  126.       done();
  127.     });
  128.   });
  129.  
  130.   it('ensures no session token is created on creating users', (done) => {
  131.     RESTController.request("POST", "/classes/_User", {username: "hello", password: "world"}).then((user) => {
  132.       expect(user.sessionToken).toBeUndefined();
  133.       const query = new Parse.Query('_Session');
  134.       return query.find({useMasterKey: true});
  135.     }).then(sessions => {
  136.       expect(sessions.length).toBe(0);
  137.       done();
  138.     }, done.fail);
  139.   });
  140.  
  141.   it('ensures a session token is created when passing installationId != cloud', (done) => {
  142.     RESTController.request("POST", "/classes/_User", {username: "hello", password: "world"}, {installationId: 'my-installation'}).then((user) => {
  143.       expect(user.sessionToken).not.toBeUndefined();
  144.       const query = new Parse.Query('_Session');
  145.       return query.find({useMasterKey: true});
  146.     }).then(sessions => {
  147.       expect(sessions.length).toBe(1);
  148.       expect(sessions[0].get('installationId')).toBe('my-installation');
  149.       done();
  150.     }, (err) => {
  151.       jfail(err);
  152.       done();
  153.     });
  154.   });
  155. });
  156.  
downloadParseServerRESTController.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