Skip to content
This repository has been archived by the owner on Mar 14, 2022. It is now read-only.

Commit

Permalink
make getModuleBrands return an array with all brands defined if the o…
Browse files Browse the repository at this point in the history
…rigami.json files has no brands property
  • Loading branch information
JakeChampion committed Feb 12, 2021
1 parent e67d908 commit dfb5cfe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lib/helpers/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,18 @@ function getComponentName(cwd) {
function getModuleBrands(cwd) {
return getOrigamiJson(cwd)
.then(origamiJson => {
if (origamiJson && origamiJson.brands && Array.isArray(origamiJson.brands)) {
const hasBrandsDefined = origamiJson && origamiJson.brands && Array.isArray(origamiJson.brands) && origamiJson.brands.length > 0;
if (hasBrandsDefined) {
return origamiJson.brands;
}
return [];
return ['master', 'internal', 'whitelabel'];
});
}

/**
* Get individual demo configuration for the component.
* @param {string} cwd - The component's directory (the current working directory).
* @return {array<object>} - An array of objects representing a component demo.
* @return {Promise<Array<object>>} - An array of objects representing a component demo.
*/
async function getComponentDemos(cwd) {
const origamiJson = await getOrigamiJson(cwd);
Expand Down
26 changes: 26 additions & 0 deletions test/unit/helpers/files.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,30 @@ describe('Files helper', function () {
proclaim.lengthEquals(Object.keys(demosDefaults), 0, 'Expected an empty object given missing default demo configuration.');
});
});

describe('getModuleBrands', function() {
context('if no brands are defined', function() {
it('should return an array containing only `master`, `internal`, `whitelabel`', async function(){
const brands = await files.getModuleBrands();
proclaim.deepStrictEqual(brands, ['master', 'internal', 'whitelabel']);
});
});

context('if brands is defined as an array with no items', function(){
it('should return an array containing only `master`, `internal`, `whitelabel`', async function(){
const brands = await files.getModuleBrands();
proclaim.deepStrictEqual(brands, ['master', 'internal', 'whitelabel']);
});
});

context('if brands is defined as an array with items', function(){
it('should return an arary with the same items as those defined', async function() {
const origamiManifest = JSON.parse(fs.readFileSync('origami.json', 'utf8'));
origamiManifest.brands = ['master'];
fs.writeFileSync('origami.json', JSON.stringify(origamiManifest), 'utf8');
const brands = await files.getModuleBrands();
proclaim.deepStrictEqual(brands, ['master']);
});
});
});
});

0 comments on commit dfb5cfe

Please sign in to comment.