import { makeAppObjectRepo } from "@vived/core";
import { makeQuestionAnswerEntity } from "../Entities";
import { makeQuestionEntity } from "../Entities/QuestionEntity";
import { makeSetAnswerFeedbackUC } from "../UC/SetAnswerFeedbackUC";
import { setAnswerFeedback } from "./setAnswerFeedback";
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 setFeedbackUC = makeSetAnswerFeedbackUC(answer.appObject);
    answer.feedbackText = "Hello World";
    return { questionEntity, answer, setFeedbackUC, appObjects };
}
describe("setAnswerFeedback Controller", () => {
    it("Sends the feedback to the UC", () => {
        const { answer, setFeedbackUC, appObjects } = makeTestRig();
        const spy = jest.spyOn(setFeedbackUC, "setFeedback");
        setAnswerFeedback(answer.id, "Hello World", appObjects);
        expect(spy).toHaveBeenCalledWith("Hello World");
    });
    it("Warns if it can't find the Question Entity", () => {
        const { questionEntity, appObjects, answer } = makeTestRig();
        appObjects.submitWarning = jest.fn();
        questionEntity.dispose();
        setAnswerFeedback(answer.id, "Hello World", appObjects);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
    it("Warns if it can't find the Answer Entity", () => {
        const { appObjects } = makeTestRig();
        appObjects.submitWarning = jest.fn();
        setAnswerFeedback("some id", "Hello World", appObjects);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
    it("Warns if it can't find the UC", () => {
        const { appObjects, setFeedbackUC, answer } = makeTestRig();
        setFeedbackUC.dispose();
        appObjects.submitWarning = jest.fn();
        setAnswerFeedback(answer.id, "Hello World", appObjects);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
});
//# sourceMappingURL=setAnswerFeedback.test.js.map