/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
import { makeCodecFamily } from "../../codec/index.js";
import { typeboxValidator } from "../../external-utilities/index.js";
// eslint-disable-next-line import/no-internal-modules
import { makeMessageCodec } from "../../shared-tree-core/messageCodecs.js";
import { TestChange } from "../testChange.js";
import { makeEncodingTestSuite, mintRevisionTag, testIdCompressor, testRevisionTagCodec, } from "../utils.js";
const commit1 = {
    revision: mintRevisionTag(),
    change: TestChange.mint([], 0),
};
const commit2 = {
    revision: mintRevisionTag(),
    change: TestChange.mint([0], [1, 2, 3]),
};
const commitWithoutRevision = {
    change: TestChange.mint([], 0),
};
const commitWithoutChange = {
    revision: mintRevisionTag(),
};
const commitInvalid = {
    revision: 1,
    change: "Invalid change",
};
const dummyContext = { originatorId: testIdCompressor.localSessionId };
const testCases = {
    successes: [
        [
            "Message with commit 1",
            {
                sessionId: testIdCompressor.localSessionId,
                commit: commit1,
            },
            dummyContext,
        ],
        [
            "Message with commit 2",
            {
                sessionId: testIdCompressor.localSessionId,
                commit: commit2,
            },
            dummyContext,
        ],
    ],
    failures: {
        0: [
            ["Empty message", {}, dummyContext],
            [
                "Missing sessionId",
                {
                    commit: commit1,
                },
                dummyContext,
            ],
            [
                "Missing commit",
                {
                    sessionId: "session1",
                },
                dummyContext,
            ],
            [
                "Message with invalid sessionId",
                {
                    sessionId: 1,
                    commit: commit1,
                },
                dummyContext,
            ],
            [
                "Message with commit without revision",
                {
                    sessionId: "session1",
                    commit: commitWithoutRevision,
                },
                dummyContext,
            ],
            [
                "Message with invalid commit",
                {
                    sessionId: "session1",
                    commit: commitInvalid,
                },
                dummyContext,
            ],
        ],
    },
};
describe("message codec", () => {
    const codec = makeMessageCodec(TestChange.codec, testRevisionTagCodec, {
        jsonValidator: typeboxValidator,
    });
    makeEncodingTestSuite(makeCodecFamily([[0, codec]]), testCases);
});
//# sourceMappingURL=message.spec.js.map