BVB Source Codes

parse-server Show Auth.spec.js Source code

Return Download parse-server: download Auth.spec.js Source code - Download parse-server Source code - Type:.js
  1. describe('Auth', () => {
  2.   var Auth = require('../src/Auth.js').Auth;
  3.  
  4.   describe('getUserRoles', () => {
  5.     var auth;
  6.     var config;
  7.     var currentRoles = null;
  8.     var currentUserId = 'userId';
  9.  
  10.     beforeEach(() => {
  11.       currentRoles = ['role:userId'];
  12.  
  13.       config = {
  14.         cacheController: {
  15.           role: {
  16.             get: () => Promise.resolve(currentRoles),
  17.             set: jasmine.createSpy('set')
  18.           }
  19.         }
  20.       }
  21.       spyOn(config.cacheController.role, 'get').and.callThrough();
  22.  
  23.       auth = new Auth({
  24.         config: config,
  25.         isMaster: false,
  26.         user: {
  27.           id: currentUserId
  28.         },
  29.         installationId: 'installationId'
  30.       });
  31.     });
  32.  
  33.     it('should get user roles from the cache', (done) => {
  34.       auth.getUserRoles()
  35.         .then((roles) => {
  36.           var firstSet = config.cacheController.role.set.calls.first();
  37.           expect(firstSet).toEqual(undefined);
  38.  
  39.           var firstGet = config.cacheController.role.get.calls.first();
  40.           expect(firstGet.args[0]).toEqual(currentUserId);
  41.           expect(roles).toEqual(currentRoles);
  42.           done();
  43.         });
  44.     });
  45.  
  46.     it('should only query the roles once', (done) => {
  47.       var loadRolesSpy = spyOn(auth, '_loadRoles').and.callThrough();
  48.       auth.getUserRoles()
  49.         .then((roles) => {
  50.           expect(roles).toEqual(currentRoles);
  51.           return auth.getUserRoles()
  52.         })
  53.         .then(() => auth.getUserRoles())
  54.         .then(() => auth.getUserRoles())
  55.         .then((roles) => {
  56.           // Should only call the cache adapter once.
  57.           expect(config.cacheController.role.get.calls.count()).toEqual(1);
  58.           expect(loadRolesSpy.calls.count()).toEqual(1);
  59.  
  60.           var firstGet = config.cacheController.role.get.calls.first();
  61.           expect(firstGet.args[0]).toEqual(currentUserId);
  62.           expect(roles).toEqual(currentRoles);
  63.           done();
  64.         });
  65.     });
  66.  
  67.     it('should not have any roles with no user', (done) => {
  68.       auth.user = null
  69.       auth.getUserRoles()
  70.         .then((roles) => expect(roles).toEqual([]))
  71.         .then(() => done());
  72.     });
  73.  
  74.     it('should not have any user roles with master', (done) => {
  75.       auth.isMaster = true
  76.       auth.getUserRoles()
  77.         .then((roles) => expect(roles).toEqual([]))
  78.         .then(() => done());
  79.     });
  80.  
  81.     it('should properly handle bcrypt upgrade', (done) => {
  82.       var bcryptOriginal = require('bcrypt-nodejs');
  83.       var bcryptNew = require('bcryptjs');
  84.       bcryptOriginal.hash('my1Long:password', null, null, function(err, res) {
  85.         bcryptNew.compare('my1Long:password', res, function(err, res) {
  86.           expect(res).toBeTruthy();
  87.           done();
  88.         })
  89.       });
  90.     });
  91.  
  92.   });
  93. });
  94.  
downloadAuth.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