refine
refine copied to clipboard
feat(core): ability to pass an argument to usePermissions
PR Checklist
Please check if your PR fulfills the following requirements:
- [ ] The commit message follows our guidelines: https://refine.dev/docs/guides-concepts/contributing/#commit-convention
Bugs / Features
- [ ] Related issue(s) linked
- [ ] Tests for the changes have been added
- [ ] Docs have been added / updated
- [ ] Changesets have been added https://refine.dev/docs/guides-concepts/contributing/#creating-a-changeset
What is the current behavior?
What is the new behavior?
added ability to pass an argument to usePermissions.
fixes #5607
Notes for reviewers
🦋 Changeset detected
Latest commit: d3e0daa0181e3d50d7a1f8e6d442cc64736316cf
The changes in this PR will be included in the next version bump.
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
@BatuhanW test case written but not sure if I got it right
@BatuhanW test case written but not sure if I got it right
Hello @Cavdy, It looks neat 🚀 But, I have some suggestions:
In the following code, I mocked the getPermissions function to assert that it is called with "params"
it("should accept params", async () => {
const mockGetPermissions = jest.fn(() => Promise.resolve(["admin"]));
const { result } = renderHook(
({ params }: { params: string }) => usePermissions({ params }),
{
initialProps: { params: "admin" },
wrapper: TestWrapper({
authProvider: {
login: () => Promise.resolve({ success: true }),
check: () => Promise.resolve({ authenticated: true }),
onError: () => Promise.resolve({}),
logout: () => Promise.resolve({ success: true }),
getPermissions: mockGetPermissions,
},
dataProvider: MockJSONServer,
resources: [{ name: "posts" }],
}),
},
);
await waitFor(() => {
expect(result.current.isSuccess).toBeTruthy();
});
expect(mockGetPermissions).toHaveBeenCalledWith("admin");
expect(result.current.data).toEqual(["admin"]);
});
Also, I believe we need to test with { v3LegacyAuthProviderCompatible: true } prop.
I think the assertions will remain the same but in this case we will pass extra prop.
Thanks for the suggestion @alicanerdurmaz
I have updated the test
☁️ Nx Cloud Report
CI is running/has finished running commands for commit d3e0daa0181e3d50d7a1f8e6d442cc64736316cf. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.
📂 See all runs for this CI Pipeline Execution
✅ Successfully ran 24 targets
lerna run cypress:run --scope with-remix-material-ui -- --record --key --group with-remix-material-uilerna run cypress:run --scope with-remix-headless -- --record --key --group with-remix-headlesslerna run cypress:run --scope with-remix-antd -- --record --key --group with-remix-antdlerna run cypress:run --scope with-nextjs-next-auth -- --record --key --group with-nextjs-next-authlerna run cypress:run --scope with-nextjs -- --record --key --group with-nextjslerna run cypress:run --scope table-react-table-basic -- --record --key --group table-react-table-basiclerna run cypress:run --scope table-react-table-advanced -- --record --key --group table-react-table-advancedlerna run cypress:run --scope table-material-ui-use-update-many -- --record --key --group table-material-ui-use-update-manylerna run cypress:run --scope table-material-ui-use-delete-many -- --record --key --group table-material-ui-use-delete-manylerna run cypress:run --scope table-material-ui-use-data-grid -- --record --key --group table-material-ui-use-data-gridlerna run cypress:run --scope table-material-ui-table-filter -- --record --key --group table-material-ui-table-filterlerna run cypress:run --scope table-material-ui-data-grid-pro -- --record --key --group table-material-ui-data-grid-prolerna run cypress:run --scope table-material-ui-cursor-pagination -- --record --key --group table-material-ui-cursor-paginationlerna run cypress:run --scope table-material-ui-advanced -- --record --key --group table-material-ui-advancedlerna run cypress:run --scope table-mantine-basic -- --record --key --group table-mantine-basiclerna run cypress:run --scope table-mantine-advanced -- --record --key --group table-mantine-advancedlerna run cypress:run --scope table-handson -- --record --key --group table-handsonlerna run cypress:run --scope table-chakra-ui-basic -- --record --key --group table-chakra-ui-basiclerna run cypress:run --scope table-chakra-ui-advanced -- --record --key --group table-chakra-ui-advancedlerna run cypress:run --scope table-antd-use-update-many -- --record --key --group table-antd-use-update-manylerna run cypress:run --scope table-antd-use-table -- --record --key --group table-antd-use-tablelerna run cypress:run --scope table-antd-use-editable-table -- --record --key --group table-antd-use-editable-tablelerna run cypress:run --scope table-antd-use-delete-many -- --record --key --group table-antd-use-delete-manylerna run cypress:run --scope table-antd-table-filter -- --record --key --group table-antd-table-filter
Sent with 💌 from NxCloud.
@BatuhanW done the changes... Thanks for the feedback