import { describe, expect, it } from "vitest"; import { isAuthorizeGated, isMigrateDisabled, isRepoSelectGated } from "./stepGating"; describe("stepGating", () => { const dummyAccount = { login: "octocat" }; describe("isAuthorizeGated", () => { it("is gated when there is no GitHub account", () => { expect(isAuthorizeGated({ account: null })).toBe(true); expect(isAuthorizeGated({ account: undefined })).toBe(true); }); it("is not gated when a GitHub account is present", () => { expect(isAuthorizeGated({ account: dummyAccount })).toBe(false); }); it("is gated when the flow is disabled even with an account", () => { expect(isAuthorizeGated({ account: dummyAccount, disabled: true })).toBe(true); }); }); describe("isRepoSelectGated", () => { it("is gated when there is no account", () => { expect(isRepoSelectGated({ account: null, authorized: false })).toBe(true); expect(isRepoSelectGated({ account: null, authorized: true })).toBe(true); }); it("is gated when there is an account but not authorized", () => { expect(isRepoSelectGated({ account: dummyAccount, authorized: false })).toBe(true); }); it("is not gated when account is present and authorized", () => { expect(isRepoSelectGated({ account: dummyAccount, authorized: true })).toBe(false); }); it("is gated when disabled is true", () => { expect( isRepoSelectGated({ account: dummyAccount, authorized: true, disabled: true }) ).toBe(true); }); }); describe("isMigrateDisabled", () => { it("is disabled without account or without authorization", () => { expect( isMigrateDisabled({ account: null, authorized: true, migratableCount: 1, knotCount: 1 }) ).toBe(true); expect( isMigrateDisabled({ account: dummyAccount, authorized: false, migratableCount: 1, knotCount: 1 }) ).toBe(true); }); it("is disabled when there are no migratable repos or no knots", () => { expect( isMigrateDisabled({ account: dummyAccount, authorized: true, migratableCount: 0, knotCount: 1 }) ).toBe(true); expect( isMigrateDisabled({ account: dummyAccount, authorized: true, migratableCount: 1, knotCount: 0 }) ).toBe(true); }); it("is enabled when prerequisites and selections are satisfied", () => { expect( isMigrateDisabled({ account: dummyAccount, authorized: true, migratableCount: 2, knotCount: 1 }) ).toBe(false); }); it("is disabled when flow disabled is true", () => { expect( isMigrateDisabled({ account: dummyAccount, authorized: true, migratableCount: 2, knotCount: 1, disabled: true }) ).toBe(true); }); }); });