bulltrackers-module 1.0.777 → 1.0.779

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.
Files changed (24) hide show
  1. package/functions/alert-system/helpers/alert_helpers.js +114 -90
  2. package/functions/alert-system/helpers/alert_manifest_loader.js +88 -99
  3. package/functions/alert-system/index.js +81 -138
  4. package/functions/alert-system/tests/stage1-alert-manifest.test.js +94 -0
  5. package/functions/alert-system/tests/stage2-alert-metadata.test.js +93 -0
  6. package/functions/alert-system/tests/stage3-alert-handler.test.js +79 -0
  7. package/functions/api-v2/helpers/data-fetchers/firestore.js +613 -478
  8. package/functions/api-v2/routes/popular_investors.js +7 -7
  9. package/functions/api-v2/routes/profile.js +2 -1
  10. package/functions/api-v2/tests/stage4-profile-paths.test.js +52 -0
  11. package/functions/api-v2/tests/stage5-aum-bigquery.test.js +81 -0
  12. package/functions/api-v2/tests/stage7-pi-page-views.test.js +55 -0
  13. package/functions/api-v2/tests/stage8-watchlist-membership.test.js +49 -0
  14. package/functions/api-v2/tests/stage9-user-alert-settings.test.js +81 -0
  15. package/functions/computation-system-v2/computations/BehavioralAnomaly.js +104 -81
  16. package/functions/computation-system-v2/computations/NewSectorExposure.js +7 -7
  17. package/functions/computation-system-v2/computations/NewSocialPost.js +6 -6
  18. package/functions/computation-system-v2/computations/PositionInvestedIncrease.js +11 -11
  19. package/functions/computation-system-v2/computations/SignedInUserPIProfileMetrics.js +1 -1
  20. package/functions/computation-system-v2/config/bulltrackers.config.js +8 -0
  21. package/functions/computation-system-v2/framework/core/Manifest.js +1 -0
  22. package/functions/computation-system-v2/handlers/scheduler.js +15 -24
  23. package/functions/core/utils/bigquery_utils.js +32 -0
  24. package/package.json +1 -1
@@ -0,0 +1,79 @@
1
+ /**
2
+ * @fileoverview Stage 3 unit test: Alert handler V2 path + pi_alert_history.
3
+ * Asserts handleComputationResultWrite parses V2 path and calls processAlertForPI correctly.
4
+ * Retained for inspection and debugging.
5
+ */
6
+
7
+ const path = require('path');
8
+ const assert = require('assert');
9
+
10
+ const alertHelpersPath = path.join(__dirname, '../helpers/alert_helpers.js');
11
+ const indexPath = path.join(__dirname, '../index.js');
12
+
13
+ let processAlertForPICalls = [];
14
+ const alertHelpers = require(alertHelpersPath);
15
+ const originalProcess = alertHelpers.processAlertForPI;
16
+ alertHelpers.processAlertForPI = async function (...args) {
17
+ processAlertForPICalls.push({ args });
18
+ };
19
+
20
+ delete require.cache[require.resolve(indexPath)];
21
+ const alertIndex = require(indexPath);
22
+ const { handleComputationResultWrite } = alertIndex;
23
+
24
+ async function runStage3Tests() {
25
+ let passed = 0;
26
+ let failed = 0;
27
+
28
+ try {
29
+ const logger = { log: () => {} };
30
+ const db = {};
31
+ const config = {};
32
+ const dependencies = { db, logger, config };
33
+
34
+ processAlertForPICalls = [];
35
+
36
+ const change = {
37
+ after: {
38
+ exists: true,
39
+ data: () => ({ triggered: true, change: 1.5, currentRisk: 4.5, previousRisk: 3 })
40
+ }
41
+ };
42
+ const context = {
43
+ params: {
44
+ date: '2025-12-26',
45
+ computationName: 'RiskScoreIncrease',
46
+ entityId: '12345'
47
+ }
48
+ };
49
+
50
+ await handleComputationResultWrite(change, context, config, dependencies);
51
+
52
+ assert.strictEqual(processAlertForPICalls.length, 1, 'processAlertForPI should be called once for per-entity path');
53
+ const call = processAlertForPICalls[0];
54
+ assert.strictEqual(call.args[0], db);
55
+ assert.strictEqual(call.args[1], logger);
56
+ assert.ok(call.args[2] === 12345 || call.args[2] === '12345', 'piCid should be 12345');
57
+ assert.strictEqual(call.args[3].computationName, 'RiskScoreIncrease');
58
+ assert.strictEqual(call.args[4].change, 1.5);
59
+ assert.strictEqual(call.args[5], '2025-12-26');
60
+
61
+ passed++;
62
+ console.log('[Stage3] Per-entity path: handleComputationResultWrite calls processAlertForPI once with correct args');
63
+ } catch (e) {
64
+ failed++;
65
+ console.error('[Stage3] FAIL:', e.message);
66
+ } finally {
67
+ alertHelpers.processAlertForPI = originalProcess;
68
+ }
69
+
70
+ console.log(`[Stage3] Done: ${passed} passed, ${failed} failed`);
71
+ return failed === 0;
72
+ }
73
+
74
+ runStage3Tests()
75
+ .then(ok => process.exit(ok ? 0 : 1))
76
+ .catch(err => {
77
+ console.error(err);
78
+ process.exit(1);
79
+ });