-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Call API to import a Google Classroom on "Import Section" click #16385
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
65d9243
Reload the sections table after a Google Classroom is imported
joshlory 3ba8eed
Merge branch 'staging' into import-google-classroom-next
joshlory 5d420e3
Call API to import a Google Classroom on "Import Section" click
joshlory 862bfe5
Remove join links and manage buttons for Google Classroom sections
joshlory 2674059
Add unit tests for the `googleClassroomRedux` store
joshlory 5a910d1
Code review feedback
joshlory File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import { PropTypes } from 'react'; | ||
import { SectionLoginType } from '@cdo/apps/util/sharedConstants'; | ||
|
||
export const sectionShape = PropTypes.shape({ | ||
id: PropTypes.number.isRequired, | ||
name: PropTypes.string.isRequired, | ||
// Though we validate valid login types here, the server actually owns the | ||
// canonical list, and passes us the list of valid login types. | ||
loginType: PropTypes.oneOf(['word', 'email', 'picture']).isRequired, | ||
loginType: PropTypes.oneOf(Object.keys(SectionLoginType)).isRequired, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
stageExtras: PropTypes.bool.isRequired, | ||
pairingAllowed: PropTypes.bool.isRequired, | ||
studentNames: PropTypes.arrayOf(PropTypes.string).isRequired, | ||
|
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 |
---|---|---|
|
@@ -18,7 +18,14 @@ export const setValidAssignments = (validCourses, validScripts) => ({ | |
validCourses, | ||
validScripts | ||
}); | ||
export const setSections = sections => ({ type: SET_SECTIONS, sections }); | ||
|
||
/** | ||
* Set the list of sections to display. If `reset` is true, first clear the | ||
* existing list. | ||
* @param sections | ||
* @param reset | ||
*/ | ||
export const setSections = (sections, reset = false) => ({ type: SET_SECTIONS, sections, reset }); | ||
export const updateSection = (sectionId, serverSection) => ({ | ||
type: UPDATE_SECTION, | ||
sectionId, | ||
|
@@ -114,9 +121,10 @@ export default function teacherSections(state=initialState, action) { | |
if (action.type === SET_SECTIONS) { | ||
const sections = action.sections.map(section => | ||
sectionFromServerSection(section)); | ||
const prevSectionIds = action.reset ? [] : state.sectionIds; | ||
return { | ||
...state, | ||
sectionIds: state.sectionIds.concat(sections.map(section => section.id)), | ||
sectionIds: prevSectionIds.concat(sections.map(section => section.id)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. might be good to get some test coverage of this reset behavior in teacherSectionsReduxTest.js |
||
sections: { | ||
...state.sections, | ||
..._.keyBy(sections, 'id') | ||
|
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
70 changes: 70 additions & 0 deletions
70
apps/test/unit/templates/teacherDashboard/googleClassroomReduxTest.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,70 @@ | ||
import { assert } from '../../../util/configuredChai'; | ||
import sinon from 'sinon'; | ||
import configureStore from 'redux-mock-store'; | ||
import thunk from 'redux-thunk'; | ||
|
||
import reducer, { | ||
loadClassroomList, | ||
setClassroomList, | ||
failedLoad, | ||
importClassroomStarted, | ||
} from '@cdo/apps/templates/teacherDashboard/googleClassroomRedux'; | ||
|
||
describe('googleClassroomRedux', () => { | ||
const initialState = reducer(undefined, {}); | ||
|
||
describe('loadClassroomList', () => { | ||
it('loads the classroom list from the API', finish => { | ||
const data = { | ||
courses: [{id: "6949959535", section: "123", name: "Sample class", enrollment_code: "gc12wb"}] | ||
}; | ||
|
||
const xhr = sinon.useFakeXMLHttpRequest(); | ||
xhr.onCreate = request => { | ||
setTimeout(() => { | ||
const mockResponse = JSON.stringify(data); | ||
request.respond(200, {'Content-Type': 'application/json'}, mockResponse); | ||
|
||
assert.deepEqual([setClassroomList(data.courses)], store.getActions()); | ||
finish(); | ||
}, 0); | ||
}; | ||
|
||
const mockStore = configureStore([thunk]); | ||
const store = mockStore({}); | ||
|
||
store.dispatch(loadClassroomList()); | ||
}); | ||
|
||
it('fails to load the classroom list from the API', finish => { | ||
const failureStatus = 403; | ||
const failureMessage = 'Sample error message'; | ||
|
||
const xhr = sinon.useFakeXMLHttpRequest(); | ||
xhr.onCreate = request => { | ||
setTimeout(() => { | ||
const mockResponse = JSON.stringify({error: failureMessage}); | ||
request.respond(failureStatus, {'Content-Type': 'application/json'}, mockResponse); | ||
|
||
assert.deepEqual([failedLoad(failureStatus, failureMessage)], store.getActions()); | ||
finish(); | ||
}, 0); | ||
}; | ||
|
||
const mockStore = configureStore([thunk]); | ||
const store = mockStore({}); | ||
|
||
store.dispatch(loadClassroomList()); | ||
}); | ||
}); | ||
|
||
describe('importClassroomStarted', () => { | ||
it('starting import sets the list of classrooms to null', () => { | ||
const state = reducer(initialState, setClassroomList(['fake classrooms'])); | ||
assert.deepEqual(state.classrooms, ['fake classrooms']); | ||
|
||
const nextState = reducer(state, importClassroomStarted()); | ||
assert.equal(nextState.classrooms, null); | ||
}); | ||
}); | ||
}); |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of these APIs set sectionsLoaded. If the call to /v2/sections finishes first, we end up with
sectionsLoaded = true
. Ifimport_google_classroom
finishes first, we end up withsectionsLoaded = false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure I follow. The JSON calls are nested, so the
/v2/sections
request won't start until after the first request resolves.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad. Didn't realize they were nested.