Handle no "link" header in todo response
The code handling the ToDoSidebar query for /planner/items didn't account for no "link" header in the response. fixes ADMIN-710 test plan: - have some upcoming things in the todo list - enable planner - load Card dashboard > expect all your todos to be in the sidebar Change-Id: Ib3f3869762b952f4a68a2bd4de9d6d77e15cf225 Reviewed-on: https://gerrit.instructure.com/140152 Tested-by: Jenkins Reviewed-by: Jon Willesen <jonw+gerrit@instructure.com> QA-Review: Mysti Sadler <mysti@instructure.com> Product-Review: Mysti Sadler <mysti@instructure.com>
This commit is contained in:
parent
4497399bda
commit
12109f1362
|
@ -45,8 +45,9 @@ export const loadNextItems = () => (
|
|||
axios.get(getState().nextUrl, { params: {
|
||||
order: 'asc'
|
||||
}}).then((response) => {
|
||||
if (parseLinkHeader(response.headers.link).next) {
|
||||
dispatch(itemsLoaded({ items: response.data, nextUrl: parseLinkHeader(response.headers.link).next.url }));
|
||||
const linkHeader = parseLinkHeader(response.headers.link)
|
||||
if (linkHeader && linkHeader.next) {
|
||||
dispatch(itemsLoaded({ items: response.data, nextUrl: linkHeader.next.url }));
|
||||
dispatch(loadNextItems());
|
||||
} else {
|
||||
dispatch(allItemsLoaded())
|
||||
|
@ -67,8 +68,9 @@ export const loadInitialItems = currentMoment => (
|
|||
end_date: lastMomentDate.format(),
|
||||
order: 'asc'
|
||||
}}).then((response) => {
|
||||
if (parseLinkHeader(response.headers.link).next) {
|
||||
dispatch(itemsLoaded({ items: response.data, nextUrl: parseLinkHeader(response.headers.link).next.url }));
|
||||
const linkHeader = parseLinkHeader(response.headers.link)
|
||||
if (linkHeader && linkHeader.next) {
|
||||
dispatch(itemsLoaded({ items: response.data, nextUrl: linkHeader.next.url }));
|
||||
dispatch(loadNextItems());
|
||||
} else {
|
||||
dispatch(itemsLoaded({ items: response.data, nextUrl: null }));
|
||||
|
|
|
@ -87,6 +87,29 @@ test('dispatches ITEMS_LOADED with the proper url on success', (assert) => {
|
|||
});
|
||||
});
|
||||
|
||||
test('dispatches ITEMS_LOADED when initial load gets them all', (assert) => {
|
||||
const done = assert.async();
|
||||
const thunk = Actions.loadInitialItems(moment().startOf('day'));
|
||||
const fakeDispatch = sinon.spy();
|
||||
thunk(fakeDispatch);
|
||||
moxios.wait(() => {
|
||||
const request = moxios.requests.mostRecent();
|
||||
request.respondWith({
|
||||
status: 200,
|
||||
headers: {
|
||||
},
|
||||
response: [{ id: 1 }, { id: 2 }]
|
||||
}).then(() => {
|
||||
const expected = {
|
||||
type: 'ITEMS_LOADED',
|
||||
payload: { items: [{ id: 1 }, { id: 2 }], nextUrl: null }
|
||||
};
|
||||
deepEqual(fakeDispatch.secondCall.args[0], expected);
|
||||
done();
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
test('dispatches ITEMS_LOADING_FAILED on failure', (assert) => {
|
||||
const done = assert.async();
|
||||
|
|
Loading…
Reference in New Issue