@rankcli/agent-runtime 0.0.15 → 0.0.17
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/README.md +5 -4
- package/dist/index.d.mts +44 -393
- package/dist/index.d.ts +44 -393
- package/dist/index.js +22098 -26131
- package/dist/index.mjs +11834 -15857
- package/package.json +10 -4
- package/scripts/build-deno.ts +0 -134
- package/src/analyzers/core-web-vitals-analyzer.test.ts +0 -236
- package/src/analyzers/core-web-vitals-analyzer.ts +0 -557
- package/src/analyzers/geo-analyzer.test.ts +0 -310
- package/src/analyzers/geo-analyzer.ts +0 -814
- package/src/analyzers/image-optimization-analyzer.test.ts +0 -145
- package/src/analyzers/image-optimization-analyzer.ts +0 -348
- package/src/analyzers/index.ts +0 -233
- package/src/analyzers/internal-linking-analyzer.test.ts +0 -141
- package/src/analyzers/internal-linking-analyzer.ts +0 -419
- package/src/analyzers/mobile-seo-analyzer.test.ts +0 -140
- package/src/analyzers/mobile-seo-analyzer.ts +0 -455
- package/src/analyzers/security-headers-analyzer.test.ts +0 -115
- package/src/analyzers/security-headers-analyzer.ts +0 -318
- package/src/analyzers/structured-data-analyzer.test.ts +0 -210
- package/src/analyzers/structured-data-analyzer.ts +0 -590
- package/src/audit/ai/analyzer.ts +0 -347
- package/src/audit/ai/index.ts +0 -29
- package/src/audit/ai/prompts/content-analysis.ts +0 -271
- package/src/audit/ai/types.ts +0 -179
- package/src/audit/checks/additional-checks.ts +0 -439
- package/src/audit/checks/agent-experience.ts +0 -108
- package/src/audit/checks/ai-citation-worthiness.ts +0 -399
- package/src/audit/checks/ai-content-structure.ts +0 -325
- package/src/audit/checks/ai-readiness.ts +0 -406
- package/src/audit/checks/anchor-text.ts +0 -179
- package/src/audit/checks/answer-conciseness.ts +0 -322
- package/src/audit/checks/asset-minification.ts +0 -270
- package/src/audit/checks/bing-optimization.ts +0 -206
- package/src/audit/checks/brand-mention-optimization.ts +0 -349
- package/src/audit/checks/caching-headers.ts +0 -305
- package/src/audit/checks/canonical-advanced.ts +0 -150
- package/src/audit/checks/canonical-domain.ts +0 -196
- package/src/audit/checks/citation-quality.ts +0 -358
- package/src/audit/checks/client-rendering.ts +0 -542
- package/src/audit/checks/color-contrast.ts +0 -342
- package/src/audit/checks/content-freshness.ts +0 -170
- package/src/audit/checks/content-science.ts +0 -589
- package/src/audit/checks/conversion-elements.ts +0 -526
- package/src/audit/checks/crawlability.ts +0 -220
- package/src/audit/checks/directory-listing.ts +0 -172
- package/src/audit/checks/dom-analysis.ts +0 -191
- package/src/audit/checks/dom-size.ts +0 -246
- package/src/audit/checks/duplicate-content.ts +0 -194
- package/src/audit/checks/eeat-signals.ts +0 -990
- package/src/audit/checks/entity-seo.ts +0 -396
- package/src/audit/checks/featured-snippet.ts +0 -473
- package/src/audit/checks/freshness-signals.ts +0 -443
- package/src/audit/checks/funnel-intent.ts +0 -463
- package/src/audit/checks/hreflang.ts +0 -174
- package/src/audit/checks/html-compliance.ts +0 -302
- package/src/audit/checks/image-dimensions.ts +0 -167
- package/src/audit/checks/images.ts +0 -160
- package/src/audit/checks/indexnow.ts +0 -275
- package/src/audit/checks/interactive-tools.ts +0 -475
- package/src/audit/checks/internal-link-graph.ts +0 -436
- package/src/audit/checks/keyword-analysis.ts +0 -239
- package/src/audit/checks/keyword-cannibalization.ts +0 -385
- package/src/audit/checks/keyword-placement.ts +0 -471
- package/src/audit/checks/links.ts +0 -273
- package/src/audit/checks/llms-txt.ts +0 -224
- package/src/audit/checks/local-seo.ts +0 -296
- package/src/audit/checks/mobile.ts +0 -167
- package/src/audit/checks/modern-images.ts +0 -226
- package/src/audit/checks/navboost-signals.ts +0 -395
- package/src/audit/checks/on-page.ts +0 -209
- package/src/audit/checks/page-resources.ts +0 -285
- package/src/audit/checks/pagination.ts +0 -180
- package/src/audit/checks/performance.ts +0 -153
- package/src/audit/checks/platform-presence.ts +0 -580
- package/src/audit/checks/rag-chunk-readiness.test.ts +0 -159
- package/src/audit/checks/rag-chunk-readiness.ts +0 -163
- package/src/audit/checks/redirect-analysis.ts +0 -153
- package/src/audit/checks/redirect-chain.ts +0 -389
- package/src/audit/checks/resource-hints.ts +0 -420
- package/src/audit/checks/responsive-css.ts +0 -247
- package/src/audit/checks/responsive-images.ts +0 -396
- package/src/audit/checks/review-ecosystem.ts +0 -415
- package/src/audit/checks/robots-validation.ts +0 -373
- package/src/audit/checks/security-headers.ts +0 -188
- package/src/audit/checks/security.ts +0 -144
- package/src/audit/checks/serp-preview.ts +0 -251
- package/src/audit/checks/site-maturity.ts +0 -453
- package/src/audit/checks/social-meta.test.ts +0 -275
- package/src/audit/checks/social-meta.ts +0 -134
- package/src/audit/checks/soft-404.ts +0 -151
- package/src/audit/checks/structured-data.ts +0 -238
- package/src/audit/checks/tech-detection.ts +0 -496
- package/src/audit/checks/topical-clusters.ts +0 -435
- package/src/audit/checks/tracker-bloat.ts +0 -462
- package/src/audit/checks/tracking-verification.test.ts +0 -371
- package/src/audit/checks/tracking-verification.ts +0 -636
- package/src/audit/checks/url-safety.ts +0 -682
- package/src/audit/deno-entry.ts +0 -66
- package/src/audit/discovery/index.ts +0 -15
- package/src/audit/discovery/link-crawler.ts +0 -233
- package/src/audit/discovery/repo-routes.ts +0 -347
- package/src/audit/engine.ts +0 -633
- package/src/audit/fixes/index.ts +0 -209
- package/src/audit/fixes/social-meta-fixes.test.ts +0 -329
- package/src/audit/fixes/social-meta-fixes.ts +0 -463
- package/src/audit/index.ts +0 -74
- package/src/audit/runner.test.ts +0 -299
- package/src/audit/runner.ts +0 -130
- package/src/audit/types.ts +0 -1987
- package/src/content/featured-snippet.ts +0 -367
- package/src/content/generator.test.ts +0 -534
- package/src/content/generator.ts +0 -501
- package/src/content/headline.ts +0 -317
- package/src/content/index.ts +0 -62
- package/src/content/intent.ts +0 -258
- package/src/content/keyword-density.ts +0 -349
- package/src/content/readability.ts +0 -262
- package/src/executor.ts +0 -336
- package/src/fixer/framework-fixes.test.ts +0 -489
- package/src/fixer/framework-fixes.ts +0 -5287
- package/src/fixer/index.ts +0 -6
- package/src/fixer/schemas.ts +0 -971
- package/src/fixer.ts +0 -642
- package/src/frameworks/detector.test.ts +0 -248
- package/src/frameworks/detector.ts +0 -899
- package/src/frameworks/index.ts +0 -68
- package/src/frameworks/recipes/angular.yaml +0 -171
- package/src/frameworks/recipes/astro.yaml +0 -206
- package/src/frameworks/recipes/django.yaml +0 -180
- package/src/frameworks/recipes/laravel.yaml +0 -137
- package/src/frameworks/recipes/nextjs.yaml +0 -268
- package/src/frameworks/recipes/nuxt.yaml +0 -175
- package/src/frameworks/recipes/rails.yaml +0 -188
- package/src/frameworks/recipes/react.yaml +0 -202
- package/src/frameworks/recipes/sveltekit.yaml +0 -154
- package/src/frameworks/recipes/vue.yaml +0 -137
- package/src/frameworks/recipes/wordpress.yaml +0 -209
- package/src/frameworks/suggestion-engine.ts +0 -357
- package/src/geo/geo-content.test.ts +0 -305
- package/src/geo/geo-content.ts +0 -266
- package/src/geo/geo-history.test.ts +0 -473
- package/src/geo/geo-history.ts +0 -433
- package/src/geo/geo-tracker.test.ts +0 -359
- package/src/geo/geo-tracker.ts +0 -411
- package/src/geo/index.ts +0 -11
- package/src/geo/llm-citation-checker.ts +0 -188
- package/src/git/commit-helper.test.ts +0 -261
- package/src/git/commit-helper.ts +0 -329
- package/src/git/index.ts +0 -12
- package/src/git/pr-helper.test.ts +0 -284
- package/src/git/pr-helper.ts +0 -307
- package/src/index.ts +0 -76
- package/src/keywords/ai-keyword-engine.ts +0 -1062
- package/src/keywords/ai-summarizer.ts +0 -387
- package/src/keywords/ci-mode.ts +0 -555
- package/src/keywords/engine.ts +0 -359
- package/src/keywords/index.ts +0 -151
- package/src/keywords/llm-judge.ts +0 -357
- package/src/keywords/nlp-analysis.ts +0 -706
- package/src/keywords/prioritizer.ts +0 -295
- package/src/keywords/site-crawler.ts +0 -342
- package/src/keywords/sources/autocomplete.ts +0 -139
- package/src/keywords/sources/competitive-search.ts +0 -450
- package/src/keywords/sources/competitor-analysis.ts +0 -374
- package/src/keywords/sources/dataforseo.ts +0 -206
- package/src/keywords/sources/free-sources.ts +0 -294
- package/src/keywords/sources/gsc.ts +0 -123
- package/src/keywords/topic-grouping.ts +0 -327
- package/src/keywords/types.ts +0 -144
- package/src/keywords/wizard.ts +0 -457
- package/src/loader.ts +0 -40
- package/src/ranking/index.ts +0 -5
- package/src/ranking/serp-client.ts +0 -348
- package/src/ranking/tracker.ts +0 -380
- package/src/ranking/types.ts +0 -123
- package/src/reports/index.ts +0 -7
- package/src/reports/report-generator.test.ts +0 -293
- package/src/reports/report-generator.ts +0 -713
- package/src/scheduler/alerts.test.ts +0 -458
- package/src/scheduler/alerts.ts +0 -328
- package/src/scheduler/index.ts +0 -8
- package/src/scheduler/scheduled-audit.test.ts +0 -377
- package/src/scheduler/scheduled-audit.ts +0 -149
- package/src/test/integration-test.ts +0 -325
- package/src/tools/analyzer.ts +0 -373
- package/src/tools/crawl.ts +0 -293
- package/src/tools/files.ts +0 -301
- package/src/tools/h1-fixer.ts +0 -249
- package/src/tools/index.ts +0 -67
- package/src/tracking/github-action.ts +0 -326
- package/src/tracking/google-analytics.ts +0 -265
- package/src/tracking/index.ts +0 -45
- package/src/tracking/report-generator.ts +0 -386
- package/src/tracking/search-console.ts +0 -335
- package/src/types.ts +0 -148
- package/src/utils/http.ts +0 -302
- package/src/wasm-adapter.ts +0 -297
- package/src/wasm-entry.ts +0 -14
- package/tsconfig.json +0 -17
- package/tsup.wasm.config.ts +0 -26
- package/vitest.config.ts +0 -15
|
@@ -1,458 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
sendSlackAlert,
|
|
4
|
-
sendDiscordAlert,
|
|
5
|
-
sendAlert,
|
|
6
|
-
formatAlertMessage,
|
|
7
|
-
shouldSendAlert,
|
|
8
|
-
AlertConfig,
|
|
9
|
-
AlertType,
|
|
10
|
-
AuditAlertPayload,
|
|
11
|
-
} from './alerts.js';
|
|
12
|
-
|
|
13
|
-
// Mock fetch globally
|
|
14
|
-
const mockFetch = vi.fn();
|
|
15
|
-
vi.stubGlobal('fetch', mockFetch);
|
|
16
|
-
|
|
17
|
-
describe('alerts', () => {
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
vi.clearAllMocks();
|
|
20
|
-
mockFetch.mockReset();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe('formatAlertMessage', () => {
|
|
24
|
-
it('formats score drop alert with details', () => {
|
|
25
|
-
const payload: AuditAlertPayload = {
|
|
26
|
-
projectId: 'proj-1',
|
|
27
|
-
projectName: 'My App',
|
|
28
|
-
url: 'https://myapp.com',
|
|
29
|
-
score: 55,
|
|
30
|
-
previousScore: 72,
|
|
31
|
-
issuesFound: 5,
|
|
32
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
const message = formatAlertMessage('score_drop', payload);
|
|
36
|
-
|
|
37
|
-
expect(message.title).toContain('Score Drop');
|
|
38
|
-
expect(message.title).toContain('My App');
|
|
39
|
-
expect(message.body).toContain('55');
|
|
40
|
-
expect(message.body).toContain('72');
|
|
41
|
-
expect(message.body).toContain('-17');
|
|
42
|
-
expect(message.severity).toBe('warning');
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it('formats error alert with severity', () => {
|
|
46
|
-
const payload: AuditAlertPayload = {
|
|
47
|
-
projectId: 'proj-1',
|
|
48
|
-
projectName: 'My App',
|
|
49
|
-
url: 'https://myapp.com',
|
|
50
|
-
score: 45,
|
|
51
|
-
issuesFound: 8,
|
|
52
|
-
errorCount: 3,
|
|
53
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
const message = formatAlertMessage('error', payload);
|
|
57
|
-
|
|
58
|
-
expect(message.title).toContain('Critical Issues');
|
|
59
|
-
expect(message.body).toContain('3 errors');
|
|
60
|
-
expect(message.severity).toBe('error');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('formats weekly report alert', () => {
|
|
64
|
-
const payload: AuditAlertPayload = {
|
|
65
|
-
projectId: 'proj-1',
|
|
66
|
-
projectName: 'My App',
|
|
67
|
-
url: 'https://myapp.com',
|
|
68
|
-
score: 78,
|
|
69
|
-
previousScore: 72,
|
|
70
|
-
issuesFound: 2,
|
|
71
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
const message = formatAlertMessage('weekly_report', payload);
|
|
75
|
-
|
|
76
|
-
expect(message.title).toContain('Weekly SEO Report');
|
|
77
|
-
expect(message.body).toContain('78');
|
|
78
|
-
expect(message.body).toContain('+6');
|
|
79
|
-
expect(message.severity).toBe('info');
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('formats PR created alert', () => {
|
|
83
|
-
const payload: AuditAlertPayload = {
|
|
84
|
-
projectId: 'proj-1',
|
|
85
|
-
projectName: 'My App',
|
|
86
|
-
url: 'https://myapp.com',
|
|
87
|
-
score: 65,
|
|
88
|
-
issuesFound: 4,
|
|
89
|
-
prUrl: 'https://github.com/owner/repo/pull/42',
|
|
90
|
-
prNumber: 42,
|
|
91
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const message = formatAlertMessage('pr_created', payload);
|
|
95
|
-
|
|
96
|
-
expect(message.title).toContain('PR Created');
|
|
97
|
-
expect(message.body).toContain('#42');
|
|
98
|
-
expect(message.body).toContain('github.com');
|
|
99
|
-
expect(message.severity).toBe('success');
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
describe('shouldSendAlert', () => {
|
|
104
|
-
it('returns true when alert type is in config', () => {
|
|
105
|
-
const config: AlertConfig = {
|
|
106
|
-
type: 'slack',
|
|
107
|
-
webhookUrl: 'https://hooks.slack.com/...',
|
|
108
|
-
on: ['error', 'score_drop'],
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
expect(shouldSendAlert(config, 'error')).toBe(true);
|
|
112
|
-
expect(shouldSendAlert(config, 'score_drop')).toBe(true);
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('returns false when alert type is not in config', () => {
|
|
116
|
-
const config: AlertConfig = {
|
|
117
|
-
type: 'slack',
|
|
118
|
-
webhookUrl: 'https://hooks.slack.com/...',
|
|
119
|
-
on: ['error'],
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
expect(shouldSendAlert(config, 'weekly_report')).toBe(false);
|
|
123
|
-
expect(shouldSendAlert(config, 'pr_created')).toBe(false);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('returns true for score_drop when threshold exceeded', () => {
|
|
127
|
-
const config: AlertConfig = {
|
|
128
|
-
type: 'slack',
|
|
129
|
-
webhookUrl: 'https://hooks.slack.com/...',
|
|
130
|
-
on: ['score_drop'],
|
|
131
|
-
scoreDropThreshold: 10,
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
const payload: AuditAlertPayload = {
|
|
135
|
-
projectId: 'proj-1',
|
|
136
|
-
projectName: 'My App',
|
|
137
|
-
url: 'https://myapp.com',
|
|
138
|
-
score: 55,
|
|
139
|
-
previousScore: 70, // 15 point drop
|
|
140
|
-
issuesFound: 5,
|
|
141
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
expect(shouldSendAlert(config, 'score_drop', payload)).toBe(true);
|
|
145
|
-
});
|
|
146
|
-
|
|
147
|
-
it('returns false for score_drop when threshold not exceeded', () => {
|
|
148
|
-
const config: AlertConfig = {
|
|
149
|
-
type: 'slack',
|
|
150
|
-
webhookUrl: 'https://hooks.slack.com/...',
|
|
151
|
-
on: ['score_drop'],
|
|
152
|
-
scoreDropThreshold: 10,
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
const payload: AuditAlertPayload = {
|
|
156
|
-
projectId: 'proj-1',
|
|
157
|
-
projectName: 'My App',
|
|
158
|
-
url: 'https://myapp.com',
|
|
159
|
-
score: 68,
|
|
160
|
-
previousScore: 72, // 4 point drop, below threshold
|
|
161
|
-
issuesFound: 1,
|
|
162
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
expect(shouldSendAlert(config, 'score_drop', payload)).toBe(false);
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
describe('sendSlackAlert', () => {
|
|
170
|
-
it('sends formatted message to Slack webhook', async () => {
|
|
171
|
-
mockFetch.mockResolvedValue({ ok: true });
|
|
172
|
-
|
|
173
|
-
const payload: AuditAlertPayload = {
|
|
174
|
-
projectId: 'proj-1',
|
|
175
|
-
projectName: 'My App',
|
|
176
|
-
url: 'https://myapp.com',
|
|
177
|
-
score: 72,
|
|
178
|
-
issuesFound: 3,
|
|
179
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
180
|
-
};
|
|
181
|
-
|
|
182
|
-
const result = await sendSlackAlert(
|
|
183
|
-
'https://hooks.slack.com/services/xxx',
|
|
184
|
-
'weekly_report',
|
|
185
|
-
payload
|
|
186
|
-
);
|
|
187
|
-
|
|
188
|
-
expect(result.success).toBe(true);
|
|
189
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
190
|
-
'https://hooks.slack.com/services/xxx',
|
|
191
|
-
expect.objectContaining({
|
|
192
|
-
method: 'POST',
|
|
193
|
-
headers: { 'Content-Type': 'application/json' },
|
|
194
|
-
body: expect.stringContaining('Weekly SEO Report'),
|
|
195
|
-
})
|
|
196
|
-
);
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
it('formats Slack message with blocks', async () => {
|
|
200
|
-
mockFetch.mockResolvedValue({ ok: true });
|
|
201
|
-
|
|
202
|
-
const payload: AuditAlertPayload = {
|
|
203
|
-
projectId: 'proj-1',
|
|
204
|
-
projectName: 'My App',
|
|
205
|
-
url: 'https://myapp.com',
|
|
206
|
-
score: 55,
|
|
207
|
-
previousScore: 70,
|
|
208
|
-
issuesFound: 5,
|
|
209
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
210
|
-
};
|
|
211
|
-
|
|
212
|
-
await sendSlackAlert('https://hooks.slack.com/xxx', 'score_drop', payload);
|
|
213
|
-
|
|
214
|
-
const callBody = JSON.parse(mockFetch.mock.calls[0][1].body);
|
|
215
|
-
expect(callBody.blocks).toBeDefined();
|
|
216
|
-
expect(callBody.blocks.length).toBeGreaterThan(0);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
it('handles Slack API errors', async () => {
|
|
220
|
-
mockFetch.mockResolvedValue({ ok: false, status: 404 });
|
|
221
|
-
|
|
222
|
-
const payload: AuditAlertPayload = {
|
|
223
|
-
projectId: 'proj-1',
|
|
224
|
-
projectName: 'My App',
|
|
225
|
-
url: 'https://myapp.com',
|
|
226
|
-
score: 72,
|
|
227
|
-
issuesFound: 2,
|
|
228
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
const result = await sendSlackAlert(
|
|
232
|
-
'https://hooks.slack.com/invalid',
|
|
233
|
-
'weekly_report',
|
|
234
|
-
payload
|
|
235
|
-
);
|
|
236
|
-
|
|
237
|
-
expect(result.success).toBe(false);
|
|
238
|
-
expect(result.error).toContain('404');
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
it('handles network errors', async () => {
|
|
242
|
-
mockFetch.mockRejectedValue(new Error('Network error'));
|
|
243
|
-
|
|
244
|
-
const payload: AuditAlertPayload = {
|
|
245
|
-
projectId: 'proj-1',
|
|
246
|
-
projectName: 'My App',
|
|
247
|
-
url: 'https://myapp.com',
|
|
248
|
-
score: 72,
|
|
249
|
-
issuesFound: 2,
|
|
250
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
const result = await sendSlackAlert(
|
|
254
|
-
'https://hooks.slack.com/xxx',
|
|
255
|
-
'weekly_report',
|
|
256
|
-
payload
|
|
257
|
-
);
|
|
258
|
-
|
|
259
|
-
expect(result.success).toBe(false);
|
|
260
|
-
expect(result.error).toContain('Network error');
|
|
261
|
-
});
|
|
262
|
-
});
|
|
263
|
-
|
|
264
|
-
describe('sendDiscordAlert', () => {
|
|
265
|
-
it('sends formatted message to Discord webhook', async () => {
|
|
266
|
-
mockFetch.mockResolvedValue({ ok: true });
|
|
267
|
-
|
|
268
|
-
const payload: AuditAlertPayload = {
|
|
269
|
-
projectId: 'proj-1',
|
|
270
|
-
projectName: 'My App',
|
|
271
|
-
url: 'https://myapp.com',
|
|
272
|
-
score: 72,
|
|
273
|
-
issuesFound: 3,
|
|
274
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
const result = await sendDiscordAlert(
|
|
278
|
-
'https://discord.com/api/webhooks/xxx',
|
|
279
|
-
'weekly_report',
|
|
280
|
-
payload
|
|
281
|
-
);
|
|
282
|
-
|
|
283
|
-
expect(result.success).toBe(true);
|
|
284
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
285
|
-
'https://discord.com/api/webhooks/xxx',
|
|
286
|
-
expect.objectContaining({
|
|
287
|
-
method: 'POST',
|
|
288
|
-
headers: { 'Content-Type': 'application/json' },
|
|
289
|
-
})
|
|
290
|
-
);
|
|
291
|
-
});
|
|
292
|
-
|
|
293
|
-
it('formats Discord message with embeds', async () => {
|
|
294
|
-
mockFetch.mockResolvedValue({ ok: true });
|
|
295
|
-
|
|
296
|
-
const payload: AuditAlertPayload = {
|
|
297
|
-
projectId: 'proj-1',
|
|
298
|
-
projectName: 'My App',
|
|
299
|
-
url: 'https://myapp.com',
|
|
300
|
-
score: 55,
|
|
301
|
-
previousScore: 70,
|
|
302
|
-
issuesFound: 5,
|
|
303
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
await sendDiscordAlert('https://discord.com/api/webhooks/xxx', 'score_drop', payload);
|
|
307
|
-
|
|
308
|
-
const callBody = JSON.parse(mockFetch.mock.calls[0][1].body);
|
|
309
|
-
expect(callBody.embeds).toBeDefined();
|
|
310
|
-
expect(callBody.embeds.length).toBeGreaterThan(0);
|
|
311
|
-
expect(callBody.embeds[0].color).toBeDefined();
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
it('handles Discord API errors', async () => {
|
|
315
|
-
mockFetch.mockResolvedValue({ ok: false, status: 401 });
|
|
316
|
-
|
|
317
|
-
const payload: AuditAlertPayload = {
|
|
318
|
-
projectId: 'proj-1',
|
|
319
|
-
projectName: 'My App',
|
|
320
|
-
url: 'https://myapp.com',
|
|
321
|
-
score: 72,
|
|
322
|
-
issuesFound: 2,
|
|
323
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
324
|
-
};
|
|
325
|
-
|
|
326
|
-
const result = await sendDiscordAlert(
|
|
327
|
-
'https://discord.com/api/webhooks/invalid',
|
|
328
|
-
'weekly_report',
|
|
329
|
-
payload
|
|
330
|
-
);
|
|
331
|
-
|
|
332
|
-
expect(result.success).toBe(false);
|
|
333
|
-
expect(result.error).toContain('401');
|
|
334
|
-
});
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
describe('sendAlert', () => {
|
|
338
|
-
it('sends to Slack when type is slack', async () => {
|
|
339
|
-
mockFetch.mockResolvedValue({ ok: true });
|
|
340
|
-
|
|
341
|
-
const config: AlertConfig = {
|
|
342
|
-
type: 'slack',
|
|
343
|
-
webhookUrl: 'https://hooks.slack.com/xxx',
|
|
344
|
-
on: ['weekly_report'],
|
|
345
|
-
};
|
|
346
|
-
|
|
347
|
-
const payload: AuditAlertPayload = {
|
|
348
|
-
projectId: 'proj-1',
|
|
349
|
-
projectName: 'My App',
|
|
350
|
-
url: 'https://myapp.com',
|
|
351
|
-
score: 72,
|
|
352
|
-
issuesFound: 3,
|
|
353
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
354
|
-
};
|
|
355
|
-
|
|
356
|
-
const result = await sendAlert(config, 'weekly_report', payload);
|
|
357
|
-
|
|
358
|
-
expect(result.success).toBe(true);
|
|
359
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
360
|
-
'https://hooks.slack.com/xxx',
|
|
361
|
-
expect.anything()
|
|
362
|
-
);
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
it('sends to Discord when type is discord', async () => {
|
|
366
|
-
mockFetch.mockResolvedValue({ ok: true });
|
|
367
|
-
|
|
368
|
-
const config: AlertConfig = {
|
|
369
|
-
type: 'discord',
|
|
370
|
-
webhookUrl: 'https://discord.com/api/webhooks/xxx',
|
|
371
|
-
on: ['error'],
|
|
372
|
-
};
|
|
373
|
-
|
|
374
|
-
const payload: AuditAlertPayload = {
|
|
375
|
-
projectId: 'proj-1',
|
|
376
|
-
projectName: 'My App',
|
|
377
|
-
url: 'https://myapp.com',
|
|
378
|
-
score: 45,
|
|
379
|
-
issuesFound: 8,
|
|
380
|
-
errorCount: 3,
|
|
381
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
382
|
-
};
|
|
383
|
-
|
|
384
|
-
const result = await sendAlert(config, 'error', payload);
|
|
385
|
-
|
|
386
|
-
expect(result.success).toBe(true);
|
|
387
|
-
expect(mockFetch).toHaveBeenCalledWith(
|
|
388
|
-
'https://discord.com/api/webhooks/xxx',
|
|
389
|
-
expect.anything()
|
|
390
|
-
);
|
|
391
|
-
});
|
|
392
|
-
|
|
393
|
-
it('skips alert if type not in config.on', async () => {
|
|
394
|
-
const config: AlertConfig = {
|
|
395
|
-
type: 'slack',
|
|
396
|
-
webhookUrl: 'https://hooks.slack.com/xxx',
|
|
397
|
-
on: ['error'],
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
const payload: AuditAlertPayload = {
|
|
401
|
-
projectId: 'proj-1',
|
|
402
|
-
projectName: 'My App',
|
|
403
|
-
url: 'https://myapp.com',
|
|
404
|
-
score: 72,
|
|
405
|
-
issuesFound: 3,
|
|
406
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
const result = await sendAlert(config, 'weekly_report', payload);
|
|
410
|
-
|
|
411
|
-
expect(result.success).toBe(true);
|
|
412
|
-
expect(result.skipped).toBe(true);
|
|
413
|
-
expect(mockFetch).not.toHaveBeenCalled();
|
|
414
|
-
});
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
describe('integration scenarios', () => {
|
|
418
|
-
it('handles multiple alert configs', async () => {
|
|
419
|
-
mockFetch.mockResolvedValue({ ok: true });
|
|
420
|
-
|
|
421
|
-
const configs: AlertConfig[] = [
|
|
422
|
-
{
|
|
423
|
-
type: 'slack',
|
|
424
|
-
webhookUrl: 'https://hooks.slack.com/xxx',
|
|
425
|
-
on: ['error', 'score_drop'],
|
|
426
|
-
},
|
|
427
|
-
{
|
|
428
|
-
type: 'discord',
|
|
429
|
-
webhookUrl: 'https://discord.com/api/webhooks/xxx',
|
|
430
|
-
on: ['weekly_report'],
|
|
431
|
-
},
|
|
432
|
-
];
|
|
433
|
-
|
|
434
|
-
const payload: AuditAlertPayload = {
|
|
435
|
-
projectId: 'proj-1',
|
|
436
|
-
projectName: 'My App',
|
|
437
|
-
url: 'https://myapp.com',
|
|
438
|
-
score: 55,
|
|
439
|
-
previousScore: 70,
|
|
440
|
-
issuesFound: 5,
|
|
441
|
-
timestamp: '2024-01-15T10:00:00Z',
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
// Send to all configs
|
|
445
|
-
const results = await Promise.all(
|
|
446
|
-
configs.map(config => sendAlert(config, 'score_drop', payload))
|
|
447
|
-
);
|
|
448
|
-
|
|
449
|
-
// Slack should send (score_drop is in its config)
|
|
450
|
-
expect(results[0].success).toBe(true);
|
|
451
|
-
expect(results[0].skipped).toBeFalsy();
|
|
452
|
-
|
|
453
|
-
// Discord should skip (score_drop not in its config)
|
|
454
|
-
expect(results[1].success).toBe(true);
|
|
455
|
-
expect(results[1].skipped).toBe(true);
|
|
456
|
-
});
|
|
457
|
-
});
|
|
458
|
-
});
|