forked from SmartDropLabs/smartdrop-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhookEvents.test.js
More file actions
50 lines (40 loc) · 1.87 KB
/
Copy pathwebhookEvents.test.js
File metadata and controls
50 lines (40 loc) · 1.87 KB
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
'use strict';
const events = require('../src/services/webhookEvents');
describe('webhook event registry', () => {
test('pool.assets_locked is a known event', () => {
expect(events.isKnownEvent('pool.assets_locked')).toBe(true);
});
test('unknown event types are rejected', () => {
expect(events.isKnownEvent('something.random')).toBe(false);
});
test('isValidSubscription accepts a non-empty array of known events', () => {
expect(events.isValidSubscription(['pool.assets_locked'])).toBe(true);
expect(events.isValidSubscription(['pool.assets_locked', 'pool.closed'])).toBe(true);
});
test('isValidSubscription accepts wildcard', () => {
expect(events.isValidSubscription(['*'])).toBe(true);
});
test('isValidSubscription rejects mixed wildcard and explicit events', () => {
expect(events.isValidSubscription(['*', 'pool.assets_locked'])).toBe(false);
});
test('isValidSubscription rejects oversized explicit subscriptions', () => {
const oversized = Array.from(
{ length: events.MAX_EXPLICIT_SUBSCRIPTIONS + 1 },
(_, i) => `pool.fake_${i}`,
);
expect(events.isValidSubscription(oversized)).toBe(false);
});
test('isValidSubscription rejects empty arrays and bad inputs', () => {
expect(events.isValidSubscription([])).toBe(false);
expect(events.isValidSubscription(null)).toBe(false);
expect(events.isValidSubscription(['nope'])).toBe(false);
});
test('matchesSubscription exact match', () => {
expect(events.matchesSubscription(['pool.assets_locked'], 'pool.assets_locked')).toBe(true);
expect(events.matchesSubscription(['pool.closed'], 'pool.assets_locked')).toBe(false);
});
test('matchesSubscription wildcard subscribes to all', () => {
expect(events.matchesSubscription(['*'], 'pool.assets_locked')).toBe(true);
expect(events.matchesSubscription(['*'], 'price.alert')).toBe(true);
});
});