2019-10-20 16:59:02 +02:00
|
|
|
import { Repository } from "@scm-manager/ui-types";
|
|
|
|
|
import { getProtocolLinkByType } from "./repositories";
|
2019-10-19 16:38:07 +02:00
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
describe("getProtocolLinkByType tests", () => {
|
|
|
|
|
it("should return the http protocol link", () => {
|
2019-10-19 16:38:07 +02:00
|
|
|
const repository: Repository = {
|
2019-10-20 16:59:02 +02:00
|
|
|
namespace: "scm",
|
|
|
|
|
name: "core",
|
|
|
|
|
type: "git",
|
2019-10-19 16:38:07 +02:00
|
|
|
_links: {
|
|
|
|
|
protocol: [
|
|
|
|
|
{
|
2019-10-20 16:59:02 +02:00
|
|
|
name: "http",
|
|
|
|
|
href: "http://scm.scm-manager.org/repo/scm/core"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2019-10-19 16:38:07 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
const link = getProtocolLinkByType(repository, "http");
|
|
|
|
|
expect(link).toBe("http://scm.scm-manager.org/repo/scm/core");
|
2019-10-19 16:38:07 +02:00
|
|
|
});
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
it("should return the http protocol link from multiple protocols", () => {
|
2019-10-19 16:38:07 +02:00
|
|
|
const repository: Repository = {
|
2019-10-20 16:59:02 +02:00
|
|
|
namespace: "scm",
|
|
|
|
|
name: "core",
|
|
|
|
|
type: "git",
|
2019-10-19 16:38:07 +02:00
|
|
|
_links: {
|
|
|
|
|
protocol: [
|
|
|
|
|
{
|
2019-10-20 16:59:02 +02:00
|
|
|
name: "http",
|
|
|
|
|
href: "http://scm.scm-manager.org/repo/scm/core"
|
2019-10-19 16:38:07 +02:00
|
|
|
},
|
|
|
|
|
{
|
2019-10-20 16:59:02 +02:00
|
|
|
name: "ssh",
|
|
|
|
|
href: "git@scm.scm-manager.org:scm/core"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2019-10-19 16:38:07 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
const link = getProtocolLinkByType(repository, "http");
|
|
|
|
|
expect(link).toBe("http://scm.scm-manager.org/repo/scm/core");
|
2019-10-19 16:38:07 +02:00
|
|
|
});
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
it("should return the http protocol, even if the protocol is a single link", () => {
|
2019-10-19 16:38:07 +02:00
|
|
|
const repository: Repository = {
|
2019-10-20 16:59:02 +02:00
|
|
|
namespace: "scm",
|
|
|
|
|
name: "core",
|
|
|
|
|
type: "git",
|
2019-10-19 16:38:07 +02:00
|
|
|
_links: {
|
|
|
|
|
protocol: {
|
2019-10-20 16:59:02 +02:00
|
|
|
name: "http",
|
|
|
|
|
href: "http://scm.scm-manager.org/repo/scm/core"
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-19 16:38:07 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
const link = getProtocolLinkByType(repository, "http");
|
|
|
|
|
expect(link).toBe("http://scm.scm-manager.org/repo/scm/core");
|
2019-10-19 16:38:07 +02:00
|
|
|
});
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
it("should return null, if such a protocol does not exists", () => {
|
2019-10-19 16:38:07 +02:00
|
|
|
const repository: Repository = {
|
2019-10-20 16:59:02 +02:00
|
|
|
namespace: "scm",
|
|
|
|
|
name: "core",
|
|
|
|
|
type: "git",
|
2019-10-19 16:38:07 +02:00
|
|
|
_links: {
|
|
|
|
|
protocol: [
|
|
|
|
|
{
|
2019-10-20 16:59:02 +02:00
|
|
|
name: "http",
|
|
|
|
|
href: "http://scm.scm-manager.org/repo/scm/core"
|
2019-10-19 16:38:07 +02:00
|
|
|
},
|
|
|
|
|
{
|
2019-10-20 16:59:02 +02:00
|
|
|
name: "ssh",
|
|
|
|
|
href: "git@scm.scm-manager.org:scm/core"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
2019-10-19 16:38:07 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
const link = getProtocolLinkByType(repository, "awesome");
|
2019-10-19 16:38:07 +02:00
|
|
|
expect(link).toBeNull();
|
|
|
|
|
});
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
it("should return null, if no protocols are available", () => {
|
2019-10-19 16:38:07 +02:00
|
|
|
const repository: Repository = {
|
2019-10-20 16:59:02 +02:00
|
|
|
namespace: "scm",
|
|
|
|
|
name: "core",
|
|
|
|
|
type: "git",
|
|
|
|
|
_links: {}
|
2019-10-19 16:38:07 +02:00
|
|
|
};
|
|
|
|
|
|
2019-10-20 16:59:02 +02:00
|
|
|
const link = getProtocolLinkByType(repository, "http");
|
2019-10-19 16:38:07 +02:00
|
|
|
expect(link).toBeNull();
|
|
|
|
|
});
|
|
|
|
|
});
|