import { makeAppObjectRepo } from "@vived/core";
import { makeStateMachineEntity } from "../../StateMachine";
import { makeChallengeEntity } from "../Entities/ChallengeEntity";
import { ChallengeMock } from "../Mocks/ChallengeMock";
import { SerializeChallengeUC } from "./SerializeChallenge";
function makeTestRig() {
    const appObjects = makeAppObjectRepo();
    const stateMachine = makeStateMachineEntity(appObjects.getOrCreate("AppState"));
    const registerSpy = jest.spyOn(stateMachine, "registerSerializedSystem");
    const ao = appObjects.getOrCreate("Challenge");
    const serializer = new SerializeChallengeUC(ao);
    const challenge = makeChallengeEntity(ao);
    const mockChallenge = new 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