simpleScope.spec.js 1.08 KB
import {
	appendSimplePermissions,
	SIMPLE_PERMISSION_IDS,
} from "./simpleScope";

describe("simple project permission scope", () => {
	it("injects the migrated routes only when the development bypass is enabled", () => {
		const source = [{ authId: "903", parentId: "1" }];

		const result = appendSimplePermissions(source, {
			nodeEnv: "development",
			enabled: "true",
		});

		expect(result).not.toBe(source);
		expect(result.map(item => item.authId)).toEqual(
			expect.arrayContaining(SIMPLE_PERMISSION_IDS),
		);
	});

	it("never injects permissions into a production build", () => {
		const source = [{ authId: "903", parentId: "1" }];

		expect(appendSimplePermissions(source, {
			nodeEnv: "production",
			enabled: "true",
		})).toEqual(source);
	});

	it("keeps an existing backend permission only once", () => {
		const source = [
			{ authId: "904", parentId: "1" },
			{ authId: "90412", parentId: "904" },
		];

		const result = appendSimplePermissions(source, {
			nodeEnv: "test",
			enabled: true,
		});

		expect(result.filter(item => item.authId === "90412")).toHaveLength(1);
	});
});