|
1
|
import { createRuleTester } from "../../../test-utils" |
|
2
|
import { rule } from "../rule" |
|
3
|
|
|
4
|
const ruleTester = createRuleTester() |
|
5
|
|
|
6
|
const JOB = "src/jobs/sync-products.ts" |
|
7
|
|
|
8
|
ruleTester.run("scheduled-job-schedule-valid-cron", rule, { |
|
9
|
valid: [ |
|
10
|
// Standard 5-field cron. |
|
11
|
{ |
|
12
|
code: `export const config = { name: "daily", schedule: "0 0 * * *" }`, |
|
13
|
filename: JOB, |
|
14
|
}, |
|
15
|
// Every minute. |
|
16
|
{ |
|
17
|
code: `export const config = { name: "every-minute", schedule: "* * * * *" }`, |
|
18
|
filename: JOB, |
|
19
|
}, |
|
20
|
// Step and range syntax. |
|
21
|
{ |
|
22
|
code: `export const config = { name: "weekdays", schedule: "*/15 9-17 * * 1-5" }`, |
|
23
|
filename: JOB, |
|
24
|
}, |
|
25
|
// Named day-of-week. |
|
26
|
{ |
|
27
|
code: `export const config = { name: "monday", schedule: "0 0 * * MON" }`, |
|
28
|
filename: JOB, |
|
29
|
}, |
|
30
|
// Predefined alias. |
|
31
|
{ |
|
32
|
code: `export const config = { name: "daily-alias", schedule: "@daily" }`, |
|
33
|
filename: JOB, |
|
34
|
}, |
|
35
|
// Interval-based schedule — not a cron string, so nothing to validate. |
|
36
|
{ |
|
37
|
code: `export const config = { name: "interval", schedule: { interval: 60000 } }`, |
|
38
|
filename: JOB, |
|
39
|
}, |
|
40
|
// Schedule resolved through a const string identifier. |
|
41
|
{ |
|
42
|
code: `const SCHEDULE = "0 0 * * *" |
|
43
|
export const config = { name: "daily", schedule: SCHEDULE }`, |
|
44
|
filename: JOB, |
|
45
|
}, |
|
46
|
// Schedule value can't be resolved statically — skip (no false positive). |
|
47
|
{ |
|
48
|
code: `export const config = { name: "daily", schedule: buildSchedule() }`, |
|
49
|
filename: JOB, |
|
50
|
}, |
|
51
|
// No schedule property — presence is enforced by scheduled-job-config-required. |
|
52
|
{ |
|
53
|
code: `export const config = { name: "daily" }`, |
|
54
|
filename: JOB, |
|
55
|
}, |
|
56
|
// No resolvable config object — nothing to validate. |
|
57
|
{ |
|
58
|
code: `export { config } from "./shared-config"`, |
|
59
|
filename: JOB, |
|
60
|
}, |
|
61
|
// Config resolved through a separate declaration + specifier export. |
|
62
|
{ |
|
63
|
code: `const config = { name: "daily", schedule: "0 0 * * *" } |
|
64
|
export { config }`, |
|
65
|
filename: JOB, |
|
66
|
}, |
|
67
|
], |
|
68
|
invalid: [ |
|
69
|
// Gibberish. |
|
70
|
{ |
|
71
|
code: `export const config = { name: "daily", schedule: "not-a-cron" }`, |
|
72
|
filename: JOB, |
|
73
|
errors: [{ messageId: "invalidCron" }], |
|
74
|
}, |
|
75
|
// Out-of-range values. |
|
76
|
{ |
|
77
|
code: `export const config = { name: "daily", schedule: "99 99 99 99 99" }`, |
|
78
|
filename: JOB, |
|
79
|
errors: [{ messageId: "invalidCron" }], |
|
80
|
}, |
|
81
|
// Single out-of-range field (minutes max 59). |
|
82
|
{ |
|
83
|
code: `export const config = { name: "daily", schedule: "60 * * * *" }`, |
|
84
|
filename: JOB, |
|
85
|
errors: [{ messageId: "invalidCron" }], |
|
86
|
}, |
|
87
|
// Too few fields. |
|
88
|
{ |
|
89
|
code: `export const config = { name: "daily", schedule: "0 0 * *" }`, |
|
90
|
filename: JOB, |
|
91
|
errors: [{ messageId: "invalidCron" }], |
|
92
|
}, |
|
93
|
// Invalid cron resolved through a const string identifier. |
|
94
|
{ |
|
95
|
code: `const SCHEDULE = "every day" |
|
96
|
export const config = { name: "daily", schedule: SCHEDULE }`, |
|
97
|
filename: JOB, |
|
98
|
errors: [{ messageId: "invalidCron" }], |
|
99
|
}, |
|
100
|
// Invalid cron in a config exported via specifier. |
|
101
|
{ |
|
102
|
code: `const config = { name: "daily", schedule: "bad" } |
|
103
|
export { config }`, |
|
104
|
filename: JOB, |
|
105
|
errors: [{ messageId: "invalidCron" }], |
|
106
|
}, |
|
107
|
], |
|
108
|
}) |