bulltrackers-module 1.0.1101 → 1.0.1102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/functions/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const version =
|
|
1
|
+
const version = 44.0
|
package/package.json
CHANGED
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
matchSubscriptions,
|
|
5
|
-
generateAlertMessage,
|
|
6
|
-
_safeJsonParse,
|
|
7
|
-
_extractMetadata
|
|
8
|
-
} = require('./AlertSubscriptionMatcher');
|
|
9
|
-
|
|
10
|
-
// ─── generateAlertMessage ───────────────────────────────────────────────────
|
|
11
|
-
|
|
12
|
-
describe('generateAlertMessage', () => {
|
|
13
|
-
test('resolves piUsername and change fields', () => {
|
|
14
|
-
const config = { messageTemplate: "{piUsername}'s risk score increased by {change} points (from {previous} to {current})" };
|
|
15
|
-
const msg = generateAlertMessage(config, 'MockGuru', { change: 4, previous: 3, current: 7 });
|
|
16
|
-
expect(msg).toBe("MockGuru's risk score increased by 4 points (from 3 to 7)");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('resolves title for social post', () => {
|
|
20
|
-
const config = { messageTemplate: '{piUsername} posted a new update: {title}' };
|
|
21
|
-
const msg = generateAlertMessage(config, 'TestTrader', { title: 'Market Analysis Q1' });
|
|
22
|
-
expect(msg).toBe('TestTrader posted a new update: Market Analysis Q1');
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
test('handles missing fields gracefully', () => {
|
|
26
|
-
const config = { messageTemplate: '{piUsername} changed {change}' };
|
|
27
|
-
const msg = generateAlertMessage(config, undefined, {});
|
|
28
|
-
expect(msg).toContain('Unknown');
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
// ─── matchSubscriptions (MVP boolean-only) ───────────────────────────────────
|
|
33
|
-
|
|
34
|
-
describe('matchSubscriptions', () => {
|
|
35
|
-
const alertConfig = {
|
|
36
|
-
id: 'increasedRisk',
|
|
37
|
-
frontendName: 'Increased Risk',
|
|
38
|
-
configKey: 'increasedRisk',
|
|
39
|
-
severity: 'high',
|
|
40
|
-
isDynamic: false,
|
|
41
|
-
messageTemplate: "{piUsername}'s risk score increased"
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const parentResults = [
|
|
45
|
-
{ entityId: '100', triggered: true, currentRisk: 7, previousRisk: 3, change: 4, username: 'MockGuru' },
|
|
46
|
-
{ entityId: '200', triggered: false, currentRisk: 2, previousRisk: 2, change: 0 }
|
|
47
|
-
];
|
|
48
|
-
|
|
49
|
-
const watchlists = [
|
|
50
|
-
{ user_id: 'user1', watchlist_id: 'wl-1', name: 'My Watchlist', items: JSON.stringify([{ cid: '100' }]) },
|
|
51
|
-
{ user_id: 'user2', watchlist_id: 'wl-2', name: 'Other', items: JSON.stringify([{ cid: '200' }]) }
|
|
52
|
-
];
|
|
53
|
-
|
|
54
|
-
const subscriptions = [
|
|
55
|
-
{ user_id: 'user1', pi_cid: '100', settings: JSON.stringify({ alertConfig: { increasedRisk: true } }) }
|
|
56
|
-
];
|
|
57
|
-
|
|
58
|
-
test('produces notifications for triggered entities with matching subscriptions', () => {
|
|
59
|
-
const result = matchSubscriptions({
|
|
60
|
-
parentResults,
|
|
61
|
-
subscriptions,
|
|
62
|
-
watchlists,
|
|
63
|
-
alertConfig,
|
|
64
|
-
computationName: 'RiskScoreIncrease',
|
|
65
|
-
date: '2026-03-07'
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
expect(result.notifications).toHaveLength(1);
|
|
69
|
-
expect(result.notifications[0]).toMatchObject({
|
|
70
|
-
userCid: 'user1',
|
|
71
|
-
piCid: 100,
|
|
72
|
-
alertTypeId: 'increasedRisk',
|
|
73
|
-
computationName: 'RiskScoreIncrease',
|
|
74
|
-
computationDate: '2026-03-07',
|
|
75
|
-
severity: 'high',
|
|
76
|
-
watchlistId: 'wl-1',
|
|
77
|
-
watchlistName: 'My Watchlist'
|
|
78
|
-
});
|
|
79
|
-
expect(result.outbox).toBeDefined();
|
|
80
|
-
expect(result.outbox.emailPayloads).toBeDefined();
|
|
81
|
-
expect(result.outbox.smsPayloads).toBeDefined();
|
|
82
|
-
expect(result.outbox.fcmPayloads).toBeDefined();
|
|
83
|
-
expect(result.totalMatched).toBe(1);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('accepts boolean toggle directly on subscription (no alertConfig wrapper)', () => {
|
|
87
|
-
const subsDirect = [
|
|
88
|
-
{ user_id: 'user1', pi_cid: '100', settings: JSON.stringify({ increasedRisk: true }) }
|
|
89
|
-
];
|
|
90
|
-
const result = matchSubscriptions({
|
|
91
|
-
parentResults,
|
|
92
|
-
subscriptions: subsDirect,
|
|
93
|
-
watchlists,
|
|
94
|
-
alertConfig,
|
|
95
|
-
computationName: 'RiskScoreIncrease',
|
|
96
|
-
date: '2026-03-07'
|
|
97
|
-
});
|
|
98
|
-
expect(result.notifications).toHaveLength(1);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
test('skips non-triggered entities', () => {
|
|
102
|
-
const result = matchSubscriptions({
|
|
103
|
-
parentResults: [{ entityId: '100', triggered: false }],
|
|
104
|
-
subscriptions,
|
|
105
|
-
watchlists,
|
|
106
|
-
alertConfig,
|
|
107
|
-
computationName: 'Test',
|
|
108
|
-
date: '2026-03-07'
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
expect(result.notifications).toHaveLength(0);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test('skips users without subscriptions', () => {
|
|
115
|
-
const result = matchSubscriptions({
|
|
116
|
-
parentResults,
|
|
117
|
-
subscriptions: [],
|
|
118
|
-
watchlists,
|
|
119
|
-
alertConfig,
|
|
120
|
-
computationName: 'Test',
|
|
121
|
-
date: '2026-03-07'
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
expect(result.notifications).toHaveLength(0);
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
test('returns standardised output shape', () => {
|
|
128
|
-
const result = matchSubscriptions({
|
|
129
|
-
parentResults: [],
|
|
130
|
-
subscriptions: [],
|
|
131
|
-
watchlists: [],
|
|
132
|
-
alertConfig,
|
|
133
|
-
computationName: 'RiskScoreIncrease',
|
|
134
|
-
date: '2026-03-07'
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
expect(result).toHaveProperty('notifications');
|
|
138
|
-
expect(result).toHaveProperty('outbox');
|
|
139
|
-
expect(result.outbox).toHaveProperty('emailPayloads');
|
|
140
|
-
expect(result.outbox).toHaveProperty('smsPayloads');
|
|
141
|
-
expect(result.outbox).toHaveProperty('fcmPayloads');
|
|
142
|
-
expect(result).toHaveProperty('totalMatched');
|
|
143
|
-
expect(result).toHaveProperty('totalEvaluated');
|
|
144
|
-
expect(Array.isArray(result.notifications)).toBe(true);
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// ─── Helpers ────────────────────────────────────────────────────────────────
|
|
149
|
-
|
|
150
|
-
describe('helpers', () => {
|
|
151
|
-
test('_safeJsonParse returns parsed value', () => {
|
|
152
|
-
expect(_safeJsonParse('{"a":1}', {})).toEqual({ a: 1 });
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
test('_safeJsonParse returns fallback on invalid JSON', () => {
|
|
156
|
-
expect(_safeJsonParse('not-json', [])).toEqual([]);
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
test('_extractMetadata removes internal fields', () => {
|
|
160
|
-
const meta = _extractMetadata({ triggered: true, entityId: '100', currentRisk: 7 });
|
|
161
|
-
expect(meta).not.toHaveProperty('triggered');
|
|
162
|
-
expect(meta).not.toHaveProperty('entityId');
|
|
163
|
-
expect(meta).toHaveProperty('currentRisk', 7);
|
|
164
|
-
});
|
|
165
|
-
});
|