refine icon indicating copy to clipboard operation
refine copied to clipboard

feat(core): ability to pass an argument to usePermissions

Open Cavdy opened this issue 1 year ago • 5 comments

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

Cavdy avatar Feb 07 '24 10:02 Cavdy

🦋 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

changeset-bot[bot] avatar Feb 07 '24 10:02 changeset-bot[bot]

@BatuhanW test case written but not sure if I got it right

Cavdy avatar Feb 07 '24 11:02 Cavdy

@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.

alicanerdurmaz avatar Feb 07 '24 14:02 alicanerdurmaz

Thanks for the suggestion @alicanerdurmaz

I have updated the test

Cavdy avatar Feb 07 '24 15:02 Cavdy

☁️ 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

Sent with 💌 from NxCloud.

nx-cloud[bot] avatar Feb 08 '24 14:02 nx-cloud[bot]

@BatuhanW done the changes... Thanks for the feedback

Cavdy avatar Feb 29 '24 20:02 Cavdy