@beechcms/api 0.4.0 → 0.4.2
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/assets/dashboard/assets/index-BKWnlvnV.css +1 -0
- package/assets/dashboard/assets/index-C1P9BXnU.js +629 -0
- package/assets/dashboard/index.html +2 -2
- package/migrations/0000_v040_base.sql +25 -0
- package/migrations/0029_automations.sql +14 -0
- package/package.json +4 -3
- package/src/auth/bcrypt-hash-provider.ts +20 -0
- package/src/auth/constants.ts +3 -3
- package/src/auth/generate-refresh-token.test.ts +19 -0
- package/src/auth/hash-provider.test.ts +46 -0
- package/src/auth/in-memory-hash-provider.ts +13 -0
- package/src/auth/jose-token-service.ts +55 -0
- package/src/auth/login.test.ts +92 -0
- package/src/auth/login.ts +15 -32
- package/src/auth/refresh.ts +0 -122
- package/src/auth/static-token-service.ts +18 -0
- package/src/auth/token-service.test.ts +82 -0
- package/src/factory.ts +80 -80
- package/src/features/automations/__tests__/action-executors.test.ts +268 -0
- package/src/features/automations/__tests__/automation-runner.test.ts +192 -0
- package/src/features/automations/__tests__/automation-runner.utils.test.ts +56 -0
- package/src/features/automations/__tests__/automations.handler.test.ts +260 -0
- package/src/features/automations/__tests__/automations.repository.test.ts +159 -0
- package/src/features/automations/__tests__/automations.schema.test.ts +134 -0
- package/src/features/automations/__tests__/context-resolver.test.ts +122 -0
- package/src/features/automations/__tests__/cron-runner.test.ts +263 -0
- package/src/features/automations/__tests__/cron-runner.utils.test.ts +140 -0
- package/src/features/automations/__tests__/set-variable.executor.test.ts +306 -0
- package/src/features/automations/__tests__/template-grammar.test.ts +304 -0
- package/src/features/automations/__tests__/when-evaluator.test.ts +270 -0
- package/src/features/automations/__tests__/when-pushdown.test.ts +277 -0
- package/src/features/automations/action-executors/create-entry.executor.ts +23 -0
- package/src/features/automations/action-executors/edit-field.executor.ts +22 -0
- package/src/features/automations/action-executors/index.ts +33 -0
- package/src/features/automations/action-executors/send-mail.executor.ts +42 -0
- package/src/features/automations/action-executors/set-variable.executor.ts +146 -0
- package/src/features/automations/action-executors/webhook.executor.ts +25 -0
- package/src/features/automations/automation-runner.ts +81 -0
- package/src/features/automations/automation-runner.utils.ts +43 -0
- package/src/features/automations/automations.handler.ts +193 -0
- package/src/features/automations/automations.schema.ts +160 -0
- package/src/features/automations/context-resolver.ts +148 -0
- package/src/features/automations/cron-runner.ts +136 -0
- package/src/features/automations/cron-runner.utils.ts +40 -0
- package/src/features/automations/filter-translation.ts +42 -0
- package/src/features/automations/index.ts +12 -0
- package/src/features/automations/template-grammar.ts +241 -0
- package/src/features/automations/var-access-resolver.ts +136 -0
- package/src/features/automations/when-evaluator.ts +83 -0
- package/src/features/automations/when-pushdown.ts +53 -0
- package/src/features/content/handlers/create.ts +22 -10
- package/src/features/content/handlers/delete.ts +21 -10
- package/src/features/content/handlers/update.ts +21 -9
- package/src/features/draft/draft.handler.ts +51 -153
- package/src/features/draft/draft.middleware.ts +62 -0
- package/src/features/email/email.service.ts +13 -0
- package/src/features/email/email.types.ts +10 -0
- package/src/features/email/index.ts +2 -1
- package/src/features/email/templates/automation-mail.ts +15 -0
- package/src/features/notifications/notifications.handler.ts +25 -54
- package/src/features/password-reset/request.ts +17 -41
- package/src/features/password-reset/reset.ts +18 -54
- package/src/features/rotate-field/rotate-field.handler.ts +15 -19
- package/src/features/schema/schema.handler.ts +1 -1
- package/src/features/settings/settings.handler.ts +64 -176
- package/src/features/setup/index.ts +12 -17
- package/src/features/stats/stats.handler.ts +110 -138
- package/src/index.ts +40 -8
- package/src/middleware/auth-providers.middleware.ts +32 -0
- package/src/middleware/observability.middleware.ts +52 -0
- package/src/middleware/rate-limit.middleware.ts +41 -0
- package/src/middleware/repository.middleware.ts +72 -5
- package/src/middleware.ts +15 -35
- package/src/public/cache-utils.ts +34 -0
- package/src/public/entry-projection.ts +42 -0
- package/src/public/idempotency.ts +19 -0
- package/src/public/problem-details.ts +5 -0
- package/src/public/public-add.ts +110 -166
- package/src/public/public-edit.ts +4 -3
- package/src/public/public-read.ts +59 -216
- package/src/public/public-routes.ts +2 -2
- package/src/public/query-builder.test.ts +220 -0
- package/src/public/rate-limit-middleware.ts +7 -19
- package/src/public/read-list.ts +50 -0
- package/src/public/read-single.ts +44 -0
- package/src/rate-limit/cloudflare-rate-limiter.test.ts +26 -0
- package/src/rate-limit/cloudflare-rate-limiter.ts +11 -0
- package/src/rate-limit/in-memory-rate-limiter.test.ts +33 -0
- package/src/rate-limit/in-memory-rate-limiter.ts +13 -0
- package/src/rate-limit/no-op-rate-limiter.test.ts +18 -0
- package/src/rate-limit/no-op-rate-limiter.ts +7 -0
- package/src/search-utils.test.ts +207 -0
- package/src/search-utils.ts +18 -1
- package/src/search.ts +24 -35
- package/src/shared/apply-policies.test.ts +77 -0
- package/src/shared/automations.repository.d1.ts +146 -0
- package/src/shared/background-notification-service.test.ts +58 -0
- package/src/shared/background-notification-service.ts +48 -0
- package/src/shared/content-utils.test.ts +161 -0
- package/src/shared/content.repository.d1.test.ts +312 -0
- package/src/shared/d1-activity-log.repository.test.ts +136 -0
- package/src/shared/d1-activity-log.repository.ts +101 -0
- package/src/shared/d1-activity-logger.test.ts +82 -0
- package/src/shared/d1-activity-logger.ts +63 -0
- package/src/shared/d1-analytics.repository.test.ts +74 -0
- package/src/shared/d1-analytics.repository.ts +81 -0
- package/src/shared/d1-content-scan.repository.test.ts +76 -0
- package/src/shared/d1-content-scan.repository.ts +29 -0
- package/src/shared/d1-notification.repository.test.ts +124 -0
- package/src/shared/d1-notification.repository.ts +114 -0
- package/src/shared/d1-password-reset-token.repository.test.ts +77 -0
- package/src/shared/d1-password-reset-token.repository.ts +52 -0
- package/src/shared/d1-search.repository.test.ts +83 -0
- package/src/shared/d1-search.repository.ts +84 -0
- package/src/shared/d1-session.repository.test.ts +121 -0
- package/src/shared/d1-session.repository.ts +98 -0
- package/src/shared/d1-user.repository.test.ts +147 -0
- package/src/shared/d1-user.repository.ts +109 -0
- package/src/shared/d1-widget.repository.test.ts +217 -0
- package/src/shared/d1-widget.repository.ts +337 -0
- package/src/shared/execution-context-scheduler.ts +9 -0
- package/src/shared/fixed-clock.ts +21 -0
- package/src/shared/idempotency.repository.d1.test.ts +79 -0
- package/src/shared/in-memory-activity-logger.ts +15 -0
- package/src/shared/in-memory-notification-service.ts +15 -0
- package/src/shared/media.repository.d1.test.ts +103 -0
- package/src/shared/media.repository.d1.ts +1 -1
- package/src/shared/request-utils.ts +22 -0
- package/src/shared/sequential-id-generator.ts +22 -0
- package/src/shared/storage-utils.ts +3 -3
- package/src/shared/system-stats.repository.d1.test.ts +54 -0
- package/src/types.ts +24 -3
- package/src/upload.ts +17 -9
- package/src/widget.ts +112 -253
- package/assets/dashboard/assets/index-CewtCjom.css +0 -1
- package/assets/dashboard/assets/index-FQ6JhvRH.js +0 -554
- package/src/shared/activity-logger.ts +0 -79
- package/src/shared/notification-service.ts +0 -56
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
createAutomationSchema,
|
|
4
|
+
updateAutomationSchema,
|
|
5
|
+
toggleAutomationSchema,
|
|
6
|
+
} from '../automations.schema'
|
|
7
|
+
|
|
8
|
+
const validWebhookAction = { type: 'webhook' as const, url: 'https://example.com/hook' }
|
|
9
|
+
|
|
10
|
+
const minimalValid = {
|
|
11
|
+
seed_slug: 'posts',
|
|
12
|
+
name: 'notify-on-create',
|
|
13
|
+
triggers: [{ event: 'create' as const }],
|
|
14
|
+
actions: [validWebhookAction],
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('createAutomationSchema', () => {
|
|
18
|
+
it('accepts minimal valid create payload', () => {
|
|
19
|
+
expect(createAutomationSchema.safeParse(minimalValid).success).toBe(true)
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('rejects cron trigger without cron expression', () => {
|
|
23
|
+
const result = createAutomationSchema.safeParse({
|
|
24
|
+
...minimalValid,
|
|
25
|
+
triggers: [{ event: 'cron' }],
|
|
26
|
+
})
|
|
27
|
+
expect(result.success).toBe(false)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('accepts cron trigger with cron expression', () => {
|
|
31
|
+
const result = createAutomationSchema.safeParse({
|
|
32
|
+
...minimalValid,
|
|
33
|
+
triggers: [{ event: 'cron', cron: '0 * * * *' }],
|
|
34
|
+
})
|
|
35
|
+
expect(result.success).toBe(true)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('rejects duplicate trigger events', () => {
|
|
39
|
+
const result = createAutomationSchema.safeParse({
|
|
40
|
+
...minimalValid,
|
|
41
|
+
triggers: [{ event: 'create' }, { event: 'create' }],
|
|
42
|
+
})
|
|
43
|
+
expect(result.success).toBe(false)
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('accepts multiple distinct triggers', () => {
|
|
47
|
+
const result = createAutomationSchema.safeParse({
|
|
48
|
+
...minimalValid,
|
|
49
|
+
triggers: [{ event: 'create' }, { event: 'update' }],
|
|
50
|
+
})
|
|
51
|
+
expect(result.success).toBe(true)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('rejects empty actions array', () => {
|
|
55
|
+
const result = createAutomationSchema.safeParse({ ...minimalValid, actions: [] })
|
|
56
|
+
expect(result.success).toBe(false)
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('rejects unknown action type', () => {
|
|
60
|
+
const result = createAutomationSchema.safeParse({
|
|
61
|
+
...minimalValid,
|
|
62
|
+
actions: [{ type: 'unknown_type', url: 'https://example.com' }],
|
|
63
|
+
})
|
|
64
|
+
expect(result.success).toBe(false)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('rejects webhook with non-url', () => {
|
|
68
|
+
const result = createAutomationSchema.safeParse({
|
|
69
|
+
...minimalValid,
|
|
70
|
+
actions: [{ type: 'webhook', url: 'not-a-url' }],
|
|
71
|
+
})
|
|
72
|
+
expect(result.success).toBe(false)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('rejects send_mail with invalid email', () => {
|
|
76
|
+
const result = createAutomationSchema.safeParse({
|
|
77
|
+
...minimalValid,
|
|
78
|
+
actions: [{ type: 'send_mail', to: 'not-an-email', subject_template: 'hi', body_template: 'body' }],
|
|
79
|
+
})
|
|
80
|
+
expect(result.success).toBe(false)
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('accepts trigger_conditions as null', () => {
|
|
84
|
+
const result = createAutomationSchema.safeParse({
|
|
85
|
+
...minimalValid,
|
|
86
|
+
trigger_conditions: null,
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
expect(result.success).toBe(true)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('accepts trigger_conditions as WhenNode', () => {
|
|
93
|
+
const result = createAutomationSchema.safeParse({
|
|
94
|
+
...minimalValid,
|
|
95
|
+
trigger_conditions: {
|
|
96
|
+
kind: 'group',
|
|
97
|
+
op: 'AND',
|
|
98
|
+
children: [
|
|
99
|
+
{ kind: 'predicate', left: { kind: 'ref', key: 'this.status' }, op: 'eq', right: { kind: 'literal', value: 'published' } },
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
})
|
|
103
|
+
expect(result.success).toBe(true)
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
describe('updateAutomationSchema', () => {
|
|
108
|
+
it('accepts empty object', () => {
|
|
109
|
+
expect(updateAutomationSchema.safeParse({}).success).toBe(true)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('accepts name-only without requiring triggers', () => {
|
|
113
|
+
const result = updateAutomationSchema.safeParse({ name: 'renamed' })
|
|
114
|
+
expect(result.success).toBe(true)
|
|
115
|
+
})
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
describe('toggleAutomationSchema', () => {
|
|
119
|
+
it('accepts { enabled: true }', () => {
|
|
120
|
+
expect(toggleAutomationSchema.safeParse({ enabled: true }).success).toBe(true)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('accepts { enabled: false }', () => {
|
|
124
|
+
expect(toggleAutomationSchema.safeParse({ enabled: false }).success).toBe(true)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('rejects missing enabled', () => {
|
|
128
|
+
expect(toggleAutomationSchema.safeParse({}).success).toBe(false)
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('rejects non-boolean enabled', () => {
|
|
132
|
+
expect(toggleAutomationSchema.safeParse({ enabled: 'true' }).success).toBe(false)
|
|
133
|
+
})
|
|
134
|
+
})
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import type { Automation } from '@beechcms/core'
|
|
3
|
+
import { resolveAutomationContext, deriveEntryContext } from '../context-resolver'
|
|
4
|
+
import { parseTemplateKey } from '../template-grammar'
|
|
5
|
+
|
|
6
|
+
function makeAutomation(overrides: Partial<Automation> = {}): Automation {
|
|
7
|
+
return {
|
|
8
|
+
id: 'auto-1',
|
|
9
|
+
seed_slug: 'orders',
|
|
10
|
+
name: 'test',
|
|
11
|
+
enabled: true,
|
|
12
|
+
triggers: [{ event: 'cron' as const, cron: '* * * * *' }],
|
|
13
|
+
trigger_conditions: null,
|
|
14
|
+
actions: [],
|
|
15
|
+
created_at: 0,
|
|
16
|
+
updated_at: 0,
|
|
17
|
+
...overrides,
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
describe('resolveAutomationContext', () => {
|
|
22
|
+
const triggerEntry = { id: 'e1', email: 'alice@example.com', product_id: 'p1' }
|
|
23
|
+
const batchEntries = [
|
|
24
|
+
{ id: 'e1', total: 10, email: 'alice@example.com' },
|
|
25
|
+
{ id: 'e2', total: 20, email: 'bob@example.com' },
|
|
26
|
+
{ id: 'e3', total: 30, email: 'carol@example.com' },
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
it('this scope resolves to triggering entry field', async () => {
|
|
30
|
+
const ctx = await resolveAutomationContext(makeAutomation(), triggerEntry, [triggerEntry])
|
|
31
|
+
expect(ctx.lookup(parseTemplateKey('this:email')!)).toBe('alice@example.com')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('this. dot notation resolves to triggering entry field', async () => {
|
|
35
|
+
const ctx = await resolveAutomationContext(makeAutomation(), triggerEntry, [triggerEntry])
|
|
36
|
+
expect(ctx.lookup(parseTemplateKey('email')!)).toBe('alice@example.com')
|
|
37
|
+
expect(ctx.lookup(parseTemplateKey('this:product_id')!)).toBe('p1')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('batch:all:count matches batchEntries length', async () => {
|
|
41
|
+
const ctx = await resolveAutomationContext(makeAutomation(), triggerEntry, batchEntries)
|
|
42
|
+
expect(ctx.lookup(parseTemplateKey('batch:all:count')!)).toBe(3)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('unknown scope → undefined + onMissing fires', async () => {
|
|
46
|
+
const ctx = await resolveAutomationContext(makeAutomation(), triggerEntry, [triggerEntry])
|
|
47
|
+
const missing: string[] = []
|
|
48
|
+
const val = ctx.lookup(parseTemplateKey('unknownseed:lastone:email')!, (f) => missing.push(f))
|
|
49
|
+
expect(val).toBeUndefined()
|
|
50
|
+
expect(missing).toHaveLength(1)
|
|
51
|
+
expect(missing[0]).toBe('unknownseed')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('pluck truncates to 100 entries and appends truncation marker', async () => {
|
|
55
|
+
const rows = Array.from({ length: 150 }, (_, i) => ({ email: `u${i}@example.com` }))
|
|
56
|
+
const ctx = await resolveAutomationContext(makeAutomation(), triggerEntry, rows)
|
|
57
|
+
const key = parseTemplateKey('batch:all:pluck:email')!
|
|
58
|
+
const result = ctx.lookup(key) as string
|
|
59
|
+
const values = result.split(', ')
|
|
60
|
+
expect(result.endsWith(' …')).toBe(true)
|
|
61
|
+
expect(values.length).toBe(100)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('sum on non-numeric field values returns 0 and fires onMissing for NaN', async () => {
|
|
65
|
+
const ctx = await resolveAutomationContext(
|
|
66
|
+
makeAutomation(),
|
|
67
|
+
triggerEntry,
|
|
68
|
+
[{ id: 'e1', amount: 'not-a-number' }, { id: 'e2', amount: 'also-not' }],
|
|
69
|
+
)
|
|
70
|
+
const missing: string[] = []
|
|
71
|
+
const result = ctx.lookup(parseTemplateKey('batch:all:sum:amount')!, (f) => missing.push(f))
|
|
72
|
+
expect(result).toBe(0)
|
|
73
|
+
expect(missing.length).toBeGreaterThan(0)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
describe('aggregates on batch', () => {
|
|
77
|
+
const rows = [
|
|
78
|
+
{ id: 'e1', total: 10 },
|
|
79
|
+
{ id: 'e2', total: 20 },
|
|
80
|
+
{ id: 'e3', total: 30 },
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
async function makeCtx(batchRows: Record<string, unknown>[]) {
|
|
84
|
+
return resolveAutomationContext(makeAutomation(), batchRows[0] ?? null, batchRows)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
it('count', async () => {
|
|
88
|
+
const ctx = await makeCtx(rows)
|
|
89
|
+
expect(ctx.lookup(parseTemplateKey('batch:all:count')!)).toBe(3)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
it('sum', async () => {
|
|
93
|
+
const ctx = await makeCtx(rows)
|
|
94
|
+
expect(ctx.lookup(parseTemplateKey('batch:all:sum:total')!)).toBe(60)
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
it('avg', async () => {
|
|
98
|
+
const ctx = await makeCtx(rows)
|
|
99
|
+
expect(ctx.lookup(parseTemplateKey('batch:all:avg:total')!)).toBe(20)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('min', async () => {
|
|
103
|
+
const ctx = await makeCtx(rows)
|
|
104
|
+
expect(ctx.lookup(parseTemplateKey('batch:all:min:total')!)).toBe(10)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
it('max', async () => {
|
|
108
|
+
const ctx = await makeCtx(rows)
|
|
109
|
+
expect(ctx.lookup(parseTemplateKey('batch:all:max:total')!)).toBe(30)
|
|
110
|
+
})
|
|
111
|
+
})
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
describe('deriveEntryContext', () => {
|
|
115
|
+
it('this scope returns new entry, batch scope delegates to base', async () => {
|
|
116
|
+
const batchRows = [{ id: 'e1', val: 1 }, { id: 'e2', val: 2 }]
|
|
117
|
+
const base = await resolveAutomationContext(makeAutomation(), batchRows[0] ?? null, batchRows)
|
|
118
|
+
const derived = deriveEntryContext(base, { id: 'e2', val: 2, email: 'derived@example.com' })
|
|
119
|
+
expect(derived.lookup(parseTemplateKey('this:email')!)).toBe('derived@example.com')
|
|
120
|
+
expect(derived.lookup(parseTemplateKey('batch:all:count')!)).toBe(2)
|
|
121
|
+
})
|
|
122
|
+
})
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
2
|
+
import type { Automation, IAutomationRepository, ContentRepository, Seed, IIdGenerator } from '@beechcms/core'
|
|
3
|
+
import { runCronAutomations } from '../cron-runner'
|
|
4
|
+
import type { CronRunnerDeps } from '../cron-runner'
|
|
5
|
+
|
|
6
|
+
vi.mock('../action-executors', () => ({
|
|
7
|
+
executeAction: vi.fn().mockResolvedValue(undefined),
|
|
8
|
+
}))
|
|
9
|
+
|
|
10
|
+
import { executeAction } from '../action-executors'
|
|
11
|
+
const executeActionMock = executeAction as ReturnType<typeof vi.fn>
|
|
12
|
+
|
|
13
|
+
// 2026-05-14T09:00:00Z → minute=0, hour=9, dow=4 (Thursday)
|
|
14
|
+
const TICK = new Date('2026-05-14T09:00:00Z').getTime()
|
|
15
|
+
|
|
16
|
+
const SEED: Seed = {
|
|
17
|
+
slug: 'posts',
|
|
18
|
+
label: 'Post',
|
|
19
|
+
displayNameAlias: 'title',
|
|
20
|
+
branches: [
|
|
21
|
+
{ alias: 'title', type: 'text', label: 'Title' },
|
|
22
|
+
{ alias: 'count', type: 'number', label: 'Count' },
|
|
23
|
+
{ alias: 'published', type: 'boolean', label: 'Published' },
|
|
24
|
+
{ alias: 'publish_date', type: 'date', label: 'Publish Date' },
|
|
25
|
+
{ alias: 'tags_list', type: 'tags', label: 'Tags' },
|
|
26
|
+
{ alias: 'meta_json', type: 'json', label: 'Meta JSON' },
|
|
27
|
+
{ alias: 'body_rich', type: 'richtext', label: 'Body' },
|
|
28
|
+
],
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const STUB_ID_GENERATOR: IIdGenerator = {
|
|
32
|
+
uuid: () => 'test-uuid',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function makeAutomation(overrides: Partial<Automation> = {}): Automation {
|
|
36
|
+
return {
|
|
37
|
+
id: 'auto_01',
|
|
38
|
+
seed_slug: 'posts',
|
|
39
|
+
name: 'every-minute',
|
|
40
|
+
enabled: true,
|
|
41
|
+
triggers: [{ event: 'cron' as const, cron: '* * * * *' }],
|
|
42
|
+
trigger_conditions: null,
|
|
43
|
+
actions: [{ type: 'webhook', url: 'https://example.com/hook' }],
|
|
44
|
+
created_at: 0,
|
|
45
|
+
updated_at: 0,
|
|
46
|
+
...overrides,
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function makeDeps(overrides: Partial<CronRunnerDeps> = {}): CronRunnerDeps & {
|
|
51
|
+
listSpy: ReturnType<typeof vi.fn>
|
|
52
|
+
findActiveSpy: ReturnType<typeof vi.fn>
|
|
53
|
+
} {
|
|
54
|
+
const listSpy = vi.fn().mockResolvedValue({ items: [{ id: 'e1', title: 'Hello' }], total: 1 })
|
|
55
|
+
const findActiveSpy = vi.fn().mockResolvedValue([makeAutomation()])
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
automationRepository: {
|
|
59
|
+
findActive: findActiveSpy,
|
|
60
|
+
list: vi.fn(), findById: vi.fn(), create: vi.fn(),
|
|
61
|
+
update: vi.fn(), toggle: vi.fn(), delete: vi.fn(),
|
|
62
|
+
} as unknown as IAutomationRepository,
|
|
63
|
+
contentRepository: { findMany: listSpy } as unknown as ContentRepository,
|
|
64
|
+
getSeed: (slug: string) => slug === 'posts' ? SEED : null,
|
|
65
|
+
env: {},
|
|
66
|
+
idGenerator: STUB_ID_GENERATOR,
|
|
67
|
+
listSpy,
|
|
68
|
+
findActiveSpy,
|
|
69
|
+
...overrides,
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
describe('runCronAutomations', () => {
|
|
74
|
+
beforeEach(() => {
|
|
75
|
+
executeActionMock.mockReset()
|
|
76
|
+
executeActionMock.mockResolvedValue(undefined)
|
|
77
|
+
})
|
|
78
|
+
|
|
79
|
+
it('calls findActive with ("*", "cron")', async () => {
|
|
80
|
+
const deps = makeDeps()
|
|
81
|
+
await runCronAutomations(deps, TICK)
|
|
82
|
+
expect(deps.findActiveSpy).toHaveBeenCalledWith('*', 'cron')
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
it('batch actions (webhook, send_mail) run once per automation with batch context', async () => {
|
|
86
|
+
const entries = [{ id: 'e1', title: 'A' }, { id: 'e2', title: 'B' }]
|
|
87
|
+
const deps = makeDeps()
|
|
88
|
+
deps.listSpy.mockResolvedValue({ items: entries, total: 2 })
|
|
89
|
+
|
|
90
|
+
await runCronAutomations(deps, TICK)
|
|
91
|
+
|
|
92
|
+
expect(executeActionMock).toHaveBeenCalledTimes(1)
|
|
93
|
+
const [, ctx] = executeActionMock.mock.calls[0]
|
|
94
|
+
// entry is the first entry (for backwards compat); batch count lives in context
|
|
95
|
+
expect(ctx.entry).toMatchObject({ id: 'e1', title: 'A' })
|
|
96
|
+
expect(ctx.context).toBeDefined()
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('per-entry actions (edit_field, create_entry) run once per matching entry', async () => {
|
|
100
|
+
const entries = [{ id: 'e1' }, { id: 'e2' }]
|
|
101
|
+
const deps = makeDeps()
|
|
102
|
+
deps.findActiveSpy.mockResolvedValue([makeAutomation({ actions: [{ type: 'edit_field', field: 'title', value: 'updated' }] })])
|
|
103
|
+
deps.listSpy.mockResolvedValue({ items: entries, total: 2 })
|
|
104
|
+
|
|
105
|
+
await runCronAutomations(deps, TICK)
|
|
106
|
+
|
|
107
|
+
expect(executeActionMock).toHaveBeenCalledTimes(2)
|
|
108
|
+
expect(executeActionMock.mock.calls[0][1].entry).toMatchObject({ id: 'e1' })
|
|
109
|
+
expect(executeActionMock.mock.calls[1][1].entry).toMatchObject({ id: 'e2' })
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('skips non-matching cron expression, runs matching one', async () => {
|
|
113
|
+
const matchingAuto = makeAutomation({ id: 'auto_match', triggers: [{ event: 'cron', cron: '* * * * *' }] })
|
|
114
|
+
const nonMatchingAuto = makeAutomation({ id: 'auto_skip', triggers: [{ event: 'cron', cron: '30 9 * * *' }] })
|
|
115
|
+
const entries = [{ id: 'e1' }, { id: 'e2' }]
|
|
116
|
+
|
|
117
|
+
const deps = makeDeps()
|
|
118
|
+
deps.findActiveSpy.mockResolvedValue([matchingAuto, nonMatchingAuto])
|
|
119
|
+
deps.listSpy.mockResolvedValue({ items: entries, total: 2 })
|
|
120
|
+
|
|
121
|
+
await runCronAutomations(deps, TICK)
|
|
122
|
+
|
|
123
|
+
// webhook = batch, runs once for the matching automation only
|
|
124
|
+
expect(executeActionMock).toHaveBeenCalledTimes(1)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
it('passes trigger_conditions as translated filters to repository.findMany', async () => {
|
|
128
|
+
const auto = makeAutomation({
|
|
129
|
+
trigger_conditions: {
|
|
130
|
+
kind: 'group',
|
|
131
|
+
op: 'AND',
|
|
132
|
+
children: [
|
|
133
|
+
{ kind: 'predicate', left: { kind: 'ref', key: 'this.title' }, op: 'eq', right: { kind: 'literal', value: 'Hello' } },
|
|
134
|
+
],
|
|
135
|
+
},
|
|
136
|
+
})
|
|
137
|
+
const deps = makeDeps()
|
|
138
|
+
deps.findActiveSpy.mockResolvedValue([auto])
|
|
139
|
+
|
|
140
|
+
await runCronAutomations(deps, TICK)
|
|
141
|
+
|
|
142
|
+
const call = deps.listSpy.mock.calls[0]
|
|
143
|
+
const options = call[1]
|
|
144
|
+
expect(options.filters).toEqual([
|
|
145
|
+
{ column: 'title', type: 'text', conditions: [{ op: 'eq', value: 'Hello' }] },
|
|
146
|
+
])
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
it('maps all branch types, system columns, unknown columns, and special operators correctly', async () => {
|
|
150
|
+
const auto = makeAutomation({
|
|
151
|
+
trigger_conditions: {
|
|
152
|
+
kind: 'group',
|
|
153
|
+
op: 'AND',
|
|
154
|
+
children: [
|
|
155
|
+
{ kind: 'predicate', left: { kind: 'ref', key: 'this.count' }, op: 'gt', right: { kind: 'literal', value: 5 } },
|
|
156
|
+
{ kind: 'predicate', left: { kind: 'ref', key: 'this.published' }, op: 'eq', right: { kind: 'literal', value: true } },
|
|
157
|
+
{ kind: 'predicate', left: { kind: 'ref', key: 'this.publish_date' }, op: 'isempty' },
|
|
158
|
+
{ kind: 'predicate', left: { kind: 'ref', key: 'this.tags_list' }, op: 'isnotempty' },
|
|
159
|
+
{ kind: 'predicate', left: { kind: 'ref', key: 'this.meta_json' }, op: 'eq', right: { kind: 'literal', value: '{}' } },
|
|
160
|
+
{ kind: 'predicate', left: { kind: 'ref', key: 'this.body_rich' }, op: 'contains', right: { kind: 'literal', value: 'hello' } },
|
|
161
|
+
{ kind: 'predicate', left: { kind: 'ref', key: 'this.status' }, op: 'eq', right: { kind: 'literal', value: 'draft' } },
|
|
162
|
+
{ kind: 'predicate', left: { kind: 'ref', key: 'this.unknown_custom' }, op: 'eq', right: { kind: 'literal', value: 'test' } },
|
|
163
|
+
],
|
|
164
|
+
},
|
|
165
|
+
})
|
|
166
|
+
const deps = makeDeps()
|
|
167
|
+
deps.findActiveSpy.mockResolvedValue([auto])
|
|
168
|
+
|
|
169
|
+
await runCronAutomations(deps, TICK)
|
|
170
|
+
|
|
171
|
+
const call = deps.listSpy.mock.calls[0]
|
|
172
|
+
expect(call[1].filters).toEqual([
|
|
173
|
+
{ column: 'count', type: 'number', conditions: [{ op: 'gt', value: 5 }] },
|
|
174
|
+
{ column: 'published', type: 'boolean', conditions: [{ op: 'eq', value: true }] },
|
|
175
|
+
{ column: 'publish_date', type: 'date', conditions: [{ op: 'is_empty', value: null }] },
|
|
176
|
+
{ column: 'tags_list', type: 'tags', conditions: [{ op: 'is_not_empty', value: null }] },
|
|
177
|
+
{ column: 'meta_json', type: 'json', conditions: [{ op: 'eq', value: '{}' }] },
|
|
178
|
+
{ column: 'body_rich', type: 'text', conditions: [{ op: 'contains', value: 'hello' }] },
|
|
179
|
+
{ column: 'status', type: 'system', conditions: [{ op: 'eq', value: 'draft' }] },
|
|
180
|
+
{ column: 'unknown_custom', type: 'text', conditions: [{ op: 'eq', value: 'test' }] },
|
|
181
|
+
])
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
it('logs warning and skips when getSeed returns null', async () => {
|
|
185
|
+
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {})
|
|
186
|
+
const auto = makeAutomation({ seed_slug: 'unknown' })
|
|
187
|
+
const deps = makeDeps()
|
|
188
|
+
deps.findActiveSpy.mockResolvedValue([auto])
|
|
189
|
+
|
|
190
|
+
await runCronAutomations(deps, TICK)
|
|
191
|
+
|
|
192
|
+
expect(executeActionMock).not.toHaveBeenCalled()
|
|
193
|
+
expect(warnSpy).toHaveBeenCalledWith('[cron] unknown seed', expect.anything())
|
|
194
|
+
warnSpy.mockRestore()
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
it('continues processing remaining per-entry actions when one entry throws', async () => {
|
|
198
|
+
const entries = [{ id: 'e1' }, { id: 'e2' }, { id: 'e3' }]
|
|
199
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
200
|
+
const deps = makeDeps()
|
|
201
|
+
deps.findActiveSpy.mockResolvedValue([makeAutomation({ actions: [{ type: 'edit_field', field: 'title', value: 'x' }] })])
|
|
202
|
+
deps.listSpy.mockResolvedValue({ items: entries, total: 3 })
|
|
203
|
+
executeActionMock
|
|
204
|
+
.mockResolvedValueOnce(undefined)
|
|
205
|
+
.mockRejectedValueOnce(new Error('boom'))
|
|
206
|
+
.mockResolvedValueOnce(undefined)
|
|
207
|
+
|
|
208
|
+
await runCronAutomations(deps, TICK)
|
|
209
|
+
|
|
210
|
+
expect(executeActionMock).toHaveBeenCalledTimes(3)
|
|
211
|
+
expect(errorSpy).toHaveBeenCalledWith('[cron] entry action failed', expect.anything())
|
|
212
|
+
errorSpy.mockRestore()
|
|
213
|
+
})
|
|
214
|
+
|
|
215
|
+
it('logs and continues to next automation when repository.findMany throws', async () => {
|
|
216
|
+
const auto1 = makeAutomation({ id: 'auto_01' })
|
|
217
|
+
const auto2 = makeAutomation({ id: 'auto_02' })
|
|
218
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
219
|
+
const deps = makeDeps()
|
|
220
|
+
deps.findActiveSpy.mockResolvedValue([auto1, auto2])
|
|
221
|
+
deps.listSpy
|
|
222
|
+
.mockRejectedValueOnce(new Error('db error'))
|
|
223
|
+
.mockResolvedValueOnce({ items: [{ id: 'e1' }], total: 1 })
|
|
224
|
+
|
|
225
|
+
await runCronAutomations(deps, TICK)
|
|
226
|
+
|
|
227
|
+
expect(errorSpy).toHaveBeenCalledWith('[cron] fetch entries failed', expect.anything())
|
|
228
|
+
// auto2 still processed (webhook = batch, 1 call)
|
|
229
|
+
expect(executeActionMock).toHaveBeenCalledTimes(1)
|
|
230
|
+
errorSpy.mockRestore()
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
it('logs error and returns gracefully when findActive throws', async () => {
|
|
234
|
+
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
|
|
235
|
+
const deps = makeDeps()
|
|
236
|
+
deps.findActiveSpy.mockRejectedValueOnce(new Error('no such table'))
|
|
237
|
+
|
|
238
|
+
await expect(runCronAutomations(deps, TICK)).resolves.toBeUndefined()
|
|
239
|
+
expect(errorSpy).toHaveBeenCalledWith(
|
|
240
|
+
expect.stringContaining('[cron] Failed to fetch automations'),
|
|
241
|
+
expect.anything(),
|
|
242
|
+
)
|
|
243
|
+
expect(executeActionMock).not.toHaveBeenCalled()
|
|
244
|
+
errorSpy.mockRestore()
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
it('resolves quietly with zero calls when no active automations exist', async () => {
|
|
248
|
+
const deps = makeDeps()
|
|
249
|
+
deps.findActiveSpy.mockResolvedValue([])
|
|
250
|
+
|
|
251
|
+
await expect(runCronAutomations(deps, TICK)).resolves.toBeUndefined()
|
|
252
|
+
expect(executeActionMock).not.toHaveBeenCalled()
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
it('skips automation silently when entries list is empty', async () => {
|
|
256
|
+
const deps = makeDeps()
|
|
257
|
+
deps.listSpy.mockResolvedValue({ items: [], total: 0 })
|
|
258
|
+
|
|
259
|
+
await runCronAutomations(deps, TICK)
|
|
260
|
+
|
|
261
|
+
expect(executeActionMock).not.toHaveBeenCalled()
|
|
262
|
+
})
|
|
263
|
+
})
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { cronMatches } from '../cron-runner.utils'
|
|
3
|
+
|
|
4
|
+
const ts = (iso: string) => new Date(iso).getTime()
|
|
5
|
+
|
|
6
|
+
describe('cronMatches', () => {
|
|
7
|
+
it('matches any timestamp with * * * * *', () => {
|
|
8
|
+
expect(cronMatches('* * * * *', ts('2026-05-14T09:37:00Z'))).toBe(true)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('returns false for null', () => {
|
|
12
|
+
expect(cronMatches(null, ts('2026-05-14T09:00:00Z'))).toBe(false)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('returns false for empty string', () => {
|
|
16
|
+
expect(cronMatches('', ts('2026-05-14T09:00:00Z'))).toBe(false)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
it('returns false for malformed (not 5 fields)', () => {
|
|
20
|
+
expect(cronMatches('* * * *', ts('2026-05-14T09:00:00Z'))).toBe(false)
|
|
21
|
+
expect(cronMatches('* * * * * *', ts('2026-05-14T09:00:00Z'))).toBe(false)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
describe('exact match', () => {
|
|
25
|
+
it('matches 0 9 * * * at 09:00', () => {
|
|
26
|
+
expect(cronMatches('0 9 * * *', ts('2026-05-14T09:00:00Z'))).toBe(true)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('does not match 0 9 * * * at 09:01', () => {
|
|
30
|
+
expect(cronMatches('0 9 * * *', ts('2026-05-14T09:01:00Z'))).toBe(false)
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
describe('day-of-week', () => {
|
|
35
|
+
// 2026-05-11 is a Monday (day 1)
|
|
36
|
+
it('matches 0 9 * * 1 on Monday', () => {
|
|
37
|
+
expect(cronMatches('0 9 * * 1', ts('2026-05-11T09:00:00Z'))).toBe(true)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
it('does not match 0 9 * * 1 on Tuesday', () => {
|
|
41
|
+
expect(cronMatches('0 9 * * 1', ts('2026-05-12T09:00:00Z'))).toBe(false)
|
|
42
|
+
})
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
describe('list', () => {
|
|
46
|
+
it('matches 0 9,17 * * * at 09:00', () => {
|
|
47
|
+
expect(cronMatches('0 9,17 * * *', ts('2026-05-14T09:00:00Z'))).toBe(true)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('matches 0 9,17 * * * at 17:00', () => {
|
|
51
|
+
expect(cronMatches('0 9,17 * * *', ts('2026-05-14T17:00:00Z'))).toBe(true)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('does not match 0 9,17 * * * at 10:00', () => {
|
|
55
|
+
expect(cronMatches('0 9,17 * * *', ts('2026-05-14T10:00:00Z'))).toBe(false)
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
describe('range', () => {
|
|
60
|
+
it('matches 0 9-11 * * * at 09:00', () => {
|
|
61
|
+
expect(cronMatches('0 9-11 * * *', ts('2026-05-14T09:00:00Z'))).toBe(true)
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('matches 0 9-11 * * * at 10:00', () => {
|
|
65
|
+
expect(cronMatches('0 9-11 * * *', ts('2026-05-14T10:00:00Z'))).toBe(true)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('matches 0 9-11 * * * at 11:00', () => {
|
|
69
|
+
expect(cronMatches('0 9-11 * * *', ts('2026-05-14T11:00:00Z'))).toBe(true)
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('does not match 0 9-11 * * * at 12:00', () => {
|
|
73
|
+
expect(cronMatches('0 9-11 * * *', ts('2026-05-14T12:00:00Z'))).toBe(false)
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
describe('step', () => {
|
|
78
|
+
it('matches */15 * * * * at :00', () => {
|
|
79
|
+
expect(cronMatches('*/15 * * * *', ts('2026-05-14T09:00:00Z'))).toBe(true)
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('matches */15 * * * * at :15', () => {
|
|
83
|
+
expect(cronMatches('*/15 * * * *', ts('2026-05-14T09:15:00Z'))).toBe(true)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('matches */15 * * * * at :30', () => {
|
|
87
|
+
expect(cronMatches('*/15 * * * *', ts('2026-05-14T09:30:00Z'))).toBe(true)
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
it('matches */15 * * * * at :45', () => {
|
|
91
|
+
expect(cronMatches('*/15 * * * *', ts('2026-05-14T09:45:00Z'))).toBe(true)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('does not match */15 * * * * at :07', () => {
|
|
95
|
+
expect(cronMatches('*/15 * * * *', ts('2026-05-14T09:07:00Z'))).toBe(false)
|
|
96
|
+
})
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
describe('range + step', () => {
|
|
100
|
+
it('matches 5-30/5 * * * * at :05', () => {
|
|
101
|
+
expect(cronMatches('5-30/5 * * * *', ts('2026-05-14T09:05:00Z'))).toBe(true)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('matches 5-30/5 * * * * at :10', () => {
|
|
105
|
+
expect(cronMatches('5-30/5 * * * *', ts('2026-05-14T09:10:00Z'))).toBe(true)
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('matches 5-30/5 * * * * at :30', () => {
|
|
109
|
+
expect(cronMatches('5-30/5 * * * *', ts('2026-05-14T09:30:00Z'))).toBe(true)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('does not match 5-30/5 * * * * at :00', () => {
|
|
113
|
+
expect(cronMatches('5-30/5 * * * *', ts('2026-05-14T09:00:00Z'))).toBe(false)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('does not match 5-30/5 * * * * at :35', () => {
|
|
117
|
+
expect(cronMatches('5-30/5 * * * *', ts('2026-05-14T09:35:00Z'))).toBe(false)
|
|
118
|
+
})
|
|
119
|
+
})
|
|
120
|
+
|
|
121
|
+
describe('edge cases and malformed field expressions', () => {
|
|
122
|
+
it('returns false for non-finite or zero step', () => {
|
|
123
|
+
expect(cronMatches('*/0 * * * *', ts('2026-05-14T09:00:00Z'))).toBe(false)
|
|
124
|
+
expect(cronMatches('*/abc * * * *', ts('2026-05-14T09:00:00Z'))).toBe(false)
|
|
125
|
+
expect(cronMatches('*/-5 * * * *', ts('2026-05-14T09:00:00Z'))).toBe(false)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
it('returns false when step is applied to a single value instead of range or wildcard', () => {
|
|
129
|
+
expect(cronMatches('5/2 * * * *', ts('2026-05-14T09:05:00Z'))).toBe(false)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('returns false for malformed range bounds', () => {
|
|
133
|
+
expect(cronMatches('abc-def * * * *', ts('2026-05-14T09:00:00Z'))).toBe(false)
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it('returns false for invalid single numeric field', () => {
|
|
137
|
+
expect(cronMatches('abc * * * *', ts('2026-05-14T09:00:00Z'))).toBe(false)
|
|
138
|
+
})
|
|
139
|
+
})
|
|
140
|
+
})
|