BVB Source Codes

parse-server Show CacheController.spec.js Source code

Return Download parse-server: download CacheController.spec.js Source code - Download parse-server Source code - Type:.js
  1. var CacheController = require('../src/Controllers/CacheController.js').default;
  2.  
  3. describe('CacheController', function() {
  4.   var FakeCacheAdapter;
  5.   var FakeAppID = 'foo';
  6.   var KEY = 'hello';
  7.  
  8.   beforeEach(() => {
  9.     FakeCacheAdapter = {
  10.       get: () => Promise.resolve(null),
  11.       put: jasmine.createSpy('put'),
  12.       del: jasmine.createSpy('del'),
  13.       clear: jasmine.createSpy('clear')
  14.     }
  15.  
  16.     spyOn(FakeCacheAdapter, 'get').and.callThrough();
  17.   });
  18.  
  19.  
  20.   it('should expose role and user caches', (done) => {
  21.     var cache = new CacheController(FakeCacheAdapter, FakeAppID);
  22.  
  23.     expect(cache.role).not.toEqual(null);
  24.     expect(cache.role.get).not.toEqual(null);
  25.     expect(cache.user).not.toEqual(null);
  26.     expect(cache.user.get).not.toEqual(null);
  27.  
  28.     done();
  29.   });
  30.  
  31.  
  32.   ['role', 'user'].forEach((cacheName) => {
  33.     it('should prefix ' + cacheName + ' cache', () => {
  34.       var cache = new CacheController(FakeCacheAdapter, FakeAppID)[cacheName];
  35.  
  36.       cache.put(KEY, 'world');
  37.       var firstPut = FakeCacheAdapter.put.calls.first();
  38.       expect(firstPut.args[0]).toEqual([FakeAppID, cacheName, KEY].join(':'));
  39.  
  40.       cache.get(KEY);
  41.       var firstGet = FakeCacheAdapter.get.calls.first();
  42.       expect(firstGet.args[0]).toEqual([FakeAppID, cacheName, KEY].join(':'));
  43.  
  44.       cache.del(KEY);
  45.       var firstDel = FakeCacheAdapter.del.calls.first();
  46.       expect(firstDel.args[0]).toEqual([FakeAppID, cacheName, KEY].join(':'));
  47.     });
  48.   });
  49.  
  50.   it('should clear the entire cache', () => {
  51.     var cache = new CacheController(FakeCacheAdapter, FakeAppID);
  52.  
  53.     cache.clear();
  54.     expect(FakeCacheAdapter.clear.calls.count()).toEqual(1);
  55.  
  56.     cache.user.clear();
  57.     expect(FakeCacheAdapter.clear.calls.count()).toEqual(2);
  58.  
  59.     cache.role.clear();
  60.     expect(FakeCacheAdapter.clear.calls.count()).toEqual(3);
  61.   });
  62.  
  63.   it('should handle cache rejections', (done) => {
  64.  
  65.     FakeCacheAdapter.get = () => Promise.reject();
  66.  
  67.     var cache = new CacheController(FakeCacheAdapter, FakeAppID);
  68.  
  69.     cache.get('foo').then(done, () => {
  70.       fail('Promise should not be rejected.');
  71.     });
  72.   });
  73.  
  74. });
  75.  
downloadCacheController.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