-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
/
Copy pathParsePubSub.spec.js
132 lines (116 loc) · 4.94 KB
/
ParsePubSub.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const ParsePubSub = require('../lib/LiveQuery/ParsePubSub').ParsePubSub;
describe('ParsePubSub', function () {
beforeEach(function (done) {
// Mock RedisPubSub
const mockRedisPubSub = {
createPublisher: jasmine.createSpy('createPublisherRedis'),
createSubscriber: jasmine.createSpy('createSubscriberRedis'),
};
jasmine.mockLibrary('../lib/Adapters/PubSub/RedisPubSub', 'RedisPubSub', mockRedisPubSub);
// Mock EventEmitterPubSub
const mockEventEmitterPubSub = {
createPublisher: jasmine.createSpy('createPublisherEventEmitter'),
createSubscriber: jasmine.createSpy('createSubscriberEventEmitter'),
};
jasmine.mockLibrary(
'../lib/Adapters/PubSub/EventEmitterPubSub',
'EventEmitterPubSub',
mockEventEmitterPubSub
);
done();
});
it('can create redis publisher', function () {
ParsePubSub.createPublisher({
redisURL: 'redisURL',
redisOptions: { socket_keepalive: true },
});
const RedisPubSub = require('../lib/Adapters/PubSub/RedisPubSub').RedisPubSub;
const EventEmitterPubSub = require('../lib/Adapters/PubSub/EventEmitterPubSub')
.EventEmitterPubSub;
expect(RedisPubSub.createPublisher).toHaveBeenCalledWith({
redisURL: 'redisURL',
redisOptions: { socket_keepalive: true },
});
expect(EventEmitterPubSub.createPublisher).not.toHaveBeenCalled();
});
it('can create event emitter publisher', function () {
ParsePubSub.createPublisher({});
const RedisPubSub = require('../lib/Adapters/PubSub/RedisPubSub').RedisPubSub;
const EventEmitterPubSub = require('../lib/Adapters/PubSub/EventEmitterPubSub')
.EventEmitterPubSub;
expect(RedisPubSub.createPublisher).not.toHaveBeenCalled();
expect(EventEmitterPubSub.createPublisher).toHaveBeenCalled();
});
it('can create redis subscriber', function () {
ParsePubSub.createSubscriber({
redisURL: 'redisURL',
redisOptions: { socket_keepalive: true },
});
const RedisPubSub = require('../lib/Adapters/PubSub/RedisPubSub').RedisPubSub;
const EventEmitterPubSub = require('../lib/Adapters/PubSub/EventEmitterPubSub')
.EventEmitterPubSub;
expect(RedisPubSub.createSubscriber).toHaveBeenCalledWith({
redisURL: 'redisURL',
redisOptions: { socket_keepalive: true },
});
expect(EventEmitterPubSub.createSubscriber).not.toHaveBeenCalled();
});
it('can create event emitter subscriber', function () {
ParsePubSub.createSubscriber({});
const RedisPubSub = require('../lib/Adapters/PubSub/RedisPubSub').RedisPubSub;
const EventEmitterPubSub = require('../lib/Adapters/PubSub/EventEmitterPubSub')
.EventEmitterPubSub;
expect(RedisPubSub.createSubscriber).not.toHaveBeenCalled();
expect(EventEmitterPubSub.createSubscriber).toHaveBeenCalled();
});
it('can create publisher/sub with custom adapter', function () {
const adapter = {
createPublisher: jasmine.createSpy('createPublisher'),
createSubscriber: jasmine.createSpy('createSubscriber'),
};
ParsePubSub.createPublisher({
pubSubAdapter: adapter,
});
expect(adapter.createPublisher).toHaveBeenCalled();
ParsePubSub.createSubscriber({
pubSubAdapter: adapter,
});
expect(adapter.createSubscriber).toHaveBeenCalled();
const RedisPubSub = require('../lib/Adapters/PubSub/RedisPubSub').RedisPubSub;
const EventEmitterPubSub = require('../lib/Adapters/PubSub/EventEmitterPubSub')
.EventEmitterPubSub;
expect(RedisPubSub.createSubscriber).not.toHaveBeenCalled();
expect(EventEmitterPubSub.createSubscriber).not.toHaveBeenCalled();
expect(RedisPubSub.createPublisher).not.toHaveBeenCalled();
expect(EventEmitterPubSub.createPublisher).not.toHaveBeenCalled();
});
it('can create publisher/sub with custom function adapter', function () {
const adapter = {
createPublisher: jasmine.createSpy('createPublisher'),
createSubscriber: jasmine.createSpy('createSubscriber'),
};
ParsePubSub.createPublisher({
pubSubAdapter: function () {
return adapter;
},
});
expect(adapter.createPublisher).toHaveBeenCalled();
ParsePubSub.createSubscriber({
pubSubAdapter: function () {
return adapter;
},
});
expect(adapter.createSubscriber).toHaveBeenCalled();
const RedisPubSub = require('../lib/Adapters/PubSub/RedisPubSub').RedisPubSub;
const EventEmitterPubSub = require('../lib/Adapters/PubSub/EventEmitterPubSub')
.EventEmitterPubSub;
expect(RedisPubSub.createSubscriber).not.toHaveBeenCalled();
expect(EventEmitterPubSub.createSubscriber).not.toHaveBeenCalled();
expect(RedisPubSub.createPublisher).not.toHaveBeenCalled();
expect(EventEmitterPubSub.createPublisher).not.toHaveBeenCalled();
});
afterEach(function () {
jasmine.restoreLibrary('../lib/Adapters/PubSub/RedisPubSub', 'RedisPubSub');
jasmine.restoreLibrary('../lib/Adapters/PubSub/EventEmitterPubSub', 'EventEmitterPubSub');
});
});