|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | + |
| 3 | +import { hasPlanSkippedSteps } from "../../packages/gittensory-engine/src/plan-skipped"; |
| 4 | +import type { PlanStep } from "../../packages/gittensory-engine/src/plan-export"; |
| 5 | + |
| 6 | +function step(over: Partial<PlanStep> & { id: string; title: string }): PlanStep { |
| 7 | + return { |
| 8 | + actionClass: undefined, |
| 9 | + dependsOn: [], |
| 10 | + status: "pending", |
| 11 | + attempts: 0, |
| 12 | + maxAttempts: 3, |
| 13 | + lastError: null, |
| 14 | + ...over, |
| 15 | + }; |
| 16 | +} |
| 17 | + |
| 18 | +describe("hasPlanSkippedSteps", () => { |
| 19 | + it("returns false for an empty plan", () => { |
| 20 | + expect(hasPlanSkippedSteps({ steps: [] })).toBe(false); |
| 21 | + }); |
| 22 | + |
| 23 | + it("returns false when no step was skipped", () => { |
| 24 | + expect( |
| 25 | + hasPlanSkippedSteps({ |
| 26 | + steps: [ |
| 27 | + step({ id: "a", title: "Build", status: "completed" }), |
| 28 | + step({ id: "b", title: "Test", status: "pending" }), |
| 29 | + ], |
| 30 | + }), |
| 31 | + ).toBe(false); |
| 32 | + }); |
| 33 | + |
| 34 | + it("returns true when at least one step was skipped", () => { |
| 35 | + expect( |
| 36 | + hasPlanSkippedSteps({ |
| 37 | + steps: [ |
| 38 | + step({ id: "a", title: "Build", status: "completed" }), |
| 39 | + step({ id: "b", title: "Deploy", status: "skipped" }), |
| 40 | + ], |
| 41 | + }), |
| 42 | + ).toBe(true); |
| 43 | + }); |
| 44 | + |
| 45 | + it("is exported from the package barrel", async () => { |
| 46 | + const barrel = await import("../../packages/gittensory-engine/src/index"); |
| 47 | + expect(typeof barrel.hasPlanSkippedSteps).toBe("function"); |
| 48 | + expect( |
| 49 | + barrel.hasPlanSkippedSteps({ |
| 50 | + steps: [step({ id: "a", title: "A", status: "skipped" })], |
| 51 | + }), |
| 52 | + ).toBe(true); |
| 53 | + }); |
| 54 | +}); |
0 commit comments