BVB Source Codes

parse-server Show ParseGlobalConfig.spec.js Source code

Return Download parse-server: download ParseGlobalConfig.spec.js Source code - Download parse-server Source code - Type:.js
  1. 'use strict';
  2.  
  3. var request = require('request');
  4. const Config = require('../src/Config');
  5.  
  6. describe('a GlobalConfig', () => {
  7.   beforeEach(done => {
  8.     const config = new Config('test');
  9.     const query = on_db('mongo', () => {
  10.       // Legacy is with an int...
  11.       return { objectId: 1 };
  12.     }, () => {
  13.       return { objectId: "1" }
  14.     })
  15.     config.database.adapter.upsertOneObject(
  16.       '_GlobalConfig',
  17.       { fields: { objectId: { type: 'Number' }, params: {type: 'Object'}} },
  18.       query,
  19.       { params: { companies: ['US', 'DK'] } }
  20.     ).then(done, (err) => {
  21.       jfail(err);
  22.       done();
  23.     });
  24.   });
  25.  
  26.   it('can be retrieved', (done) => {
  27.     request.get({
  28.       url    : 'http://localhost:8378/1/config',
  29.       json   : true,
  30.       headers: {
  31.         'X-Parse-Application-Id': 'test',
  32.         'X-Parse-Master-Key'    : 'test'
  33.       }
  34.     }, (error, response, body) => {
  35.       try {
  36.         expect(response.statusCode).toEqual(200);
  37.         expect(body.params.companies).toEqual(['US', 'DK']);
  38.       } catch(e) { jfail(e); }
  39.       done();
  40.     });
  41.   });
  42.  
  43.   it('can be updated when a master key exists', (done) => {
  44.     request.put({
  45.       url    : 'http://localhost:8378/1/config',
  46.       json   : true,
  47.       body   : { params: { companies: ['US', 'DK', 'SE'] } },
  48.       headers: {
  49.         'X-Parse-Application-Id': 'test',
  50.         'X-Parse-Master-Key'    : 'test'
  51.       }
  52.     }, (error, response, body) => {
  53.       expect(response.statusCode).toEqual(200);
  54.       expect(body.result).toEqual(true);
  55.       done();
  56.     });
  57.   });
  58.  
  59.   it('can add and retrive files', (done) => {
  60.     request.put({
  61.       url    : 'http://localhost:8378/1/config',
  62.       json   : true,
  63.       body   : { params: { file: { __type: 'File', name: 'name', url: 'http://url' } } },
  64.       headers: {
  65.         'X-Parse-Application-Id': 'test',
  66.         'X-Parse-Master-Key'    : 'test'
  67.       }
  68.     }, (error, response, body) => {
  69.       expect(response.statusCode).toEqual(200);
  70.       expect(body.result).toEqual(true);
  71.       Parse.Config.get().then((res) => {
  72.         const file = res.get('file');
  73.         expect(file.name()).toBe('name');
  74.         expect(file.url()).toBe('http://url');
  75.         done();
  76.       });
  77.     });
  78.   });
  79.  
  80.   it('can add and retrive Geopoints', (done) => {
  81.     const geopoint = new Parse.GeoPoint(10,-20);
  82.     request.put({
  83.       url    : 'http://localhost:8378/1/config',
  84.       json   : true,
  85.       body   : { params: { point: geopoint.toJSON() } },
  86.       headers: {
  87.         'X-Parse-Application-Id': 'test',
  88.         'X-Parse-Master-Key'    : 'test'
  89.       }
  90.     }, (error, response, body) => {
  91.       expect(response.statusCode).toEqual(200);
  92.       expect(body.result).toEqual(true);
  93.       Parse.Config.get().then((res) => {
  94.         const point = res.get('point');
  95.         expect(point.latitude).toBe(10);
  96.         expect(point.longitude).toBe(-20);
  97.         done();
  98.       });
  99.     });
  100.   });
  101.  
  102.   it('properly handles delete op', (done) => {
  103.     request.put({
  104.       url    : 'http://localhost:8378/1/config',
  105.       json   : true,
  106.       body   : { params: { companies: {__op: 'Delete'}, foo: 'bar' } },
  107.       headers: {
  108.         'X-Parse-Application-Id': 'test',
  109.         'X-Parse-Master-Key'    : 'test'
  110.       }
  111.     }, (error, response, body) => {
  112.       expect(response.statusCode).toEqual(200);
  113.       expect(body.result).toEqual(true);
  114.       request.get({
  115.         url    : 'http://localhost:8378/1/config',
  116.         json   : true,
  117.         headers: {
  118.           'X-Parse-Application-Id': 'test',
  119.           'X-Parse-Master-Key'    : 'test'
  120.         }
  121.       }, (error, response, body) => {
  122.         try {
  123.           expect(response.statusCode).toEqual(200);
  124.           expect(body.params.companies).toBeUndefined();
  125.           expect(body.params.foo).toBe('bar');
  126.           expect(Object.keys(body.params).length).toBe(1);
  127.         } catch(e) { jfail(e); }
  128.         done();
  129.       });
  130.     });
  131.   });
  132.  
  133.   it('fail to update if master key is missing', (done) => {
  134.     request.put({
  135.       url    : 'http://localhost:8378/1/config',
  136.       json   : true,
  137.       body   : { params: { companies: [] } },
  138.       headers: {
  139.         'X-Parse-Application-Id': 'test',
  140.         'X-Parse-REST-API-Key'  : 'rest'
  141.       }
  142.     }, (error, response, body) => {
  143.       expect(response.statusCode).toEqual(403);
  144.       expect(body.error).toEqual('unauthorized: master key is required');
  145.       done();
  146.     });
  147.   });
  148.  
  149.   it('failed getting config when it is missing', (done) => {
  150.     const config = new Config('test');
  151.     config.database.adapter.deleteObjectsByQuery(
  152.       '_GlobalConfig',
  153.       { fields: { params: { __type: 'String' } } },
  154.       { objectId: "1" }
  155.     ).then(() => {
  156.       request.get({
  157.         url    : 'http://localhost:8378/1/config',
  158.         json   : true,
  159.         headers: {
  160.           'X-Parse-Application-Id': 'test',
  161.           'X-Parse-Master-Key'    : 'test'
  162.         }
  163.       }, (error, response, body) => {
  164.         expect(response.statusCode).toEqual(200);
  165.         expect(body.params).toEqual({});
  166.         done();
  167.       });
  168.     }).catch((e) => {
  169.       jfail(e);
  170.       done();
  171.     });
  172.   });
  173. });
  174.  
downloadParseGlobalConfig.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