Skip to content

Commit f20dafa

Browse files
committed
add unit test to prevent drift
1 parent d6a78ca commit f20dafa

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @vitest-environment node
3+
*/
4+
import { describe, expect, it } from 'vitest'
5+
import { POLLING_PROVIDERS } from '@/triggers/constants'
6+
import { TRIGGER_REGISTRY } from '@/triggers/registry'
7+
8+
describe('POLLING_PROVIDERS sync with TriggerConfig.polling', () => {
9+
it('matches every trigger with polling: true in the registry', () => {
10+
const registryPollingProviders = new Set(
11+
Object.values(TRIGGER_REGISTRY)
12+
.filter((t) => t.polling === true)
13+
.map((t) => t.provider)
14+
)
15+
16+
expect(POLLING_PROVIDERS).toEqual(registryPollingProviders)
17+
})
18+
19+
it('no trigger with polling: true is missing from POLLING_PROVIDERS', () => {
20+
const missing: string[] = []
21+
for (const trigger of Object.values(TRIGGER_REGISTRY)) {
22+
if (trigger.polling && !POLLING_PROVIDERS.has(trigger.provider)) {
23+
missing.push(`${trigger.id} (provider: ${trigger.provider})`)
24+
}
25+
}
26+
expect(missing, `Triggers with polling: true missing from POLLING_PROVIDERS`).toEqual([])
27+
})
28+
29+
it('no POLLING_PROVIDERS entry lacks a polling: true trigger in the registry', () => {
30+
const extra: string[] = []
31+
for (const provider of POLLING_PROVIDERS) {
32+
const hasTrigger = Object.values(TRIGGER_REGISTRY).some(
33+
(t) => t.provider === provider && t.polling === true
34+
)
35+
if (!hasTrigger) {
36+
extra.push(provider)
37+
}
38+
}
39+
expect(extra, `POLLING_PROVIDERS entries with no matching polling trigger`).toEqual([])
40+
})
41+
})

0 commit comments

Comments
 (0)