"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var semver_1 = require("semver");
var rule_interface_1 = require("../interfaces/rule.interface");
var support_prerelease_if_not_released_1 = require("./support-prerelease-if-not-released");
describe("support-prerelease-if-not-released", function () {
    function generateVersions() {
        var sortedVersions = [
            "3.0.0-alpha.2",
            "3.0.0-alpha.1",
            "3.0.0-alpha.0",
            "2.0.0",
            "2.0.0-alpha.0",
        ].map(function (v) { return new semver_1.SemVer(v); });
        return sortedVersions;
    }
    describe("with default parameters", function () {
        it("should support the latest alpha release", function () {
            expect.assertions(1);
            var result = support_prerelease_if_not_released_1.supportPreReleaseIfNotReleased(undefined, new semver_1.SemVer("3.0.0-alpha.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should continue on the latest prerelease-1", function () {
            expect.assertions(1);
            var result = support_prerelease_if_not_released_1.supportPreReleaseIfNotReleased(undefined, new semver_1.SemVer("3.0.0-alpha.1"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should continue on the latest released version", function () {
            expect.assertions(1);
            var result = support_prerelease_if_not_released_1.supportPreReleaseIfNotReleased(undefined, new semver_1.SemVer("2.0.0"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should continue on alpha version for which a release is present", function () {
            expect.assertions(1);
            var result = support_prerelease_if_not_released_1.supportPreReleaseIfNotReleased(undefined, new semver_1.SemVer("2.0.0-alpha.0"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
    });
    describe("with numberOfMajorReleases=2", function () {
        function generateOptions() {
            return {
                numberOfPreReleases: 2,
            };
        }
        it("should support the latest alpha version", function () {
            expect.assertions(1);
            var result = support_prerelease_if_not_released_1.supportPreReleaseIfNotReleased(generateOptions(), new semver_1.SemVer("3.0.0-alpha.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should support the latest-1 alpha version", function () {
            expect.assertions(1);
            var result = support_prerelease_if_not_released_1.supportPreReleaseIfNotReleased(generateOptions(), new semver_1.SemVer("3.0.0-alpha.1"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should continue on the latest-2 alpha", function () {
            expect.assertions(1);
            var result = support_prerelease_if_not_released_1.supportPreReleaseIfNotReleased(generateOptions(), new semver_1.SemVer("3.0.0-alpha.0"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
        it("should continue on the released alpha", function () {
            expect.assertions(1);
            var result = support_prerelease_if_not_released_1.supportPreReleaseIfNotReleased(generateOptions(), new semver_1.SemVer("2.0.0-alpha.0"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
    });
    describe("with numberOfMajorReleases=all", function () {
        function generateOptions() {
            return {
                numberOfPreReleases: "all",
            };
        }
        it("should support the latest alpha version", function () {
            expect.assertions(1);
            var result = support_prerelease_if_not_released_1.supportPreReleaseIfNotReleased(generateOptions(), new semver_1.SemVer("3.0.0-alpha.2"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should support the latest-1 alpha version", function () {
            expect.assertions(1);
            var result = support_prerelease_if_not_released_1.supportPreReleaseIfNotReleased(generateOptions(), new semver_1.SemVer("3.0.0-alpha.1"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should support on the latest-2 alpha", function () {
            expect.assertions(1);
            var result = support_prerelease_if_not_released_1.supportPreReleaseIfNotReleased(generateOptions(), new semver_1.SemVer("3.0.0-alpha.0"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.support });
        });
        it("should continue on the released alpha", function () {
            expect.assertions(1);
            var result = support_prerelease_if_not_released_1.supportPreReleaseIfNotReleased(generateOptions(), new semver_1.SemVer("2.0.0-alpha.0"), generateVersions());
            expect(result).toEqual({ action: rule_interface_1.Action.continue });
        });
    });
});
