Skip to content

Commit

Permalink
refactor naming for implementation clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
endiliey committed Oct 8, 2018
1 parent 39d8d87 commit ce549c0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
16 changes: 8 additions & 8 deletions v1/lib/server/__tests__/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,26 +90,26 @@ describe('server utils', () => {
});

describe('validateSidebar', () => {
test('should throw an error for invalid pages', () => {
test('should throw an error for invalid sidebarMetadatas', () => {
const metadata = {
id: 'doc1',
sidebar: 'docs',
next_id: 'doc2',
next: 'doc2',
};

const pages = {
const sidebarMetadatas = {
doc1: {},
};

expect(() => {
utils.validateSidebar(metadata, pages);
utils.validateSidebar(metadata, sidebarMetadatas);
}).toThrow(
`Improper sidebars.json file, document with id 'doc2' not found. Make sure that documents with the ids specified in sidebars.json exist and that no ids are repeated.`,
);
});

test('should throw an error for invalid version pages', () => {
test('should throw an error for invalid version sidebarMetadatas', () => {
const metadata = {
id: 'doc1',
version: 'foo',
Expand All @@ -118,12 +118,12 @@ describe('server utils', () => {
next: 'doc2',
};

const pages = {
const sidebarMetadatas = {
doc1: {},
};

expect(() => {
utils.validateSidebar(metadata, pages);
utils.validateSidebar(metadata, sidebarMetadatas);
}).toThrow(
`Improper sidebars file for version foo, document with id 'doc2' not found. Make sure that all documents with ids specified in this version's sidebar file exist and that no ids are repeated.`,
);
Expand All @@ -137,13 +137,13 @@ describe('server utils', () => {
next: 'doc2',
};

const pages = {
const sidebarMetadatas = {
doc1: {},
doc2: {},
};

expect(() => {
utils.validateSidebar(metadata, pages);
utils.validateSidebar(metadata, sidebarMetadatas);
}).not.toThrow();
});
});
Expand Down
10 changes: 5 additions & 5 deletions v1/lib/server/readCategories.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ function readCategories(sidebar, allMetadata, languages) {
const language = enabledLanguages[k];
const metadatas = [];
const categories = [];
const pages = {};
const sidebarMetadatas = {};

// Get the metadata for the current sidebar
// Get all related metadata for the current sidebar
Object.keys(allMetadata).forEach(id => {
const metadata = allMetadata[id];
if (metadata.sidebar === sidebar && metadata.language === language) {
metadatas.push(metadata);
pages[metadata.id] = metadata;
sidebarMetadatas[metadata.id] = metadata;
}
});

Expand Down Expand Up @@ -59,8 +59,8 @@ function readCategories(sidebar, allMetadata, languages) {
const category = metadata.category;
const subCategory = metadata.sub_category;

// Validate pages in the sidebar
validateSidebar(metadata, pages);
// Validate sidebarMetadatas in the sidebar
validateSidebar(metadata, sidebarMetadatas);

if (!indexedCategories[category]) {
indexedCategories[category] = [];
Expand Down
4 changes: 2 additions & 2 deletions v1/lib/server/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ function autoPrefixCss(cssContent) {
}

// Validate the docs in the sidebar are valid
function validateSidebar(metadata, pages) {
function validateSidebar(metadata, sidebarMetadatas) {
if (metadata.next) {
if (!pages[metadata.next]) {
if (!sidebarMetadatas[metadata.next]) {
throw new Error(
metadata.version
? `Improper sidebars file for version ${
Expand Down

0 comments on commit ce549c0

Please sign in to comment.