Skip to content

adding unit test to forOwnerOnly #794#795

Merged
vnugent merged 3 commits into
developfrom
forOwnerOnly/#794
Apr 25, 2023
Merged

adding unit test to forOwnerOnly #794#795
vnugent merged 3 commits into
developfrom
forOwnerOnly/#794

Conversation

@clintonlunn

@clintonlunn clintonlunn commented Apr 23, 2023

Copy link
Copy Markdown
Collaborator

This pull request adds unit tests for the forOwnerOnly higher order function, which is used to restrict access to certain components or functions to a specific owner. The tests verify that the function behaves as expected and that it correctly restricts access to components based on if isAuthorized returns true from the mocked usePermission hook.

@vercel

vercel Bot commented Apr 23, 2023

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
open-tacos ✅ Ready (Inspect) Visit Preview Apr 23, 2023 9:56pm

@clintonlunn clintonlunn linked an issue Apr 23, 2023 that may be closed by this pull request
@clintonlunn clintonlunn temporarily deployed to Preview April 23, 2023 21:52 — with GitHub Actions Inactive
@clintonlunn clintonlunn temporarily deployed to Preview April 23, 2023 21:53 — with GitHub Actions Inactive
@clintonlunn clintonlunn requested a review from vnugent April 24, 2023 14:19
@vnugent vnugent merged commit dd34618 into develop Apr 25, 2023
@vnugent vnugent deleted the forOwnerOnly/#794 branch April 25, 2023 08:13
authProviderId: 'auth0|123456789012345678901234'
}
// Create a mock component to be used with forOwnerOnly
const MockComponent: React.FC<WithOwnerProfile> = () => <div>Mock Component</div>

@MichaelDimmitt MichaelDimmitt Apr 25, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consider:
const MockComponent = (unusedProps: WithOwnerProfile) => <div>Mock Component</div>

})

it('should render the component if isAuthorized is true', async () => {
(usePermissions as jest.Mock).mockReturnValue({ isAuthorized: true })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// jest.Mock(usePermission)
not sure the actual constructor here so pseudocode above. the pseudocode would in theory should have the correct prototype, previously you are just adding the type which does nothing. The only reason it is working is because of some jest global environment magic.

actuallyyun pushed a commit that referenced this pull request May 7, 2023
* adding unit test to forOwnerOnly #794

* add description for Fn type that accepts generic param P

* delete empty line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit tests for forOwnerOnly higher order function

3 participants