"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 SetAnswerFeedbackUC_1 = require("../UC/SetAnswerFeedbackUC");
const setAnswerFeedback_1 = require("./setAnswerFeedback");
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 setFeedbackUC = (0, SetAnswerFeedbackUC_1.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");
        (0, setAnswerFeedback_1.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();
        (0, setAnswerFeedback_1.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();
        (0, setAnswerFeedback_1.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();
        (0, setAnswerFeedback_1.setAnswerFeedback)(answer.id, "Hello World", appObjects);
        expect(appObjects.submitWarning).toHaveBeenCalled();
    });
});
//# sourceMappingURL=setAnswerFeedback.test.js.map