-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: verify learner email belongs to org (#1356)
- Loading branch information
1 parent
3bb7650
commit c9bd93f
Showing
12 changed files
with
198 additions
and
3 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
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
36 changes: 36 additions & 0 deletions
36
src/components/PeopleManagement/LearnerNotInOrgErrorState.jsx
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import React from 'react'; | ||
import { | ||
Card, Hyperlink, Stack, Icon, | ||
} from '@openedx/paragon'; | ||
import classNames from 'classnames'; | ||
import { Error } from '@openedx/paragon/icons'; | ||
|
||
const LearnerNotInOrgErrorState = () => ( | ||
<Stack gap={2.5} className="mb-4"> | ||
<Card | ||
className={classNames( | ||
'invite-modal-summary-card rounded-0 shadow-none', | ||
{ invalid: true }, | ||
)} | ||
> | ||
<Card.Section> | ||
<Stack direction="horizontal" gap={3}> | ||
<Icon className="text-danger" src={Error} /> | ||
<div> | ||
<div className="h4 mb-0">Some people can't be added.</div> | ||
<span className="small">Check that all people in the file are registered with your organization. | ||
<Hyperlink | ||
destination="https://www.edx.org" | ||
target="_blank" | ||
> | ||
Learn more | ||
</Hyperlink> | ||
</span> | ||
</div> | ||
</Stack> | ||
</Card.Section> | ||
</Card> | ||
</Stack> | ||
); | ||
|
||
export default LearnerNotInOrgErrorState; |
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 |
---|---|---|
|
@@ -17,6 +17,7 @@ import { | |
useEnterpriseLearnersTableData, | ||
useGetAllEnterpriseLearnerEmails, | ||
} from '../../learner-credit-management/data/hooks/useEnterpriseLearnersTableData'; | ||
import { useEnterpriseLearners } from '../../learner-credit-management/data'; | ||
|
||
jest.mock('@tanstack/react-query', () => ({ | ||
...jest.requireActual('@tanstack/react-query'), | ||
|
@@ -28,6 +29,10 @@ jest.mock('../../learner-credit-management/data/hooks/useEnterpriseLearnersTable | |
useEnterpriseLearnersTableData: jest.fn(), | ||
useGetAllEnterpriseLearnerEmails: jest.fn(), | ||
})); | ||
jest.mock('../../learner-credit-management/data', () => ({ | ||
...jest.requireActual('../../learner-credit-management/data'), | ||
useEnterpriseLearners: jest.fn(), | ||
})); | ||
|
||
const mockStore = configureMockStore([thunk]); | ||
const getMockStore = store => mockStore(store); | ||
|
@@ -118,6 +123,9 @@ describe('<CreateGroupModal />', () => { | |
fetchLearnerEmails: jest.fn(), | ||
addButtonState: 'complete', | ||
}); | ||
useEnterpriseLearners.mockReturnValue({ | ||
allEnterpriseLearners: ['[email protected]', '[email protected]', '[email protected]', '[email protected]'], | ||
}); | ||
}); | ||
it('Modal renders as expected', async () => { | ||
render(<CreateGroupModalWrapper />); | ||
|
@@ -204,6 +212,29 @@ describe('<CreateGroupModal />', () => { | |
expect(mockInvite).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
it('displays error for email not belonging in an org', async () => { | ||
const mockGroupData = { uuid: 'test-uuid' }; | ||
LmsApiService.createEnterpriseGroup.mockResolvedValue({ status: 201, data: mockGroupData }); | ||
|
||
const mockInviteData = { records_processed: 1, new_learners: 1, existing_learners: 0 }; | ||
LmsApiService.inviteEnterpriseLearnersToGroup.mockResolvedValue(mockInviteData); | ||
useEnterpriseLearners.mockReturnValue({ | ||
allEnterpriseLearners: ['[email protected]'], | ||
}); | ||
render(<CreateGroupModalWrapper />); | ||
const groupNameInput = screen.getByTestId('group-name'); | ||
userEvent.type(groupNameInput, 'test group name'); | ||
const fakeFile = new File(['[email protected]'], 'emails.csv', { type: 'text/csv' }); | ||
const dropzone = screen.getByText('Drag and drop your file here or click to upload.'); | ||
Object.defineProperty(dropzone, 'files', { | ||
value: [fakeFile], | ||
}); | ||
fireEvent.drop(dropzone); | ||
await waitFor(() => { | ||
expect(screen.getByText(/Some people can't be added/i)).toBeInTheDocument(); | ||
expect(/[email protected] email address is not available to be added to a group./i); | ||
}, { timeout: EMAIL_ADDRESSES_INPUT_VALUE_DEBOUNCE_DELAY + 1000 }); | ||
}); | ||
it('displays system error modal', async () => { | ||
const mockCreateGroup = jest.spyOn(LmsApiService, 'createEnterpriseGroup'); | ||
const mockInvite = jest.spyOn(LmsApiService, 'inviteEnterpriseLearnersToGroup'); | ||
|
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
48 changes: 48 additions & 0 deletions
48
src/components/learner-credit-management/data/hooks/tests/useEnterpriseLearners.test.jsx
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { QueryClientProvider } from '@tanstack/react-query'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
|
||
import { camelCaseObject } from '@edx/frontend-platform/utils'; | ||
import LmsApiService from '../../../../../data/services/LmsApiService'; | ||
import { queryClient } from '../../../../test/testUtils'; | ||
import useEnterpriseLearners from '../useEnterpriseLearners'; | ||
|
||
jest.mock('../../../../../data/services/LmsApiService', () => ({ | ||
fetchEnterpriseLearnerData: jest.fn(), | ||
})); | ||
|
||
jest.mock('@edx/frontend-platform/utils', () => ({ | ||
camelCaseObject: jest.fn(), | ||
})); | ||
|
||
const wrapper = ({ children }) => ( | ||
<QueryClientProvider client={queryClient()}>{children}</QueryClientProvider> | ||
); | ||
|
||
describe('useEnterpriseLearners', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should fetch and return enterprise learners', async () => { | ||
const mockData = [ | ||
{ | ||
user: { | ||
email: '[email protected]', | ||
}, | ||
}, | ||
]; | ||
LmsApiService.fetchEnterpriseLearnerData.mockResolvedValue(mockData); | ||
camelCaseObject.mockResolvedValue(mockData); | ||
|
||
const { result, waitForNextUpdate } = renderHook( | ||
() => useEnterpriseLearners({ enterpriseUUID: 'test-id' }), | ||
{ wrapper }, | ||
); | ||
await waitForNextUpdate(); | ||
expect(LmsApiService.fetchEnterpriseLearnerData).toHaveBeenCalledWith({ | ||
enterprise_customer: 'test-id', | ||
}); | ||
expect(camelCaseObject).toHaveBeenCalledWith(mockData); | ||
expect(result.current.allEnterpriseLearners).toEqual(['[email protected]']); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
src/components/learner-credit-management/data/hooks/useEnterpriseLearners.js
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { camelCaseObject } from '@edx/frontend-platform/utils'; | ||
import { logError } from '@edx/frontend-platform/logging'; | ||
|
||
import LmsApiService from '../../../../data/services/LmsApiService'; | ||
|
||
const useEnterpriseLearners = ({ | ||
enterpriseUUID, | ||
}) => { | ||
const [allEnterpriseLearners, setAllEnterpriseLearners] = useState([]); | ||
|
||
useEffect(() => { | ||
const fetchLearnerEmails = async () => { | ||
try { | ||
const options = { | ||
enterprise_customer: enterpriseUUID, | ||
}; | ||
const data = await LmsApiService.fetchEnterpriseLearnerData(options); | ||
const results = await camelCaseObject(data); | ||
const learnerEmails = results.map(result => result?.user?.email); | ||
setAllEnterpriseLearners(learnerEmails); | ||
} catch (error) { | ||
logError(error); | ||
} | ||
}; | ||
fetchLearnerEmails(); | ||
}, [enterpriseUUID]); | ||
|
||
return { | ||
allEnterpriseLearners, | ||
}; | ||
}; | ||
|
||
export default useEnterpriseLearners; |
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
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