Files
SCM-Manager/scm-ui/ui-webapp/src/repos/permissions/components/permissionValidation.test.ts

70 lines
1.8 KiB
TypeScript
Raw Normal View History

import * as validator from "./permissionValidation";
2018-10-02 15:27:51 +02:00
describe("permission validation", () => {
it("should return true if permission is valid and does not exist", () => {
2018-10-02 15:27:51 +02:00
const permissions = [];
const name = "PermissionName";
2018-10-02 15:27:51 +02:00
const groupPermission = false;
expect(
validator.isPermissionValid(name, groupPermission, permissions)
2018-10-02 15:27:51 +02:00
).toBe(true);
});
it("should return true if permission is valid and does not exists with same group permission", () => {
2018-10-02 15:27:51 +02:00
const permissions = [
{
name: "PermissionName",
2018-10-02 15:27:51 +02:00
groupPermission: true,
type: "READ",
2019-01-28 16:48:57 +01:00
_links: {},
verbs: []
}
2018-10-02 15:27:51 +02:00
];
const name = "PermissionName";
2018-10-02 15:27:51 +02:00
const groupPermission = false;
expect(
validator.isPermissionValid(name, groupPermission, permissions)
2018-10-02 15:27:51 +02:00
).toBe(true);
});
it("should return false if permission is valid but exists", () => {
2018-10-02 15:27:51 +02:00
const permissions = [
{
name: "PermissionName",
2018-10-02 15:27:51 +02:00
groupPermission: false,
type: "READ",
2019-01-28 16:48:57 +01:00
_links: {},
verbs: []
}
2018-10-02 15:27:51 +02:00
];
const name = "PermissionName";
2018-10-02 15:27:51 +02:00
const groupPermission = false;
expect(
validator.isPermissionValid(name, groupPermission, permissions)
2018-10-02 15:27:51 +02:00
).toBe(false);
});
it("should return false if permission does not exist but is invalid", () => {
2018-10-02 15:27:51 +02:00
const permissions = [];
const name = "@PermissionName";
2018-10-02 15:27:51 +02:00
const groupPermission = false;
expect(
validator.isPermissionValid(name, groupPermission, permissions)
2018-10-02 15:27:51 +02:00
).toBe(false);
});
it("should return false if permission is not valid and does not exist", () => {
2018-10-02 15:27:51 +02:00
const permissions = [];
const name = "@PermissionName";
2018-10-02 15:27:51 +02:00
const groupPermission = false;
expect(
validator.isPermissionValid(name, groupPermission, permissions)
2018-10-02 15:27:51 +02:00
).toBe(false);
});
});