1 import { createRuleTester } from "../../../test-utils"
2 import { rule } from "../rule"
3
4 const ruleTester = createRuleTester()
5
6 ruleTester.run("step-id-kebab-case", rule, {
7 valid: [
8 // Variable with trailing `Step` — stripped before comparison.
9 {
10 code: `
11 import { createStep } from "@medusajs/framework/workflows-sdk"
12 export const fetchCustomersStep = createStep("fetch-customers", () => {})
13 `,
14 },
15 // Filename with trailing `-step` — stripped before comparison.
16 {
17 code: `
18 import { createStep } from "@medusajs/framework/workflows-sdk"
19 createStep("fetch-customers", () => {})
20 `,
21 filename: "src/workflows/fetch-customers-step.ts",
22 },
23 // Variable without `Step` suffix still matches when the id is identical.
24 {
25 code: `
26 import { createStep } from "@medusajs/framework/workflows-sdk"
27 export const fetchCustomers = createStep("fetch-customers", () => {})
28 `,
29 },
30 // Kebab id containing digits — matches variable name (Step suffix stripped).
31 {
32 code: `
33 import { createStep } from "@medusajs/framework/workflows-sdk"
34 export const fetchCustomersV2Step = createStep("fetch-customers-v2", () => {})
35 `,
36 },
37 // Aliased createStep import.
38 {
39 code: `
40 import { createStep as cs } from "@medusajs/framework/workflows-sdk"
41 export const fetchCustomersStep = cs("fetch-customers", () => {})
42 `,
43 },
44 // Non-string-literal id — outside this rule's scope.
45 {
46 code: `
47 import { createStep } from "@medusajs/framework/workflows-sdk"
48 const id = "anything"
49 export const fetchCustomersStep = createStep(id, () => {})
50 `,
51 },
52 // Not the workflows-sdk import — should not flag.
53 {
54 code: `
55 import { createStep } from "some-other-lib"
56 export const fetchCustomers = createStep("BadID", () => {})
57 `,
58 },
59 // Kebab id, no enclosing variable, filename is index.ts — skip filename check.
60 {
61 code: `
62 import { createStep } from "@medusajs/framework/workflows-sdk"
63 createStep("anything-goes", () => {})
64 `,
65 filename: "src/workflows/foo/index.ts",
66 },
67 // Bare `step` variable — suffix not stripped (would leave empty); compare full.
68 {
69 code: `
70 import { createStep } from "@medusajs/framework/workflows-sdk"
71 export const step = createStep("step", () => {})
72 `,
73 },
74 ],
75 invalid: [
76 // camelCase id — autofix to kebab from variable (Step suffix stripped).
77 {
78 code: `
79 import { createStep } from "@medusajs/framework/workflows-sdk"
80 export const fetchCustomersStep = createStep("fetchCustomers", () => {})
81 `,
82 errors: [{ messageId: "notKebabCase" }],
83 output: `
84 import { createStep } from "@medusajs/framework/workflows-sdk"
85 export const fetchCustomersStep = createStep("fetch-customers", () => {})
86 `,
87 },
88 // snake_case id — autofix to stripped kebab.
89 {
90 code: `
91 import { createStep } from "@medusajs/framework/workflows-sdk"
92 export const fetchCustomersStep = createStep("fetch_customers", () => {})
93 `,
94 errors: [{ messageId: "notKebabCase" }],
95 output: `
96 import { createStep } from "@medusajs/framework/workflows-sdk"
97 export const fetchCustomersStep = createStep("fetch-customers", () => {})
98 `,
99 },
100 // PascalCase id, no variable binding — autofix from filename (Step suffix stripped).
101 {
102 code: `
103 import { createStep } from "@medusajs/framework/workflows-sdk"
104 createStep("FetchCustomers", () => {})
105 `,
106 filename: "src/workflows/fetch-customers-step.ts",
107 errors: [{ messageId: "notKebabCase" }],
108 output: `
109 import { createStep } from "@medusajs/framework/workflows-sdk"
110 createStep("fetch-customers", () => {})
111 `,
112 },
113 // Kebab but mismatches variable name — autofix to stripped variable kebab.
114 {
115 code: `
116 import { createStep } from "@medusajs/framework/workflows-sdk"
117 export const createCustomerStep = createStep("update-customer", () => {})
118 `,
119 errors: [{ messageId: "idMismatch" }],
120 output: `
121 import { createStep } from "@medusajs/framework/workflows-sdk"
122 export const createCustomerStep = createStep("create-customer", () => {})
123 `,
124 },
125 // Id includes the `-step` suffix that the variable strips — flagged.
126 {
127 code: `
128 import { createStep } from "@medusajs/framework/workflows-sdk"
129 export const fetchCustomersStep = createStep("fetch-customers-step", () => {})
130 `,
131 errors: [{ messageId: "idMismatch" }],
132 output: `
133 import { createStep } from "@medusajs/framework/workflows-sdk"
134 export const fetchCustomersStep = createStep("fetch-customers", () => {})
135 `,
136 },
137 // Kebab but mismatches filename (no variable) — autofix to stripped filename kebab.
138 {
139 code: `
140 import { createStep } from "@medusajs/framework/workflows-sdk"
141 createStep("something-else", () => {})
142 `,
143 filename: "src/workflows/fetch-customers-step.ts",
144 errors: [{ messageId: "idMismatch" }],
145 output: `
146 import { createStep } from "@medusajs/framework/workflows-sdk"
147 createStep("fetch-customers", () => {})
148 `,
149 },
150 // Aliased createStep import is still tracked.
151 {
152 code: `
153 import { createStep as cs } from "@medusajs/framework/workflows-sdk"
154 export const fetchCustomersStep = cs("fetchCustomers", () => {})
155 `,
156 errors: [{ messageId: "notKebabCase" }],
157 output: `
158 import { createStep as cs } from "@medusajs/framework/workflows-sdk"
159 export const fetchCustomersStep = cs("fetch-customers", () => {})
160 `,
161 },
162 // Variable name takes precedence over filename when both differ.
163 {
164 code: `
165 import { createStep } from "@medusajs/framework/workflows-sdk"
166 export const fetchCustomersStep = createStep("other-id", () => {})
167 `,
168 filename: "src/workflows/different-name-step.ts",
169 errors: [{ messageId: "idMismatch" }],
170 output: `
171 import { createStep } from "@medusajs/framework/workflows-sdk"
172 export const fetchCustomersStep = createStep("fetch-customers", () => {})
173 `,
174 },
175 ],
176 })