import { makeAppObjectRepo } from "@vived/core";
import { makeQuestionAnswerEntity } from "../Entities";
import { makeQuestionEntity } from "../Entities/QuestionEntity";
import { makeToggleQuestionChallengeAnswerIsCorrectUC } from "../UC/ToggleQuestionAnswerIsCorrect";
import { toggleAnswerIsCorrect } from "./toggleAnswerIsCorrect";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const question = appObjects.getOrCreate("Question");
    const questionEntity = makeQuestionEntity(question);
    questionEntity.answerFactory = (id) => {
        const index = questionEntity.getAllAnswers().length + 1;
        const ao = appObjects.getOrCreate(id ?? "answer" + index);
        return makeQuestionAnswerEntity(ao);
    };
    const answer = questionEntity.createNewAnswer();
    const toggleUC = 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");
        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();
        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();
        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();
        toggleAnswerIsCorrect(answer.id, appObjects);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
});
//# sourceMappingURL=toggleAnswerIsCorrect.test.js.map