mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-10-04 02:04:06 +00:00
Co-authored-by: alejandrobailo <alejandrobailo94@gmail.com>
92 lines
2.7 KiB
TypeScript
92 lines
2.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import type { TourCompletionRecord } from "@/lib/tours/tour-types";
|
|
import { TOUR_COMPLETION_STATES } from "@/lib/tours/tour-types";
|
|
|
|
import { shouldStartOnboarding } from "../gate-decision";
|
|
|
|
const recordWithState = (
|
|
state: TourCompletionRecord["state"],
|
|
): TourCompletionRecord => ({
|
|
tourId: "add-provider",
|
|
version: 1,
|
|
state,
|
|
completedAt: "2026-01-15T12:00:00.000Z",
|
|
});
|
|
|
|
describe("shouldStartOnboarding", () => {
|
|
it("returns true for a zero-provider user with no completion record", () => {
|
|
const result = shouldStartOnboarding({
|
|
hasProviders: false,
|
|
canManageProviders: true,
|
|
completionRecord: null,
|
|
});
|
|
expect(result).toBe(true);
|
|
});
|
|
|
|
it("returns false when the user cannot add providers, even in an empty tenant", () => {
|
|
// Limited-visibility users see zero providers without the tenant being empty.
|
|
const result = shouldStartOnboarding({
|
|
hasProviders: false,
|
|
canManageProviders: false,
|
|
completionRecord: null,
|
|
});
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
it("returns false when the user already has providers", () => {
|
|
const result = shouldStartOnboarding({
|
|
hasProviders: true,
|
|
canManageProviders: true,
|
|
completionRecord: null,
|
|
});
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
it("returns false when a dismissed record exists", () => {
|
|
const result = shouldStartOnboarding({
|
|
hasProviders: false,
|
|
canManageProviders: true,
|
|
completionRecord: recordWithState(TOUR_COMPLETION_STATES.DISMISSED),
|
|
});
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
it("returns false when a completed record exists", () => {
|
|
const result = shouldStartOnboarding({
|
|
hasProviders: false,
|
|
canManageProviders: true,
|
|
completionRecord: recordWithState(TOUR_COMPLETION_STATES.COMPLETED),
|
|
});
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
it("returns false when a skipped record exists", () => {
|
|
const result = shouldStartOnboarding({
|
|
hasProviders: false,
|
|
canManageProviders: true,
|
|
completionRecord: recordWithState(TOUR_COMPLETION_STATES.SKIPPED),
|
|
});
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
it("fails open when hasProviders is undefined", () => {
|
|
// strict === false check rejects non-false values; don't force onboarding on unknown state
|
|
const result = shouldStartOnboarding({
|
|
hasProviders: undefined,
|
|
canManageProviders: true,
|
|
completionRecord: null,
|
|
});
|
|
expect(result).toBe(false);
|
|
});
|
|
|
|
it("fails open when hasProviders is null", () => {
|
|
const result = shouldStartOnboarding({
|
|
hasProviders: null as unknown as boolean,
|
|
canManageProviders: true,
|
|
completionRecord: null,
|
|
});
|
|
expect(result).toBe(false);
|
|
});
|
|
});
|