"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const core_1 = require("@vived/core");
const StateMachine_1 = require("../../StateMachine");
const ChallengeEntity_1 = require("../Entities/ChallengeEntity");
const ChallengeMock_1 = require("../Mocks/ChallengeMock");
const SerializeChallenge_1 = require("./SerializeChallenge");
function makeTestRig() {
    const appObjects = (0, core_1.makeAppObjectRepo)();
    const stateMachine = (0, StateMachine_1.makeStateMachineEntity)(appObjects.getOrCreate("AppState"));
    const registerSpy = jest.spyOn(stateMachine, "registerSerializedSystem");
    const ao = appObjects.getOrCreate("Challenge");
    const serializer = new SerializeChallenge_1.SerializeChallengeUC(ao);
    const challenge = (0, ChallengeEntity_1.makeChallengeEntity)(ao);
    const mockChallenge = new ChallengeMock_1.ChallengeMock("MOCK_CHALLENGE");
    challenge.registerChallenge(mockChallenge);
    return { challenge, serializer, stateMachine, registerSpy };
}
describe("Serialize Round UCSerializedStateV1", () => {
    it("Registers with the Serialized System on construction", () => {
        const { registerSpy, serializer } = makeTestRig();
        expect(registerSpy).toHaveBeenCalledWith(serializer);
    });
    it("Set to default if an unsupported version is passed in", () => {
        const { serializer } = makeTestRig();
        serializer.applyDefaultState = jest.fn();
        const state = {
            challenge: "NONE",
        };
        serializer.applySystemState(state, -1);
        expect(serializer.applyDefaultState).toHaveBeenCalled();
    });
    it("Serializes the challenge", () => {
        const { challenge, serializer } = makeTestRig();
        challenge.selectedChallenge = "MOCK_CHALLENGE";
        const state = serializer.getSystemState();
        expect(state.challenge).toEqual("MOCK_CHALLENGE");
    });
    it("Deserializes Challenge id", () => {
        const { challenge, serializer } = makeTestRig();
        const state = {
            challenge: "MOCK_CHALLENGE",
        };
        serializer.applySystemState(state, 1);
        expect(challenge.selectedChallenge).toEqual("MOCK_CHALLENGE");
    });
    it("Sets the default", () => {
        const { challenge, serializer } = makeTestRig();
        challenge.selectedChallenge = "MOCK_CHALLENGE";
        serializer.applyDefaultState();
        expect(challenge.selectedChallenge).toEqual("NONE");
    });
});
//# sourceMappingURL=SerializeChallenge.test.js.map