From b6dfa759fdc3c68bd169e2d805df14e1e0fa4c5c Mon Sep 17 00:00:00 2001 From: Tamlyn Rhodes <tamlyn@tamlyn.org> Date: Wed, 1 Nov 2017 16:19:08 +0000 Subject: [PATCH] Update fragment actions for top level fragment API Allow passing a falsy value as the collection and construct the appropriate URL --- src/actions/fragments.js | 19 +++++-------------- test/actions/fragments.test.js | 3 ++- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/actions/fragments.js b/src/actions/fragments.js index d3644df57..0f9197be1 100644 --- a/src/actions/fragments.js +++ b/src/actions/fragments.js @@ -2,19 +2,10 @@ import * as api from '../helpers/api' import * as T from './types' export const fragmentUrl = (collection, fragment) => { - let url = `/collections/${collection.id}/fragments` - - if (fragment.id) url += `/${fragment.id}` - - return url -} - -export const collectionUrl = (collection, suffix) => { - let url = '/collections' - - if (collection) url += `/${collection.id}` - - if (suffix) url += `/${suffix}` + let url = '' + if (collection) url += `/collections/${collection.id}` + url += '/fragments' + if (fragment && fragment.id) url += `/${fragment.id}` return url } @@ -46,7 +37,7 @@ export function getFragments(collection, options) { return dispatch => { dispatch(getFragmentsRequest(collection)) - let url = collectionUrl(collection, 'fragments') + let url = fragmentUrl(collection) if (options && options.fields) { url += '?fields=' + encodeURIComponent(options.fields.join(',')) diff --git a/test/actions/fragments.test.js b/test/actions/fragments.test.js index e083c2ae7..97c50fb91 100644 --- a/test/actions/fragments.test.js +++ b/test/actions/fragments.test.js @@ -36,7 +36,8 @@ describe('fragments actions', () => { }) describeAction('createFragment', { - firstarg: mockcol, + // no collection routes to top level fragment endpoint + firstarg: null, secondarg: { title: 'mock fragment', type: 'some_fragment', -- GitLab