-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3196 from OpenNeuroOrg/orcid-permissions
Allow sharing permissions by ORCID
- Loading branch information
Showing
11 changed files
with
295 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,6 +74,8 @@ export const PERMISSION_FRAGMENT = gql` | |
user { | ||
id | ||
orcid | ||
name | ||
} | ||
level | ||
} | ||
|
42 changes: 0 additions & 42 deletions
42
packages/openneuro-app/src/scripts/datalad/mutations/remove-permissions.jsx
This file was deleted.
Oops, something went wrong.
86 changes: 0 additions & 86 deletions
86
packages/openneuro-app/src/scripts/datalad/mutations/update-permissions.jsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,44 @@ | ||
import React from "react" | ||
import { render } from "@testing-library/react" | ||
import { fireEvent, render, screen, waitFor } from "@testing-library/react" | ||
import { MockedProvider } from "@apollo/client/testing" | ||
import { UpdateDatasetPermissions } from "../update-permissions" | ||
import { | ||
isValidOrcid, | ||
UPDATE_ORCID_PERMISSIONS, | ||
UPDATE_PERMISSIONS, | ||
UpdateDatasetPermissions, | ||
} from "../update-permissions" | ||
|
||
function permissionMocksFactory( | ||
updatePermissionsCalled, | ||
updateOrcidPermissionsCalled, | ||
) { | ||
return [ | ||
{ | ||
request: { | ||
query: UPDATE_PERMISSIONS, | ||
|
||
variables: { | ||
datasetId: "ds000005", | ||
userEmail: "[email protected]", | ||
level: "ro", | ||
}, | ||
}, | ||
newData: updatePermissionsCalled, | ||
}, | ||
{ | ||
request: { | ||
query: UPDATE_ORCID_PERMISSIONS, | ||
|
||
variables: { | ||
datasetId: "ds000005", | ||
userOrcid: "0000-0002-1694-233X", | ||
level: "ro", | ||
}, | ||
}, | ||
newData: updateOrcidPermissionsCalled, | ||
}, | ||
] | ||
} | ||
|
||
describe("UpdateDatasetPermissions mutation", () => { | ||
it("renders with default props", () => { | ||
|
@@ -12,17 +49,76 @@ describe("UpdateDatasetPermissions mutation", () => { | |
) | ||
expect(asFragment()).toMatchSnapshot() | ||
}) | ||
it("renders with typical props", () => { | ||
it("calls UPDATE_PERMISSIONS when clicked with an email address", async () => { | ||
const updatePermissionsCalled = vi.fn() | ||
const updateOrcidPermissionsCalled = vi.fn() | ||
const mocks = permissionMocksFactory( | ||
updatePermissionsCalled, | ||
updateOrcidPermissionsCalled, | ||
) | ||
const done = vi.fn() | ||
const { asFragment } = render( | ||
<MockedProvider> | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<UpdateDatasetPermissions | ||
datasetId="ds000005" | ||
userEmail="[email protected]" | ||
access="ro" | ||
done={vi.fn()} | ||
userIdentifier="[email protected]" | ||
metadata="ro" | ||
done={done} | ||
/> | ||
</MockedProvider>, | ||
) | ||
expect(asFragment()).toMatchSnapshot() | ||
const fragment = asFragment() | ||
expect(fragment).toMatchSnapshot() | ||
// Try clicking the button and make sure the right mutation runs | ||
const button = screen.getByRole("button") | ||
await fireEvent.click(button) | ||
// Make sure it ran at all | ||
await waitFor(() => expect(done).toHaveBeenCalled()) | ||
// Verify the expected query ran | ||
await waitFor(() => expect(updatePermissionsCalled).toHaveBeenCalled()) | ||
await waitFor(() => | ||
expect(updateOrcidPermissionsCalled).not.toHaveBeenCalled() | ||
) | ||
}) | ||
it("calls UPDATE_ORCID_PERMISSIONS when clicked with an ORCID", async () => { | ||
const updatePermissionsCalled = vi.fn() | ||
const updateOrcidPermissionsCalled = vi.fn() | ||
const mocks = permissionMocksFactory( | ||
updatePermissionsCalled, | ||
updateOrcidPermissionsCalled, | ||
) | ||
const done = vi.fn() | ||
const { asFragment } = render( | ||
<MockedProvider mocks={mocks} addTypename={false}> | ||
<UpdateDatasetPermissions | ||
datasetId="ds000005" | ||
userIdentifier="0000-0002-1694-233X" | ||
metadata="ro" | ||
done={done} | ||
/> | ||
</MockedProvider>, | ||
) | ||
const fragment = asFragment() | ||
expect(fragment).toMatchSnapshot() | ||
// Try clicking the button and make sure the right mutation runs | ||
const button = screen.getByRole("button") | ||
await fireEvent.click(button) | ||
// Make sure it ran at all | ||
await waitFor(() => expect(done).toHaveBeenCalled()) | ||
// Verify the expected query ran | ||
await waitFor(() => expect(updatePermissionsCalled).not.toHaveBeenCalled()) | ||
await waitFor(() => expect(updateOrcidPermissionsCalled).toHaveBeenCalled()) | ||
}) | ||
describe("isValidOrcid", () => { | ||
it("matches typical ORCID strings", () => { | ||
expect(isValidOrcid("0000-0001-2345-678")).toBe(false) | ||
expect(isValidOrcid("0000-0001-2345-678f")).toBe(false) | ||
expect(isValidOrcid("19818c4d-1e60-4480-a317-6fcc1c1a88c6")).toBe(false) | ||
expect(isValidOrcid("0000000123456789")).toBe(false) | ||
// Check for a correct value | ||
expect(isValidOrcid("0000-0001-2345-6789")).toBe(true) | ||
// Test with the X checksum value | ||
expect(isValidOrcid("0000-0002-1694-233X")).toBe(true) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.