"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var semver_1 = require("semver");
var rule_interface_1 = require("./interfaces/rule.interface");
var version_for_message_finder_1 = __importDefault(require("./version-for-message-finder"));
describe("VersionForMessageFinder", function () {
    describe("with not supported versions", function () {
        it("should return undefined", function () {
            var target = new version_for_message_finder_1.default();
            expect(target.findBest([], new semver_1.SemVer("1.0.0"))).toBe(undefined);
        });
    });
    describe("with a supported version of the same major & minor version", function () {
        it("should return the oldest major + minor supported version", function () {
            var target = new version_for_message_finder_1.default();
            var results = [
                { version: new semver_1.SemVer("3.0.0"), action: rule_interface_1.Action.support },
                { version: new semver_1.SemVer("2.2.0"), action: rule_interface_1.Action.support },
                { version: new semver_1.SemVer("2.1.2"), action: rule_interface_1.Action.support },
                { version: new semver_1.SemVer("2.1.1"), action: rule_interface_1.Action.support },
                { version: new semver_1.SemVer("2.1.0"), action: rule_interface_1.Action.deprecate },
            ];
            expect(target.findBest(results, new semver_1.SemVer("2.1.0"))).toEqual(new semver_1.SemVer("2.1.1"));
        });
    });
    describe("with a supported version of the same major version", function () {
        it("should return the latest version of the minor still supported", function () {
            var target = new version_for_message_finder_1.default();
            var results = [
                { version: new semver_1.SemVer("3.0.0"), action: rule_interface_1.Action.support },
                { version: new semver_1.SemVer("2.2.2"), action: rule_interface_1.Action.support },
                { version: new semver_1.SemVer("2.2.1"), action: rule_interface_1.Action.support },
                { version: new semver_1.SemVer("2.2.0"), action: rule_interface_1.Action.support },
                { version: new semver_1.SemVer("2.1.0"), action: rule_interface_1.Action.deprecate },
            ];
            expect(target.findBest(results, new semver_1.SemVer("2.1.0"))).toEqual(new semver_1.SemVer("2.2.2"));
        });
    });
    describe("with a supported version of another major", function () {
        it("should return the latest minor&patch of the oldest supported version", function () {
            var target = new version_for_message_finder_1.default();
            var results = [
                { version: new semver_1.SemVer("4.0.0"), action: rule_interface_1.Action.support },
                { version: new semver_1.SemVer("3.1.1"), action: rule_interface_1.Action.support },
                { version: new semver_1.SemVer("3.1.0"), action: rule_interface_1.Action.support },
                { version: new semver_1.SemVer("3.0.0"), action: rule_interface_1.Action.support },
                { version: new semver_1.SemVer("2.1.0"), action: rule_interface_1.Action.deprecate },
            ];
            expect(target.findBest(results, new semver_1.SemVer("2.1.0"))).toEqual(new semver_1.SemVer("3.1.1"));
        });
    });
});
