import { makeAppObjectRepo } from "@vived/core";
import { makeFeatureFlagsEntity } from "../../FeatureFlags";
import { MockAppHandlerEntity } from "../Mocks/MockAppHandlerEntity";
import { makeEnableFeatureUC } from "./EnableFeatureUC";
function makeTestRig() {
    const appObjectRepo = makeAppObjectRepo();
    const handlerAO = appObjectRepo.getOrCreate("Handler");
    const mockAppHandler = new MockAppHandlerEntity(handlerAO);
    const featureFlagsEntity = makeFeatureFlagsEntity(appObjectRepo.getOrCreate("FeatureFlags"));
    const uc = makeEnableFeatureUC(handlerAO);
    return { mockAppHandler, uc, featureFlagsEntity };
}
describe("Enable Feature UC Handler", () => {
    it("Registers as a handler when constructed", () => {
        const { mockAppHandler, uc } = makeTestRig();
        expect(mockAppHandler.registerRequestHandler).toHaveBeenCalledWith(uc);
    });
    it("Submits the feature", () => {
        const { uc, featureFlagsEntity } = makeTestRig();
        expect(featureFlagsEntity.hasFlag("someFeature")).toEqual(false);
        uc.handleRequest(1, { featureFlag: "someFeature" });
        expect(featureFlagsEntity.hasFlag("someFeature")).toEqual(true);
    });
    it("Throws for an unsupported version", () => {
        const { uc } = makeTestRig();
        expect(() => uc.handleRequest(-1)).toThrowError();
    });
    it("Throws for an bungled payload", () => {
        const { uc } = makeTestRig();
        expect(() => uc.handleRequest(2, { foo: "bar" })).toThrowError();
    });
});
//# sourceMappingURL=EnableFeatureUC.test.js.map