"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const FeatureFlags_1 = require("../../FeatureFlags");
const MockAppHandlerEntity_1 = require("../Mocks/MockAppHandlerEntity");
const EnableFeatureUC_1 = require("./EnableFeatureUC");
function makeTestRig() {
    const appObjectRepo = (0, core_1.makeAppObjectRepo)();
    const handlerAO = appObjectRepo.getOrCreate("Handler");
    const mockAppHandler = new MockAppHandlerEntity_1.MockAppHandlerEntity(handlerAO);
    const featureFlagsEntity = (0, FeatureFlags_1.makeFeatureFlagsEntity)(appObjectRepo.getOrCreate("FeatureFlags"));
    const uc = (0, EnableFeatureUC_1.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