"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var semver_1 = require("semver");
var rule_interface_1 = require("../interfaces/rule.interface");
var support_latest_1 = require("./support-latest");
describe("support-latest", function () {
    function generateVersions() {
        var sortedVersions = [
            "3.0.0-alpha.0",
            "2.2.2",
            "2.2.1",
            "2.2.0",
            "2.1.2",
            "2.1.1",
            "2.1.0",
            "2.0.2",
            "2.0.1",
            "2.0.0",
            "1.2.2",
            "1.2.1",
            "1.2.0",
            "1.1.2",
            "1.1.1",
            "1.1.0",
            "1.0.2",
            "1.0.1",
            "1.0.0",
        ].map(function (v) { return new semver_1.SemVer(v); });
        return sortedVersions;
    }
    describe("with default parameters", function () {
        it("should support the latest stable release", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(undefined, new semver_1.SemVer("2.2.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should continue on the latest prerelease", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(undefined, new semver_1.SemVer("3.0.0-alpha.0"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should continue on the major-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(undefined, new semver_1.SemVer("1.0.0"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should continue on the minor-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(undefined, new semver_1.SemVer("2.1.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should continue on the patch-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(undefined, new semver_1.SemVer("2.2.1"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
    });
    describe("with numberOfMajorReleases=2", function () {
        function generateOptions() {
            return {
                numberOfMajorReleases: 2,
            };
        }
        it("should support the latest version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.2.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should support the latest-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("1.2.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should continue on the latest major, minor-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.1.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should continue on the latest major-1, minor-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("1.1.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should continue on the latest major, latest minor, patch-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.2.1"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should continue on the latest-1 major, latest minor, patch-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("1.2.1"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should continue on the latest prerelease", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("3.0.0-alpha.0"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
    });
    describe("with numberOfMinorReleases=2", function () {
        function generateOptions() {
            return {
                numberOfMinorReleases: 2,
            };
        }
        it("should support the latest version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.2.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should continue with the latest major-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("1.2.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should support on the latest major, minor-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.1.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should continue on the latest major-1, minor-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("1.1.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
    });
    describe("with numberOfPatchReleases=2", function () {
        function generateOptions() {
            return {
                numberOfPatchReleases: 2,
            };
        }
        it("should support the latest version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.2.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should continue with the latest major-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("1.2.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should continue on the latest major, minor-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.1.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should continue on the latest major-1, minor-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("1.1.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should support the latest major, minor and patch-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.2.1"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
    });
    describe("with numberOfMajorReleases=all", function () {
        function generateOptions() {
            return {
                numberOfMajorReleases: "all",
            };
        }
        it("should support the latest version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.2.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should support with the latest-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("1.2.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should continue with the previous minor", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.1.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should continue on the latest major, latest minor, patch-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.2.1"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should continue on the latest prerelease", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("3.0.0-alpha.0"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
    });
    describe("with numberOfMinorReleases=all", function () {
        function generateOptions() {
            return {
                numberOfMinorReleases: "all",
            };
        }
        it("should support the latest version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.2.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should continue with the latest-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("1.2.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should support the previous minor", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.1.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should support the latest minor - 2", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.0.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should continue on the latest major, patch-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.2.1"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should continue on the latest prerelease", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("3.0.0-alpha.0"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
    });
    describe("with numberOfPatchReleases=all", function () {
        function generateOptions() {
            return {
                numberOfPatchReleases: "all",
            };
        }
        it("should support the latest version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.2.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should continue with the latest-1 version", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("1.2.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should continue with the previous minor", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.1.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should support the previous patch", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.2.1"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should support the latest patch - 2", function () {
            expect.assertions(1);
            var result = support_latest_1.supportLatest(generateOptions(), new semver_1.SemVer("2.2.0"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
    });
});
