Fix: get files by path depth (#2993)

* fix: get files up to depth specified by colletion path

* test(e2e): update mock data

* chore: fix comment
This commit is contained in:
Erez Rokah
2019-12-22 15:20:42 +02:00
committed by GitHub
parent 982fd7b0f8
commit b27748b54f
75 changed files with 4075 additions and 3714 deletions

View File

@ -1,5 +1,6 @@
import { parseLinkHeader, getAllResponses } from '../backendUtil';
import { parseLinkHeader, getAllResponses, getCollectionDepth } from '../backendUtil';
import { oneLine } from 'common-tags';
import { Map } from 'immutable';
import nock from 'nock';
describe('parseLinkHeader', () => {
@ -69,3 +70,13 @@ describe('getAllResponses', () => {
expect(pages[2]).toHaveLength(10);
});
});
describe('getCollectionDepth', () => {
it('should return 1 for collection with no path', () => {
expect(getCollectionDepth(Map({}))).toBe(1);
});
it('should return 2 for collection with path of one nested folder', () => {
expect(getCollectionDepth(Map({ path: '{{year}}/{{slug}}' }))).toBe(2);
});
});

View File

@ -77,3 +77,8 @@ export const getAllResponses = async (url, options = {}, linkHeaderRelName = 'ne
return pageResponses;
};
export const getCollectionDepth = collection => {
const depth = collection.get('path', '').split('/').length;
return depth;
};

View File

@ -18,6 +18,7 @@ import {
parseLinkHeader,
parseResponse,
responseParser,
getCollectionDepth,
} from './backendUtil';
import loadScript from './loadScript';
import getBlobSHA from './getBlobSHA';
@ -46,6 +47,7 @@ export const NetlifyCmsLibUtil = {
responseParser,
loadScript,
getBlobSHA,
getCollectionDepth,
};
export {
APIError,
@ -73,4 +75,5 @@ export {
getBlobSHA,
asyncLock,
isAbsolutePath,
getCollectionDepth,
};