"use strict";
/*!
 * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
 * Licensed under the MIT License.
 */
Object.defineProperty(exports, "__esModule", { value: true });
const node_assert_1 = require("node:assert");
const gcHelpers_js_1 = require("../../gc/gcHelpers.js");
describe("Garbage Collection Helpers Tests", () => {
    describe("[TEMP] shouldAllowGcTombstoneEnforcement - Show behavior change as it's replaced by shouldAllowGcSweep", () => {
        const testCases = [
            {
                persisted: undefined,
                current: undefined,
                expectedShouldAllowValue: true,
            },
            {
                persisted: undefined,
                current: 1,
                expectedShouldAllowValue: false,
            },
            {
                persisted: 1,
                current: undefined,
                expectedShouldAllowValue: true,
            },
            {
                persisted: 1,
                current: 1,
                expectedShouldAllowValue: true,
            },
            {
                persisted: 1,
                current: 2,
                expectedShouldAllowValue: false,
            },
            {
                persisted: 2,
                current: 1,
                expectedShouldAllowValue: false,
            },
        ];
        for (const { persisted, current, expectedShouldAllowValue } of testCases) {
            it(`persisted=${persisted}, current=${current}`, () => {
                const shouldAllow = (0, gcHelpers_js_1.shouldAllowGcSweep)({ tombstoneGeneration: persisted }, current);
                node_assert_1.strict.equal(shouldAllow, expectedShouldAllowValue);
            });
        }
    });
    describe("shouldAllowGcSweep", () => {
        const testCases = [
            {
                persisted: {},
                current: undefined,
                expectedShouldAllowValue: true,
            },
            {
                persisted: { gcGeneration: 1 },
                current: undefined,
                expectedShouldAllowValue: true,
            },
            {
                persisted: {},
                current: 0,
                expectedShouldAllowValue: false,
            },
            {
                persisted: { tombstoneGeneration: 0 },
                current: 0,
                expectedShouldAllowValue: true,
            },
            {
                persisted: { tombstoneGeneration: 1 },
                current: 1,
                expectedShouldAllowValue: true,
            },
            {
                persisted: { tombstoneGeneration: 1 },
                current: 0,
                expectedShouldAllowValue: false,
            },
            {
                persisted: { gcGeneration: 0 },
                current: 0,
                expectedShouldAllowValue: true,
            },
            {
                persisted: { gcGeneration: 1 },
                current: 1,
                expectedShouldAllowValue: true,
            },
            {
                persisted: { gcGeneration: 1 },
                current: 2,
                expectedShouldAllowValue: false,
            },
            {
                persisted: { gcGeneration: 2 },
                current: 1,
                expectedShouldAllowValue: false,
            },
        ];
        for (const { persisted, current, expectedShouldAllowValue } of testCases) {
            it(`persisted=${JSON.stringify(persisted)}, current=${current}`, () => {
                const shouldAllow = (0, gcHelpers_js_1.shouldAllowGcSweep)(persisted, current);
                node_assert_1.strict.equal(shouldAllow, expectedShouldAllowValue);
            });
        }
    });
    describe("dataStoreNodePathOnly", () => {
        const testCases = [
            {
                path: "/",
                expected: "/",
            },
            {
                path: "/a",
                expected: "/a",
            },
            {
                path: "/a/b",
                expected: "/a",
            },
            {
                path: "/a/b/c",
                expected: "/a",
            },
        ];
        for (const { path, expected } of testCases) {
            it(`path=${path}`, () => {
                const result = (0, gcHelpers_js_1.dataStoreNodePathOnly)(path);
                node_assert_1.strict.equal(result, expected);
            });
        }
    });
    describe("urlToGCNodePath", () => {
        const testCases = [
            {
                url: "/a",
                expected: "/a",
            },
            {
                url: "/a/",
                expected: "/a",
            },
            {
                url: "/a/b",
                expected: "/a/b",
            },
            {
                url: "/a/b/",
                expected: "/a/b",
            },
            {
                url: "/a?x=1",
                expected: "/a",
            },
            {
                url: "/a/?x=1",
                expected: "/a",
            },
            {
                url: "/a/b?x=1",
                expected: "/a/b",
            },
            {
                url: "/a/b/?x=1",
                expected: "/a/b",
            },
        ];
        for (const { url, expected } of testCases) {
            it(`url=${url}`, () => {
                const result = (0, gcHelpers_js_1.urlToGCNodePath)(url);
                node_assert_1.strict.equal(result, expected);
            });
        }
    });
});
//# sourceMappingURL=gcHelpers.spec.js.map