"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const Entities_1 = require("../Entities");
const QuestionEntity_1 = require("../Entities/QuestionEntity");
const ToggleQuestionAnswerIsCorrect_1 = require("../UC/ToggleQuestionAnswerIsCorrect");
const toggleAnswerIsCorrect_1 = require("./toggleAnswerIsCorrect");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const question = appObjects.getOrCreate("Question");
    const questionEntity = (0, QuestionEntity_1.makeQuestionEntity)(question);
    questionEntity.answerFactory = (id) => {
        const index = questionEntity.getAllAnswers().length + 1;
        const ao = appObjects.getOrCreate(id ?? "answer" + index);
        return (0, Entities_1.makeQuestionAnswerEntity)(ao);
    };
    const answer = questionEntity.createNewAnswer();
    const toggleUC = (0, ToggleQuestionAnswerIsCorrect_1.makeToggleQuestionChallengeAnswerIsCorrectUC)(answer.appObject);
    return { questionEntity, answer, toggleUC, appObjects };
}
describe("toggleAnswer Is Correct Controller", () => {
    it("Sends the feedback to the UC", () => {
        const { answer, toggleUC, appObjects } = makeTestRig();
        const spy = jest.spyOn(toggleUC, "toggleIsCorrect");
        (0, toggleAnswerIsCorrect_1.toggleAnswerIsCorrect)(answer.id, appObjects);
        expect(spy).toHaveBeenCalled();
    });
    it("Warns if it can't find the Question Entity", () => {
        const { questionEntity, appObjects, answer } = makeTestRig();
        questionEntity.dispose();
        appObjects.submitWarning = jest.fn();
        (0, toggleAnswerIsCorrect_1.toggleAnswerIsCorrect)(answer.id, appObjects);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
    it("Warns if it can't find the Answer Entity", () => {
        const { appObjects } = makeTestRig();
        appObjects.submitWarning = jest.fn();
        (0, toggleAnswerIsCorrect_1.toggleAnswerIsCorrect)("some id", appObjects);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
    it("Warns if it can't find the UC", () => {
        const { appObjects, toggleUC, answer } = makeTestRig();
        toggleUC.dispose();
        appObjects.submitWarning = jest.fn();
        (0, toggleAnswerIsCorrect_1.toggleAnswerIsCorrect)(answer.id, appObjects);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
});
//# sourceMappingURL=toggleAnswerIsCorrect.test.js.map