Skip to content

Commit

Permalink
Merge d7e32ed into fb7d022
Browse files Browse the repository at this point in the history
  • Loading branch information
iFlameing committed Jul 20, 2019
2 parents fb7d022 + d7e32ed commit b3c8f38
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 18 deletions.
116 changes: 116 additions & 0 deletions src/__tests__/gatsby-node.tests.js
Expand Up @@ -3,6 +3,7 @@ import {
createContentDigest,
makeNavigationNode,
makeBreadcrumbsNode,
fetchPloneNavigationNode,
} from '../utils';

// This import is here only to make gatsby-node to appear in overall coverage
Expand Down Expand Up @@ -334,6 +335,111 @@ const expectedBreadcrumbsNode = {
},
};

const idFetchPloneNavigation =
'http://localhost:8080/Plone/this-is-upperfolder';
const baseUrlNavigation = 'http://localhost:8080/Plone';
const fetchPloneNode = {
items: [
{
description: '',
title: 'Home',
_path: '/',
_id: 'http://localhost:8080/Plone',
},
{
description: '',
title: 'gatsby-source-plone',
_path: '/index/',
_id: 'http://localhost:8080/Plone/index',
},
{
description: 'News on gatsby-source-plone development',
title: 'News',
_path: '/news/',
_id: 'http://localhost:8080/Plone/news',
},
{
description:
'A folder with different standard content types that Plone supports out of the box',
title: 'Examples',
_path: '/examples/',
_id: 'http://localhost:8080/Plone/examples',
},
{
description: '',
title: 'Tutorial',
_path: '/tutorial/',
_id: 'http://localhost:8080/Plone/tutorial',
},
{
description: 'Reference documentation',
title: 'Docs',
_path: '/reference/',
_id: 'http://localhost:8080/Plone/reference',
},
{
description: 'UpperFolder',
title: 'This is upperFolder',
_path: '/this-is-upperfolder/',
_id: 'http://localhost:8080/Plone/this-is-upperfolder',
},
],
_path: '/this-is-upperfolder/',
_id: 'http://localhost:8080/Plone/this-is-upperfolder/@navigation',
id: 'http://localhost:8080/Plone/this-is-upperfolder/@navigation',
internal: {
contentDigest: '641ddc1e243fc5a8d38ac14ad28be690',
mediaType: 'application/json',
type: 'PloneNavigation',
},
};

const mockDataNavigation = {
'@id': 'http://localhost:8080/Plone/this-is-upperfolder/@navigation',
items: [
{ '@id': 'http://localhost:8080/Plone', description: '', title: 'Home' },
{
'@id': 'http://localhost:8080/Plone/index',
description: '',
title: 'gatsby-source-plone',
},
{
'@id': 'http://localhost:8080/Plone/news',
description: 'News on gatsby-source-plone development',
title: 'News',
},
{
'@id': 'http://localhost:8080/Plone/examples',
description:
'A folder with different standard content types that Plone supports out of the box',
title: 'Examples',
},
{
'@id': 'http://localhost:8080/Plone/tutorial',
description: '',
title: 'Tutorial',
},
{
'@id': 'http://localhost:8080/Plone/reference',
description: 'Reference documentation',
title: 'Docs',
},
{
'@id': 'http://localhost:8080/Plone/this-is-upperfolder',
description: 'UpperFolder',
title: 'This is upperFolder',
},
],
};

const mockfetchPloneget = {
get: async (url, headers, params) => {
return {
data: mockDataNavigation,
};
},
};

test('makeContentNode returns Gatsby Node', () => {
expect(makeContentNode(mockid, mockdata, mockbaseUrl, mockbacklinks)).toEqual(
expectednode
Expand All @@ -351,3 +457,13 @@ test('makeBreadcrumbsNode returns Gatsby Node for Breadcrumbs', () => {
makeBreadcrumbsNode(idBreadcrumbs, dataBreadcrumbs, pathBreadcrumbs)
).toEqual(expectedBreadcrumbsNode);
});

test('fetchPloneNavigation returns Gatsby Node for Navigation', async () => {
const data = await fetchPloneNavigationNode(
idFetchPloneNavigation,
'',
baseUrlNavigation,
mockfetchPloneget
);
expect(data).toEqual(fetchPloneNode);
});
19 changes: 1 addition & 18 deletions src/gatsby-node.js
Expand Up @@ -9,6 +9,7 @@ import {
makeContentNode,
makeNavigationNode,
makeBreadcrumbsNode,
fetchPloneNavigationNode,
parentId,
} from './utils';

Expand Down Expand Up @@ -74,24 +75,6 @@ const fetchPloneBreadcrumbsNode = async (id, token, baseUrl) => {
);
};

// Fetch only navigation component node
const fetchPloneNavigationNode = async (id, token, baseUrl) => {
// Fetch from Plone REST API and normalize it to be GraphQL compatible
const data = normalizeData(
await fetchPlone(`${id}/@navigation`, token, {
// TODO: Higher depth results in "conflicting field types in your data"
'expand.navigation.depth': 1,
}),
baseUrl
);
// Yield navigation node
return makeNavigationNode(
`${id}/@navigation`,
data,
data._path.split('@navigation')[0]
);
};

// GatsbyJS source plugin for Plone
exports.sourceNodes = async (
{ actions, cache, getNode, getNodes, store },
Expand Down
23 changes: 23 additions & 0 deletions src/utils.js
Expand Up @@ -310,3 +310,26 @@ export const makeBreadcrumbsNode = (id, data, path) => {
_path: path,
};
};

// Fetch only navigation component node
export const fetchPloneNavigationNode = async (id, token, baseUrl, mock) => {
// Fetch from Plone REST API and normalize it to be GraphQL compatible
const data = normalizeData(
await fetchPlone(
`${id}/@navigation`,
token,
{
// TODO: Higher depth results in "conflicting field types in your data"
'expand.navigation.depth': 1,
},
mock
),
baseUrl
);
// Yield navigation node
return makeNavigationNode(
`${id}/@navigation`,
data,
data._path.split('@navigation')[0]
);
};

0 comments on commit b3c8f38

Please sign in to comment.