- {["to-review", "work-in-progress"].includes(signoffSource.status) && (
-
-
-
- )}
+ const handleRollback = (text: string) => {
+ rollbackChanges(text);
+ history.push(`/buckets/${bid}/collections/${cid}/records`);
+ };
-
+ return (
+
+
+ Review{" "}
+
+ {bid}/{cid}
+ {" "}
+ Changes
+
+
+ {signoffSource.status !== "signed" && (
+
+
+
+ )}
+
+
+
);
}
diff --git a/src/components/signoff/utils.ts b/src/components/signoff/utils.ts
new file mode 100644
index 000000000..25439ea26
--- /dev/null
+++ b/src/components/signoff/utils.ts
@@ -0,0 +1,25 @@
+import { SessionState, SignoffSourceInfo } from "../../types";
+
+export function isMember(
+ groupKey: string,
+ source: SignoffSourceInfo,
+ sessionState: SessionState
+) {
+ const {
+ serverInfo: { user, capabilities },
+ } = sessionState;
+ if (!source || !user?.principals) {
+ return false;
+ }
+ const { principals } = user;
+ const { bid, cid } = source;
+ const { signer = {} } = capabilities;
+ // @ts-ignore
+ const { [groupKey]: defaultGroupName } = signer;
+ // @ts-ignore
+ const { [groupKey]: groupName = defaultGroupName } = source;
+ const expectedGroup = groupName.replace("{collection_id}", cid);
+ const expectedPrincipal = `/buckets/${bid}/groups/${expectedGroup}`;
+
+ return principals.includes(expectedPrincipal);
+}
diff --git a/src/containers/signoff/SimpleReviewPage.ts b/src/containers/signoff/SimpleReviewPage.ts
index ac78b5326..e60ec87f1 100644
--- a/src/containers/signoff/SimpleReviewPage.ts
+++ b/src/containers/signoff/SimpleReviewPage.ts
@@ -25,6 +25,8 @@ function mapStateToProps(
return {
session: state.session,
signoff: state.signoff,
+ collection: state.collection,
+ capabilities: state.session.serverInfo.capabilities,
fetchRecords,
};
}
diff --git a/src/hooks.ts b/src/hooks/app.ts
similarity index 79%
rename from src/hooks.ts
rename to src/hooks/app.ts
index c6458e6ce..de4bf39d9 100644
--- a/src/hooks.ts
+++ b/src/hooks/app.ts
@@ -1,5 +1,5 @@
import { TypedUseSelectorHook, useSelector, useDispatch } from "react-redux";
-import type { AppDispatch, AppState } from "./types";
+import type { AppDispatch, AppState } from "../types";
export const useAppSelector: TypedUseSelectorHook
= useSelector;
export const useAppDispatch = () => useDispatch();
diff --git a/src/hooks/storage.ts b/src/hooks/storage.ts
new file mode 100644
index 000000000..e5d65a151
--- /dev/null
+++ b/src/hooks/storage.ts
@@ -0,0 +1,40 @@
+import { useState, useEffect } from "react";
+
+export const storageKeys = {
+ useSimpleReview: "useSimpleReview",
+};
+
+export function useLocalStorage(key: string, initialValue: any) {
+ const [val, setVal] = useState(() => {
+ try {
+ return localStorage[key] ? JSON.parse(localStorage[key]) : initialValue;
+ } catch (ex) {
+ console.error("Error retrieving value from localStorage", ex);
+ return initialValue;
+ }
+ });
+
+ const setStoredVal = val => {
+ try {
+ localStorage[key] = JSON.stringify(val);
+ setVal(val);
+ } catch (ex) {
+ console.error("Error setting value in localStorage", ex);
+ }
+ };
+
+ useEffect(() => {
+ // will fire if localStorage is touched in another browser tab/window
+ const handleStorageChange = (evt: StorageEvent) => {
+ if (evt.key !== key) {
+ return;
+ }
+ setVal(evt.newValue ? JSON.parse(evt.newValue) : undefined);
+ };
+ window.addEventListener("storage", handleStorageChange);
+
+ return () => window.removeEventListener("storage", handleStorageChange);
+ }, [key]);
+
+ return [val, setStoredVal];
+}
diff --git a/src/permission.tsx b/src/permission.tsx
index d9881e586..e28c5f588 100644
--- a/src/permission.tsx
+++ b/src/permission.tsx
@@ -1,6 +1,5 @@
import type {
SessionState,
- BucketState,
CollectionState,
GroupState,
GroupData,
@@ -37,12 +36,12 @@ export function canCreateBucket(session: SessionState): boolean {
export function canEditBucket(
session: SessionState,
- bucket: BucketState
+ bucketId: string
): boolean {
return can(session, (perm: PermissionsListEntry) => {
return (
perm.resource_name == "bucket" &&
- perm.bucket_id == bucket.data.id &&
+ perm.bucket_id == bucketId &&
perm.permissions.includes("write")
);
});
@@ -50,12 +49,12 @@ export function canEditBucket(
export function canCreateCollection(
session: SessionState,
- bucket: BucketState
+ bucketId: string
): boolean {
return can(session, (perm: PermissionsListEntry) => {
return (
perm.resource_name == "bucket" &&
- perm.bucket_id == bucket.data.id &&
+ perm.bucket_id == bucketId &&
perm.permissions.includes("collection:create")
);
});
@@ -63,7 +62,7 @@ export function canCreateCollection(
export function canEditCollection(
session: SessionState,
- bucket: BucketState,
+ bucketId: string,
collection: CollectionState
): boolean {
return can(session, (perm: PermissionsListEntry) => {
@@ -71,7 +70,7 @@ export function canEditCollection(
(perm.resource_name == "bucket" ||
(perm.resource_name == "collection" &&
perm.collection_id == collection.data.id)) &&
- perm.bucket_id == bucket.data.id &&
+ perm.bucket_id == bucketId &&
perm.permissions.includes("write")
);
});
@@ -79,12 +78,12 @@ export function canEditCollection(
export function canCreateGroup(
session: SessionState,
- bucket: BucketState
+ bucketId: string
): boolean {
return can(session, (perm: PermissionsListEntry) => {
return (
perm.resource_name == "bucket" &&
- perm.bucket_id == bucket.data.id &&
+ perm.bucket_id == bucketId &&
perm.permissions.includes("group:create")
);
});
@@ -92,7 +91,7 @@ export function canCreateGroup(
export function canEditGroup(
session: SessionState,
- bucket: BucketState,
+ bucketId: string,
group: GroupState
): boolean {
return can(session, (perm: PermissionsListEntry) => {
@@ -102,7 +101,7 @@ export function canEditGroup(
return (
(perm.resource_name == "bucket" ||
(perm.resource_name == "group" && perm.group_id == group.data.id)) &&
- perm.bucket_id == bucket.data.id &&
+ perm.bucket_id == bucketId &&
perm.permissions.includes("write")
);
});
@@ -110,7 +109,7 @@ export function canEditGroup(
export function canCreateRecord(
session: SessionState,
- bucket: BucketState,
+ bucketId: string,
collection: CollectionState
): boolean {
return can(session, (perm: PermissionsListEntry) => {
@@ -119,14 +118,14 @@ export function canCreateRecord(
(perm.resource_name == "collection" &&
perm.collection_id == collection.data.id &&
perm.permissions.includes("record:create"))) &&
- perm.bucket_id == bucket.data.id
+ perm.bucket_id == bucketId
);
});
}
export function canEditRecord(
session: SessionState,
- bucket: BucketState,
+ bucketId: string,
collection: CollectionState,
record: RecordState
): boolean {
@@ -139,7 +138,7 @@ export function canEditRecord(
perm.collection_id == collection.data.id &&
perm.record_id == record.data.id)) &&
perm.permissions.includes("write") &&
- perm.bucket_id == bucket.data.id
+ perm.bucket_id == bucketId
);
});
}
diff --git a/src/url.ts b/src/url.ts
index b343ce3c9..f10b543b0 100644
--- a/src/url.ts
+++ b/src/url.ts
@@ -30,6 +30,8 @@ const URLS = {
`/buckets/${bid}/collections/${cid}/history`,
"collection:permissions": ({ bid, cid }) =>
`/buckets/${bid}/collections/${cid}/permissions`,
+ "collection:simple-review": ({ bid, cid }) =>
+ `/buckets/${bid}/collections/${cid}/simple-review`,
"collection:records": ({ bid, cid }) =>
`/buckets/${bid}/collections/${cid}/records`,
diff --git a/test/components/signoff/SimpleReview/PerRecordDiffView_test.js b/test/components/signoff/SimpleReview/PerRecordDiffView_test.js
index 7d2f324a7..c5b075501 100644
--- a/test/components/signoff/SimpleReview/PerRecordDiffView_test.js
+++ b/test/components/signoff/SimpleReview/PerRecordDiffView_test.js
@@ -65,6 +65,19 @@ describe("findChangeTypes", () => {
]);
});
+ it("should find multiple removed items", () => {
+ expect(
+ findChangeTypes(
+ [{ id: "a" }, { id: "b" }, { id: "c" }, { id: "d" }],
+ [{ id: "a" }]
+ )
+ ).eql([
+ { id: "b", changeType: ChangeType.REMOVE, source: { id: "b" } },
+ { id: "c", changeType: ChangeType.REMOVE, source: { id: "c" } },
+ { id: "d", changeType: ChangeType.REMOVE, source: { id: "d" } },
+ ]);
+ });
+
it("should find updated items", () => {
expect(
findChangeTypes(
diff --git a/test/components/signoff/SimpleReview/SimpleReviewButtons_test.js b/test/components/signoff/SimpleReview/SimpleReviewButtons_test.js
index 36fa4e3de..3f6858749 100644
--- a/test/components/signoff/SimpleReview/SimpleReviewButtons_test.js
+++ b/test/components/signoff/SimpleReview/SimpleReviewButtons_test.js
@@ -1,15 +1,13 @@
-import { expect } from "chai";
-import { createComponent } from "../../../test_utils";
-import ReactDomTestUtils from "react-dom/test-utils";
-import sinon from "sinon";
+import { renderWithProvider } from "../../../test_utils";
+import { fireEvent } from "@testing-library/react";
import * as React from "react";
import SimpleReviewButtons from "../../../../src/components/signoff/SimpleReview/SimpleReviewButtons";
function renderButtons(props = null) {
- const approveChanges = sinon.stub();
- const declineChanges = sinon.stub();
- const rollbackChanges = sinon.stub();
+ const approveChanges = jest.fn();
+ const declineChanges = jest.fn();
+ const rollbackChanges = jest.fn();
const mergedProps = {
status: "to-review",
@@ -19,45 +17,45 @@ function renderButtons(props = null) {
...props,
};
- const node = createComponent();
+ const node = renderWithProvider();
return { approveChanges, declineChanges, rollbackChanges, node };
}
describe("SimpleReviewHeader component", () => {
- it("should call approveChanges when approve button is clicked", () => {
- const { approveChanges, node } = renderButtons({ status: "to-review" });
+ it("should call approveChanges when approve button is clicked", async () => {
+ const { approveChanges, node } = renderButtons({
+ status: "to-review",
+ canReview: true,
+ });
- ReactDomTestUtils.Simulate.click(node.querySelector(".btn-success"));
- expect(approveChanges.firstCall).to.be.ok;
+ fireEvent.click(node.getByText(/Approve/));
+ expect(approveChanges).toHaveBeenCalled();
+ expect(await node.findByTestId("spinner")).toBeDefined();
});
it("should open CommentDialog when reject is clicked call declineChanges from modal", async () => {
- const { declineChanges, node } = renderButtons({ status: "to-review" });
- ReactDomTestUtils.act(() => {
- ReactDomTestUtils.Simulate.click(node.querySelector(".btn-danger"));
- });
- expect(node.querySelector(".modal")).to.be.ok;
- ReactDomTestUtils.act(() => {
- ReactDomTestUtils.Simulate.click(
- node.querySelector(".modal .btn-primary")
- );
+ const { declineChanges, node } = renderButtons({
+ status: "to-review",
+ canReview: true,
});
- expect(declineChanges.firstCall).to.be.ok;
+ fireEvent.click(node.getByText(/Decline/));
+ fireEvent.click(await node.findByText("Reject changes"));
+ expect(declineChanges).toHaveBeenCalled();
+ expect(await node.findByTestId("spinner")).toBeDefined();
+ });
+
+ it("should open CommentDialog when request review is clicked and call requestReview from modal", async () => {
+ const {} = renderButtons({ status: "work-in-progress" });
});
it("should display rollback button when status is wip and call rollbackChanges from modal", async () => {
const { rollbackChanges, node } = renderButtons({
status: "work-in-progress",
+ canRequestReview: true,
});
- ReactDomTestUtils.act(() => {
- ReactDomTestUtils.Simulate.click(node.querySelector(".btn-danger"));
- });
- expect(node.querySelector(".modal")).to.be.ok;
- ReactDomTestUtils.act(() => {
- ReactDomTestUtils.Simulate.click(
- node.querySelector(".modal .btn-primary")
- );
- });
- expect(rollbackChanges.firstCall).to.be.ok;
+ fireEvent.click(node.getByText(/Rollback changes/));
+ fireEvent.click(await node.findByText("Rollback"));
+ expect(rollbackChanges).toHaveBeenCalled();
+ expect(await node.findByTestId("spinner")).toBeDefined();
});
});
diff --git a/test/components/signoff/SimpleReview/SimpleReviewHeader_test.js b/test/components/signoff/SimpleReview/SimpleReviewHeader_test.js
index 20077b18a..d0893932f 100644
--- a/test/components/signoff/SimpleReview/SimpleReviewHeader_test.js
+++ b/test/components/signoff/SimpleReview/SimpleReviewHeader_test.js
@@ -1,6 +1,4 @@
-import { expect } from "chai";
import { createComponent } from "../../../test_utils";
-
import SimpleReviewHeader from "../../../../src/components/signoff/SimpleReview/SimpleReviewHeader";
import * as React from "react";
@@ -22,24 +20,25 @@ const wipProps = {
describe("SimpleReviewHeader component", () => {
it("should render title when component is to-review", () => {
const node = createComponent();
- expect(node.querySelector(".card-header").textContent).to.equal(
+ expect(node.querySelector(".card-header").textContent).toBe(
"Review requested by ana:"
);
});
it("should render an editor comment when component is to-review", () => {
const node = createComponent();
- expect(node.querySelector(".card-text").textContent).to.equal(
- "please review"
- );
+ expect(node.querySelector(".card-text").textContent).toBe("please review");
});
- it("should render a wip header", () => {
- const node = createComponent();
- expect(node.querySelector(".card-header").textContent).to.equal(
+ it("should render a reviewer comments as expected when component is wip", () => {
+ const node = createComponent(
+
+ );
+ expect(node.querySelector(".card-text").textContent).toBe("no thanks");
+ expect(node.querySelector(".card-header").textContent).toBe(
"Status is work-in-progress. Most recent reviewer comment was:"
);
});
- it("should render a reviewer comment when component is wip", () => {
- const node = createComponent();
- expect(node.querySelector(".card-text").textContent).to.equal("no thanks");
- });
});
diff --git a/test/components/signoff/SimpleReview/SimpleReview_test.js b/test/components/signoff/SimpleReview/SimpleReview_test.js
index 7f71a60b1..97e94190d 100644
--- a/test/components/signoff/SimpleReview/SimpleReview_test.js
+++ b/test/components/signoff/SimpleReview/SimpleReview_test.js
@@ -1,6 +1,50 @@
import * as React from "react";
+import { fireEvent, waitForElementToBeRemoved } from "@testing-library/react";
import { renderWithProvider, sessionFactory } from "../../../test_utils";
import SimpleReview from "../../../../src/components/signoff/SimpleReview";
+import { useLocalStorage } from "../../../../src/hooks/storage";
+import { Redirect, useHistory } from "react-router-dom";
+
+jest.mock("../../../../src/hooks/storage", () => {
+ const originalModule = jest.requireActual("../../../../src/hooks/storage");
+ return {
+ __esModule: true,
+ ...originalModule,
+ useLocalStorage: jest.fn().mockReturnValue([true, jest.fn()]),
+ };
+});
+
+jest.mock("react-router-dom", () => {
+ const originalModule = jest.requireActual("react-router-dom");
+ const pushMock = jest.fn();
+ const useHistory = () => {
+ return {
+ push: pushMock,
+ };
+ };
+ return {
+ __esModule: true,
+ ...originalModule,
+ useHistory,
+ Redirect: jest.fn().mockReturnValue(foo
),
+ };
+});
+
+jest.mock("../../../../src/permission", () => {
+ return {
+ canEditCollection: () => {
+ return true;
+ },
+ };
+});
+
+jest.mock("../../../../src/components/signoff/utils", () => {
+ return {
+ isMember: () => {
+ return true;
+ },
+ };
+});
function signoffFactory() {
return {
@@ -14,7 +58,7 @@ function signoffFactory() {
lastEditDate: 1622816256864,
lastEditorComment: undefined,
lastReviewBy: undefined,
- lastReviewDate: NaN,
+ lastReviewDate: 1622816256865,
lastReviewRequestBy: undefined,
lastReviewRequestDate: NaN,
lastReviewerComment: undefined,
@@ -34,6 +78,10 @@ function signoffFactory() {
pendingConfirmReviewRequest: false,
pendingConfirmDeclineChanges: false,
pendingConfirmRollbackChanges: false,
+ capabilities: {},
+ collection: {
+ totalRecords: 3,
+ },
};
}
@@ -48,8 +96,11 @@ function renderSimpleReview(props = null) {
listRecords() {},
session: sessionFactory(),
signoff: signoffFactory(),
- async fetchRecords() {},
+ async fetchRecords() {
+ return [];
+ },
...props,
+ rollbackChanges: jest.fn(),
};
return renderWithProvider();
}
@@ -60,17 +111,6 @@ const fakeLocation = {
hash: "",
};
-jest.mock("react-router", () => {
- const originalModule = jest.requireActual("react-router");
- return {
- __esModule: true,
- ...originalModule,
- useLocation: () => {
- return fakeLocation;
- },
- };
-});
-
describe("SimpleTest component", () => {
it("should render spinner when authenticating", async () => {
const node = renderSimpleReview({
@@ -86,13 +126,6 @@ describe("SimpleTest component", () => {
expect(node.container.textContent).toBe("Not authenticated");
});
- it("should render not authenticated", async () => {
- const node = renderSimpleReview({
- session: sessionFactory({ authenticated: false, authenticating: false }),
- });
- expect(node.container.textContent).toBe("Not authenticated");
- });
-
it("should render not reviewable", async () => {
const node = renderSimpleReview({ signoff: undefined });
expect(node.container.textContent).toBe(
@@ -100,26 +133,35 @@ describe("SimpleTest component", () => {
);
});
- it("should render not a reviewer", async () => {
+ it("should render a diff form for not a reviewer", async () => {
const session = sessionFactory();
session.serverInfo.user.principals = [];
const node = renderSimpleReview({
session,
});
- expect(node.container.textContent).toMatch(
- /You do not have review permissions/
+ await waitForElementToBeRemoved(() => node.queryByTestId("spinner"));
+ expect(node.getByText(/Status is/).textContent).toBe(
+ "Status is work-in-progress. "
);
+ expect(node.getByText("(No comment was left by a reviewer)")).toBeDefined();
+ expect(node.getByText("Show all lines")).toBeDefined();
});
- it("should render a review component after records are fetched", async () => {
+ it("should render a review component after records are fetched and allow for a rollback", async () => {
let node = renderSimpleReview({
async fetchRecords() {
return [];
},
});
+ await waitForElementToBeRemoved(() => node.queryByTestId("spinner"));
expect(node.queryByText("Rollback")).toBeDefined();
expect(node.container.querySelector(".simple-review-header")).toBeDefined();
+
+ // also check rollback calls history.push while we're here
+ fireEvent.click(node.queryByText(/Rollback changes/));
+ fireEvent.click(node.queryByText("Rollback"));
+ expect(useHistory().push).toHaveBeenCalled();
});
it("should hide the rollback button if the hideRollback query parameter is provided", async () => {
@@ -129,8 +171,19 @@ describe("SimpleTest component", () => {
return [];
},
});
+ await waitForElementToBeRemoved(() => node.queryByTestId("spinner"));
expect(node.queryByText("Rollback")).toBeNull();
fakeLocation.search = "";
});
+
+ it("should redirect the user if the legacy review process is enabled", async () => {
+ useLocalStorage.mockReturnValue([false, jest.fn()]);
+ const session = sessionFactory();
+ session.serverInfo.user.principals = [];
+ renderSimpleReview({
+ session,
+ });
+ expect(Redirect).toHaveBeenCalled();
+ });
});
diff --git a/test/components/signoff/components_test.js b/test/components/signoff/components_test.js
index 0c9d5e2ad..ff8f120f7 100644
--- a/test/components/signoff/components_test.js
+++ b/test/components/signoff/components_test.js
@@ -2,6 +2,25 @@ import SignoffToolBar from "../../../src/components/signoff/SignoffToolBar";
import * as React from "react";
import { render, fireEvent } from "@testing-library/react";
+// to avoid rendering a router around everything, allows for more focused testing
+jest.mock("react-router-dom", () => {
+ const originalModule = jest.requireActual("react-router-dom");
+ return {
+ __esModule: true,
+ ...originalModule,
+ Link: "a",
+ };
+});
+
+jest.mock("../../../src/hooks/storage", () => {
+ const originalModule = jest.requireActual("../../../src/hooks/storage");
+ return {
+ __esModule: true,
+ ...originalModule,
+ useLocalStorage: jest.fn().mockReturnValue([false, jest.fn()]),
+ };
+});
+
describe("SignoffToolBar component", () => {
const props = {
sessionState: {
@@ -121,7 +140,7 @@ describe("SignoffToolBar component", () => {
expect(node.queryByTestId("spinner")).toBeNull();
expect(propsOverride.approveChanges).toHaveBeenCalledTimes(0);
fireEvent.click(await node.findByText("Approve"));
- expect(node.queryByTestId("spinner")).toBeDefined();
+ expect(await node.findByTestId("spinner")).toBeDefined();
expect(propsOverride.approveChanges).toHaveBeenCalledTimes(1);
});
});
diff --git a/test/hooks/storage_test.js b/test/hooks/storage_test.js
new file mode 100644
index 000000000..b814c86f7
--- /dev/null
+++ b/test/hooks/storage_test.js
@@ -0,0 +1,76 @@
+import { renderHook, act } from "@testing-library/react-hooks";
+import { useLocalStorage } from "../../src/hooks/storage";
+
+class localStorageClass {
+ isConstructor() {
+ this.store = {};
+ }
+
+ clear() {
+ this.store = {};
+ }
+
+ getItem(key) {
+ return this.store[key];
+ }
+
+ setItem(key, value) {
+ this.store[key] = String(value);
+ }
+
+ removeItem(key) {
+ delete this.store[key];
+ }
+}
+
+global.localStorage = new localStorageClass();
+
+describe("useLocalStorage", () => {
+ it("should return default value if a value isn't set yet", () => {
+ const { result } = renderHook(() =>
+ useLocalStorage("testKey", "defaultValue")
+ );
+
+ expect(result.current[0]).toBe("defaultValue");
+ });
+
+ it("should get an existing value from localStorage if one exists", () => {
+ localStorage.setItem("testKey", JSON.stringify("storedValue"));
+ const { result } = renderHook(() =>
+ useLocalStorage("testKey", "defaultValue")
+ );
+
+ expect(result.current[0]).toBe("storedValue");
+ });
+
+ it("should set a new value in localStorage", () => {
+ const { result } = renderHook(() =>
+ useLocalStorage("testKey", "defaultValue")
+ );
+
+ act(() => {
+ result.current[1]("newValue");
+ });
+
+ expect(result.current[0]).toBe("newValue");
+ expect(localStorage.getItem("testKey")).toBe(JSON.stringify("newValue"));
+ });
+
+ it("should update the value when localStorage changes from another session", () => {
+ const { result } = renderHook(() =>
+ useLocalStorage("testKey", "defaultValue")
+ );
+
+ act(() => {
+ localStorage.setItem("testKey", JSON.stringify("externalChange"));
+ const event = new StorageEvent("storage", {
+ oldValue: JSON.stringify("defaultValue"),
+ newValue: JSON.stringify("externalChange"),
+ key: "testKey",
+ });
+ window.dispatchEvent(event);
+ });
+
+ expect(result.current[0]).toBe("externalChange");
+ });
+});
diff --git a/test/permission_test.js b/test/permission_test.js
index 85a50d106..29513c09f 100644
--- a/test/permission_test.js
+++ b/test/permission_test.js
@@ -44,14 +44,12 @@ describe("canCreateBucket", () => {
describe("canEditBucket", () => {
it("should always return true if no permissions list", () => {
const session = { permissions: null };
- const bucket = {};
- expect(canEditBucket(session, bucket)).eql(true);
+ expect(canEditBucket(session, "")).eql(true);
});
it("should return false if object is not listed", () => {
const session = { permissions: [{ bucket_id: "xyz" }] };
- const bucket = { data: { id: "abc" } };
- expect(canEditBucket(session, bucket)).eql(false);
+ expect(canEditBucket(session, "abc")).eql(false);
});
it("should return false if permission is not listed", () => {
@@ -64,8 +62,7 @@ describe("canEditBucket", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
- expect(canEditBucket(session, bucket)).eql(false);
+ expect(canEditBucket(session, "xyz")).eql(false);
});
it("should return true if permission is listed", () => {
@@ -78,22 +75,19 @@ describe("canEditBucket", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
- expect(canEditBucket(session, bucket)).eql(true);
+ expect(canEditBucket(session, "xyz")).eql(true);
});
});
describe("canCreateCollection", () => {
it("should always return true if no permisssions list", () => {
const session = { permissions: null };
- const bucket = {};
- expect(canCreateCollection(session, bucket)).eql(true);
+ expect(canCreateCollection(session, "")).eql(true);
});
it("should return false if object is not listed", () => {
const session = { permissions: [{ bucket_id: "xyz" }] };
- const bucket = { data: { id: "abc" } };
- expect(canCreateCollection(session, bucket)).eql(false);
+ expect(canCreateCollection(session, "abc")).eql(false);
});
it("should return false if permission is not listed", () => {
@@ -106,8 +100,7 @@ describe("canCreateCollection", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
- expect(canCreateCollection(session, bucket)).eql(false);
+ expect(canCreateCollection(session, "xyz")).eql(false);
});
it("should return true if permission is listed", () => {
@@ -120,22 +113,19 @@ describe("canCreateCollection", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
- expect(canCreateCollection(session, bucket)).eql(true);
+ expect(canCreateCollection(session, "xyz")).eql(true);
});
});
describe("canCreateGroup", () => {
it("should always return true if no permisssions list", () => {
const session = { permissions: null };
- const bucket = {};
- expect(canCreateGroup(session, bucket)).eql(true);
+ expect(canCreateGroup(session, "")).eql(true);
});
it("should return false if object is not listed", () => {
const session = { permissions: [{ bucket_id: "xyz" }] };
- const bucket = { data: { id: "abc" } };
- expect(canCreateGroup(session, bucket)).eql(false);
+ expect(canCreateGroup(session, "abc")).eql(false);
});
it("should return false if permission is not listed", () => {
@@ -148,8 +138,7 @@ describe("canCreateGroup", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
- expect(canCreateGroup(session, bucket)).eql(false);
+ expect(canCreateGroup(session, "xyz")).eql(false);
});
it("should return true if permission is listed", () => {
@@ -162,26 +151,23 @@ describe("canCreateGroup", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
- expect(canCreateGroup(session, bucket)).eql(true);
+ expect(canCreateGroup(session, "xyz")).eql(true);
});
});
describe("canEditCollection", () => {
it("should always return true if no permisssions list", () => {
const session = { permissions: null };
- const bucket = {};
const collection = {};
- expect(canEditCollection(session, bucket, collection)).eql(true);
+ expect(canEditCollection(session, "", collection)).eql(true);
});
it("should return false if object is not listed", () => {
const session = {
permissions: [{ bucket_id: "abc", collection_id: "foo" }],
};
- const bucket = { data: { id: "abc" } };
const collection = { data: { id: "bar" } };
- expect(canEditCollection(session, bucket, collection)).eql(false);
+ expect(canEditCollection(session, "abc", collection)).eql(false);
});
it("should return false if permission is not listed", () => {
@@ -195,9 +181,8 @@ describe("canEditCollection", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
const collection = { data: { id: "foo" } };
- expect(canEditCollection(session, bucket, collection)).eql(false);
+ expect(canEditCollection(session, "xyz", collection)).eql(false);
});
it("should return true if permission is listed", () => {
@@ -211,9 +196,8 @@ describe("canEditCollection", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
const collection = { data: { id: "foo" } };
- expect(canEditCollection(session, bucket, collection)).eql(true);
+ expect(canEditCollection(session, "xyz", collection)).eql(true);
});
it("should return true if permission on bucket is listed", () => {
@@ -226,25 +210,22 @@ describe("canEditCollection", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
const collection = { data: { id: "foo" } };
- expect(canEditCollection(session, bucket, collection)).eql(true);
+ expect(canEditCollection(session, "xyz", collection)).eql(true);
});
});
describe("canEditGroup", () => {
it("should always return true if no permisssions list", () => {
const session = { permissions: null };
- const bucket = {};
const group = {};
- expect(canEditGroup(session, bucket, group)).eql(true);
+ expect(canEditGroup(session, "", group)).eql(true);
});
it("should return false if object is not listed", () => {
const session = { permissions: [{ bucket_id: "abc", group_id: "foo" }] };
- const bucket = { data: { id: "abc" } };
const group = { data: { id: "bar" } };
- expect(canEditGroup(session, bucket, group)).eql(false);
+ expect(canEditGroup(session, "abc", group)).eql(false);
});
it("should return false if permission is not listed", () => {
@@ -258,9 +239,8 @@ describe("canEditGroup", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
const group = { data: { id: "foo" } };
- expect(canEditGroup(session, bucket, group)).eql(false);
+ expect(canEditGroup(session, "xyz", group)).eql(false);
});
it("should return true if permission is listed", () => {
@@ -274,9 +254,8 @@ describe("canEditGroup", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
const group = { data: { id: "foo" } };
- expect(canEditGroup(session, bucket, group)).eql(true);
+ expect(canEditGroup(session, "xyz", group)).eql(true);
});
it("should return true if permission on bucket is listed", () => {
@@ -289,27 +268,24 @@ describe("canEditGroup", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
const group = { data: { id: "foo" } };
- expect(canEditGroup(session, bucket, group)).eql(true);
+ expect(canEditGroup(session, "xyz", group)).eql(true);
});
});
describe("canCreateRecord", () => {
it("should always return true if no permisssions list", () => {
const session = { permissions: null };
- const bucket = {};
const collection = {};
- expect(canCreateRecord(session, bucket, collection)).eql(true);
+ expect(canCreateRecord(session, "", collection)).eql(true);
});
it("should return false if object is not listed", () => {
const session = {
permissions: [{ bucket_id: "abc", collection_id: "foo" }],
};
- const bucket = { data: { id: "abc" } };
const collection = { data: { id: "bar" } };
- expect(canCreateRecord(session, bucket, collection)).eql(false);
+ expect(canCreateRecord(session, "abc", collection)).eql(false);
});
it("should return false if permission is not listed", () => {
@@ -323,9 +299,8 @@ describe("canCreateRecord", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
const collection = { data: { id: "foo" } };
- expect(canCreateRecord(session, bucket, collection)).eql(false);
+ expect(canCreateRecord(session, "xyz", collection)).eql(false);
});
it("should return true if permission is listed", () => {
@@ -339,9 +314,8 @@ describe("canCreateRecord", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
const collection = { data: { id: "foo" } };
- expect(canCreateRecord(session, bucket, collection)).eql(true);
+ expect(canCreateRecord(session, "xyz", collection)).eql(true);
});
it("should return true if permission on bucket is listed", () => {
@@ -354,19 +328,17 @@ describe("canCreateRecord", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
const collection = { data: { id: "foo" } };
- expect(canCreateRecord(session, bucket, collection)).eql(true);
+ expect(canCreateRecord(session, "xyz", collection)).eql(true);
});
});
describe("canEditRecord", () => {
it("should always return true if no permisssions list", () => {
const session = { permissions: null };
- const bucket = {};
const collection = {};
const record = {};
- expect(canEditRecord(session, bucket, collection, record)).eql(true);
+ expect(canEditRecord(session, "", collection, record)).eql(true);
});
it("should return false if object is not listed", () => {
@@ -379,10 +351,9 @@ describe("canEditRecord", () => {
},
],
};
- const bucket = { data: { id: "abc" } };
const collection = { data: { id: "bar" } };
const record = { data: { id: "blah" } };
- expect(canEditRecord(session, bucket, collection, record)).eql(false);
+ expect(canEditRecord(session, "abc", collection, record)).eql(false);
});
it("should return false if permission is not listed", () => {
@@ -397,10 +368,9 @@ describe("canEditRecord", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
const collection = { data: { id: "foo" } };
const record = { data: { id: "blah" } };
- expect(canEditRecord(session, bucket, collection, record)).eql(false);
+ expect(canEditRecord(session, "xyz", collection, record)).eql(false);
});
it("should return true if permission is listed", () => {
@@ -415,10 +385,9 @@ describe("canEditRecord", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
const collection = { data: { id: "foo" } };
const record = { data: { id: "blah" } };
- expect(canEditRecord(session, bucket, collection, record)).eql(true);
+ expect(canEditRecord(session, "xyz", collection, record)).eql(true);
});
it("should return true if permission on bucket is listed", () => {
@@ -431,10 +400,9 @@ describe("canEditRecord", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
const collection = { data: { id: "foo" } };
const record = { data: { id: "blah" } };
- expect(canEditRecord(session, bucket, collection, record)).eql(true);
+ expect(canEditRecord(session, "xyz", collection, record)).eql(true);
});
it("should return true if permission on collection is listed", () => {
@@ -448,10 +416,9 @@ describe("canEditRecord", () => {
},
],
};
- const bucket = { data: { id: "xyz" } };
const collection = { data: { id: "foo" } };
const record = { data: { id: "blah" } };
- expect(canEditRecord(session, bucket, collection, record)).eql(true);
+ expect(canEditRecord(session, "xyz", collection, record)).eql(true);
});
});