BVB Source Codes

parse-server Show ParsePubSub.spec.js Source code

Return Download parse-server: download ParsePubSub.spec.js Source code - Download parse-server Source code - Type:.js
  1. var ParsePubSub = require('../src/LiveQuery/ParsePubSub').ParsePubSub;
  2.  
  3. describe('ParsePubSub', function() {
  4.  
  5.   beforeEach(function(done) {
  6.     // Mock RedisPubSub
  7.     var mockRedisPubSub = {
  8.       createPublisher: jasmine.createSpy('createPublisherRedis'),
  9.       createSubscriber: jasmine.createSpy('createSubscriberRedis')
  10.     };
  11.     jasmine.mockLibrary('../src/Adapters/PubSub/RedisPubSub', 'RedisPubSub', mockRedisPubSub);
  12.     // Mock EventEmitterPubSub
  13.     var mockEventEmitterPubSub = {
  14.       createPublisher: jasmine.createSpy('createPublisherEventEmitter'),
  15.       createSubscriber: jasmine.createSpy('createSubscriberEventEmitter')
  16.     };
  17.     jasmine.mockLibrary('../src/Adapters/PubSub/EventEmitterPubSub', 'EventEmitterPubSub', mockEventEmitterPubSub);
  18.     done();
  19.   });
  20.  
  21.   it('can create redis publisher', function() {
  22.     ParsePubSub.createPublisher({
  23.       redisURL: 'redisURL'
  24.     });
  25.  
  26.     var RedisPubSub = require('../src/Adapters/PubSub/RedisPubSub').RedisPubSub;
  27.     var EventEmitterPubSub = require('../src/Adapters/PubSub/EventEmitterPubSub').EventEmitterPubSub;
  28.     expect(RedisPubSub.createPublisher).toHaveBeenCalledWith({redisURL: 'redisURL'});
  29.     expect(EventEmitterPubSub.createPublisher).not.toHaveBeenCalled();
  30.   });
  31.  
  32.   it('can create event emitter publisher', function() {
  33.     ParsePubSub.createPublisher({});
  34.  
  35.     var RedisPubSub = require('../src/Adapters/PubSub/RedisPubSub').RedisPubSub;
  36.     var EventEmitterPubSub = require('../src/Adapters/PubSub/EventEmitterPubSub').EventEmitterPubSub;
  37.     expect(RedisPubSub.createPublisher).not.toHaveBeenCalled();
  38.     expect(EventEmitterPubSub.createPublisher).toHaveBeenCalled();
  39.   });
  40.  
  41.   it('can create redis subscriber', function() {
  42.     ParsePubSub.createSubscriber({
  43.       redisURL: 'redisURL'
  44.     });
  45.  
  46.     var RedisPubSub = require('../src/Adapters/PubSub/RedisPubSub').RedisPubSub;
  47.     var EventEmitterPubSub = require('../src/Adapters/PubSub/EventEmitterPubSub').EventEmitterPubSub;
  48.     expect(RedisPubSub.createSubscriber).toHaveBeenCalledWith({redisURL: 'redisURL'});
  49.     expect(EventEmitterPubSub.createSubscriber).not.toHaveBeenCalled();
  50.   });
  51.  
  52.   it('can create event emitter subscriber', function() {
  53.     ParsePubSub.createSubscriber({});
  54.  
  55.     var RedisPubSub = require('../src/Adapters/PubSub/RedisPubSub').RedisPubSub;
  56.     var EventEmitterPubSub = require('../src/Adapters/PubSub/EventEmitterPubSub').EventEmitterPubSub;
  57.     expect(RedisPubSub.createSubscriber).not.toHaveBeenCalled();
  58.     expect(EventEmitterPubSub.createSubscriber).toHaveBeenCalled();
  59.   });
  60.  
  61.   it('can create publisher/sub with custom adapter', function() {
  62.     const adapter =  {
  63.       createPublisher: jasmine.createSpy('createPublisher'),
  64.       createSubscriber: jasmine.createSpy('createSubscriber')
  65.     }
  66.     ParsePubSub.createPublisher({
  67.       pubSubAdapter: adapter
  68.     });
  69.     expect(adapter.createPublisher).toHaveBeenCalled();
  70.  
  71.     ParsePubSub.createSubscriber({
  72.       pubSubAdapter: adapter
  73.     });
  74.     expect(adapter.createSubscriber).toHaveBeenCalled();
  75.  
  76.     var RedisPubSub = require('../src/Adapters/PubSub/RedisPubSub').RedisPubSub;
  77.     var EventEmitterPubSub = require('../src/Adapters/PubSub/EventEmitterPubSub').EventEmitterPubSub;
  78.     expect(RedisPubSub.createSubscriber).not.toHaveBeenCalled();
  79.     expect(EventEmitterPubSub.createSubscriber).not.toHaveBeenCalled();
  80.     expect(RedisPubSub.createPublisher).not.toHaveBeenCalled();
  81.     expect(EventEmitterPubSub.createPublisher).not.toHaveBeenCalled();
  82.   });
  83.  
  84.   it('can create publisher/sub with custom function adapter', function() {
  85.     const adapter =  {
  86.       createPublisher: jasmine.createSpy('createPublisher'),
  87.       createSubscriber: jasmine.createSpy('createSubscriber')
  88.     }
  89.     ParsePubSub.createPublisher({
  90.       pubSubAdapter: function() {
  91.         return adapter;
  92.       }
  93.     });
  94.     expect(adapter.createPublisher).toHaveBeenCalled();
  95.  
  96.     ParsePubSub.createSubscriber({
  97.       pubSubAdapter: function() {
  98.         return adapter;
  99.       }
  100.     });
  101.     expect(adapter.createSubscriber).toHaveBeenCalled();
  102.  
  103.     var RedisPubSub = require('../src/Adapters/PubSub/RedisPubSub').RedisPubSub;
  104.     var EventEmitterPubSub = require('../src/Adapters/PubSub/EventEmitterPubSub').EventEmitterPubSub;
  105.     expect(RedisPubSub.createSubscriber).not.toHaveBeenCalled();
  106.     expect(EventEmitterPubSub.createSubscriber).not.toHaveBeenCalled();
  107.     expect(RedisPubSub.createPublisher).not.toHaveBeenCalled();
  108.     expect(EventEmitterPubSub.createPublisher).not.toHaveBeenCalled();
  109.   });
  110.  
  111.   afterEach(function(){
  112.     jasmine.restoreLibrary('../src/Adapters/PubSub/RedisPubSub', 'RedisPubSub');
  113.     jasmine.restoreLibrary('../src/Adapters/PubSub/EventEmitterPubSub', 'EventEmitterPubSub');
  114.   });
  115. });
  116.  
downloadParsePubSub.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