Skip to content

Commit

Permalink
fix: add excludedCourseRoles to bulk-grades fetch (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
muselesscreator authored Aug 4, 2021
1 parent f5d2a34 commit e8a8cca
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/data/constants/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const filters = StrictDict({
courseGrade: 'courseGrade',
courseGradeMax: 'courseGradeMax',
courseGradeMin: 'courseGradeMin',
excludedCourseRoles: 'excludedCourseRoles',
includeCourseRoleMembers: 'includeCourseRoleMembers',
track: 'track',
});
Expand Down
11 changes: 11 additions & 0 deletions src/data/selectors/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ export const selectedAssignmentId = (state) => (simpleSelectors.assignment(state
*/
export const selectedAssignmentLabel = (state) => (simpleSelectors.assignment(state) || {}).label;

/**
* Returns the api value for excludedCourseRoles based on the
* internal Bool value for includeCourseRoleMembers.
* @param {object} state - redux state
* @return {string} - '' if to be included, else 'all'
*/
export const excludedCourseRoles = (state) => (
simpleSelectors.includeCourseRoleMembers(state) ? '' : 'all'
);

export default StrictDict({
...simpleSelectors,
isDefault,
Expand All @@ -143,5 +153,6 @@ export default StrictDict({
allFilters,
areAssignmentGradeFiltersSet,
chooseRelevantAssignmentData,
excludedCourseRoles,
getAssignmentsFromResultsSubstate,
});
9 changes: 9 additions & 0 deletions src/data/selectors/filters.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ describe('filters selectors', () => {
});
});

describe('excludedCourseRoles', () => {
it('returns empty string if includeCourseRoleMembers', () => {
expect(selectors.excludedCourseRoles({ filters: { includeCourseRoleMembers: true } })).toEqual('');
});
it('returns "all" string if not includeCourseRoleMembers', () => {
expect(selectors.excludedCourseRoles({ filters: { includeCourseRoleMembers: false } })).toEqual('all');
});
});

describe('selectedAssignmentId', () => {
it('gets filtered assignment ID when available', () => {
const assignmentId = selectors.selectedAssignmentId(testState);
Expand Down
10 changes: 3 additions & 7 deletions src/data/selectors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,7 @@ export const getHeadings = (state) => grades.headingMapper(
* @return {string} - generated grade export url
*/
export const gradeExportUrl = (state) => (
lms.urls.gradeCsvUrl({
...module.lmsApiServiceArgs(state),
excludeCourseRoles: filters.includeCourseRoleMembers(state) ? '' : 'all',
})
lms.urls.gradeCsvUrl(module.lmsApiServiceArgs(state))
);

/**
Expand All @@ -140,9 +137,7 @@ export const gradeExportUrl = (state) => (
* @return {string} - generated intervention export url
*/
export const interventionExportUrl = (state) => (
lms.urls.interventionExportCsvUrl(
module.lmsApiServiceArgs(state),
)
lms.urls.interventionExportCsvUrl(module.lmsApiServiceArgs(state))
);

/**
Expand All @@ -166,6 +161,7 @@ export const lmsApiServiceArgs = (state) => ({
),
courseGradeMin: grades.formatMinCourseGrade(filters.courseGradeMin(state)),
courseGradeMax: grades.formatMaxCourseGrade(filters.courseGradeMax(state)),
excludedCourseRoles: filters.excludedCourseRoles(state),
});

/**
Expand Down
25 changes: 7 additions & 18 deletions src/data/selectors/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,24 +339,11 @@ describe('root selectors', () => {
afterEach(() => {
moduleSelectors.lmsApiServiceArgs = lmsApiServiceArgs;
});
describe('without includeCourseRoleMembers filter', () => {
it('calls the API service with the right args, excluding all course roles', () => {
selectors.filters.includeCourseRoleMembers.mockReturnValue(undefined);
expect(selector(testState)).toEqual({
gradeCsvUrl: {
args: [{ lmsArgs: testState, excludeCourseRoles: 'all' }],
},
});
});
});
describe('with includeCourseRoleMembers filter', () => {
it('calls the API service with the right args, including course roles', () => {
selectors.filters.includeCourseRoleMembers.mockReturnValue(true);
expect(selector(testState)).toEqual({
gradeCsvUrl: {
args: [{ lmsArgs: testState, excludeCourseRoles: '' }],
},
});
it('calls the API service with the right args', () => {
expect(selector(testState)).toEqual({
gradeCsvUrl: {
args: [{ lmsArgs: testState }],
},
});
});
});
Expand Down Expand Up @@ -386,6 +373,7 @@ describe('root selectors', () => {
selectors.filters.assignmentGradeMin = mockFn('assignmentGradeMin');
selectors.filters.courseGradeMax = mockFn('courseGradeMax');
selectors.filters.courseGradeMin = mockFn('courseGradeMin');
selectors.filters.excludedCourseRoles = mockFn('excludedCourseRoles');
selectors.grades.formatMaxAssignmentGrade = mockMetaFn('formatMaxAssignmentGrade');
selectors.grades.formatMinAssignmentGrade = mockMetaFn('formatMinAssignmentGrade');
selectors.grades.formatMinCourseGrade = mockFn('formatMinCourseGrade');
Expand All @@ -412,6 +400,7 @@ describe('root selectors', () => {
courseGradeMax: {
formatMaxCourseGrade: { courseGradeMax: testState },
},
excludedCourseRoles: { excludedCourseRoles: testState },
});
});
});
Expand Down

0 comments on commit e8a8cca

Please sign in to comment.