Skip to content

Commit

Permalink
SWC-6776 - Reorder tests since handler is not resetting
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgros committed Sep 23, 2024
1 parent 01bf25c commit 65e6a4f
Showing 1 changed file with 51 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -518,58 +518,6 @@ describe('EntityAclEditor', () => {
).toBeInTheDocument()
})

it('displays an error on mutate failure', async () => {
const errorReason = 'Something was invalid'
server.use(
rest.put(
`${getEndpoint(BackendDestinationEnum.REPO_ENDPOINT)}${ENTITY_ID(
':entityId',
)}/acl`,
async (req, res, ctx) => {
const status = 400
let response: SynapseApiResponse<AccessControlList> = {
reason: errorReason,
}

return res(ctx.status(status), ctx.json(response))
},
),
)

const { ref, user } = await setUp(
{
entityId: mockFileEntityWithLocalSharingSettingsData.id,
onCanSaveChange,
onUpdateSuccess,
},
mockFileEntityWithLocalSharingSettingsData.bundle!.benefactorAcl
.resourceAccess.length,
)

// Enable sending a message, so we can verify that it is not sent when the update fails
await checkNotifyUsers(user)

// Add a user to the ACL
const newUserRow = await addUserToAcl(user, MOCK_USER_NAME_2)
confirmItem(newUserRow, MOCK_USER_NAME_2, 'Can download')

await waitFor(() => expect(onCanSaveChange).toHaveBeenLastCalledWith(true))

act(() => {
ref.current!.save()
})

const alert = await screen.findByRole('alert')
within(alert).getByText(errorReason)

await waitFor(() => {
expect(updateAclSpy).toHaveBeenCalled()
// Verify callback and sendMessage were not called
expect(onUpdateSuccess).not.toHaveBeenCalled()
expect(sendMessageSpy).not.toHaveBeenCalled()
})
})

it('current user cannot remove themselves', async () => {
const { itemRows } = await setUp(
{
Expand Down Expand Up @@ -679,4 +627,55 @@ describe('EntityAclEditor', () => {
expect(sendMessageSpy).not.toHaveBeenCalled()
})
})
it('displays an error on mutate failure', async () => {
const errorReason = 'Something was invalid'
server.use(
rest.put(
`${getEndpoint(BackendDestinationEnum.REPO_ENDPOINT)}${ENTITY_ID(
':entityId',
)}/acl`,
async (req, res, ctx) => {
const status = 400
let response: SynapseApiResponse<AccessControlList> = {
reason: errorReason,
}

return res(ctx.status(status), ctx.json(response))
},
),
)

const { ref, user } = await setUp(
{
entityId: mockFileEntityWithLocalSharingSettingsData.id,
onCanSaveChange,
onUpdateSuccess,
},
mockFileEntityWithLocalSharingSettingsData.bundle!.benefactorAcl
.resourceAccess.length,
)

// Enable sending a message, so we can verify that it is not sent when the update fails
await checkNotifyUsers(user)

// Add a user to the ACL
const newUserRow = await addUserToAcl(user, MOCK_USER_NAME_2)
confirmItem(newUserRow, MOCK_USER_NAME_2, 'Can download')

await waitFor(() => expect(onCanSaveChange).toHaveBeenLastCalledWith(true))

act(() => {
ref.current!.save()
})

const alert = await screen.findByRole('alert')
within(alert).getByText(errorReason)

await waitFor(() => {
expect(updateAclSpy).toHaveBeenCalled()
// Verify callback and sendMessage were not called
expect(onUpdateSuccess).not.toHaveBeenCalled()
expect(sendMessageSpy).not.toHaveBeenCalled()
})
})
})

0 comments on commit 65e6a4f

Please sign in to comment.