Skip to content

Commit

Permalink
chore: replace tags with vendor extension (twilio#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkingserious committed Dec 7, 2020
1 parent 077455f commit 4e91b40
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
39 changes: 20 additions & 19 deletions src/services/twilio-api/get-action-description.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { capitalize } = require('@twilio/cli-core').services.namingConventions;

// The (upper-case) name of any tags that we should ignore when building command descriptions.
const IGNORED_TAGS = new Set(['GA']);
// The (upper-case) name of any maturity levels that we should ignore when building command descriptions.
const IGNORED_MATURITY = new Set(['GA']);
const DESCRIPTION_SEPARATOR = '\n\n';

const getSummaryDescription = (actionDefinition) => {
Expand All @@ -26,30 +26,31 @@ const getSummaryDescription = (actionDefinition) => {

const getActionDescription = (actionDefinition) => {
let summaryDescription = getSummaryDescription(actionDefinition);
if (actionDefinition.action['x-maturity']) {
// Get the list of maturity levels that we care about.
const maturity = actionDefinition.action['x-maturity'].filter(
(maturityName) => !IGNORED_MATURITY.has(maturityName.toUpperCase()),
);

if (actionDefinition.action.tags) {
// Get the list of tags that we care about.
const tags = actionDefinition.action.tags.filter((tagName) => !IGNORED_TAGS.has(tagName.toUpperCase()));
// Build maturity IDs and prepend them to the summary description.
const maturityIds = maturity.map((maturityName) => `[${maturityName.toUpperCase()}]`).join(' ');

// Build tag IDs and prepend them to the summary description.
const tagIds = tags.map((tagName) => `[${tagName.toUpperCase()}]`).join(' ');
summaryDescription = `${maturityIds} ${summaryDescription}`;

summaryDescription = `${tagIds} ${summaryDescription}`;

if (actionDefinition.domain.tags) {
if (actionDefinition.domain['x-maturity']) {
/*
* Build the tag descriptions and append them to the summary description.
* We map from domain tags to action tags (rather the the other way
* around) in order to maintain the ordering of the domain tags. It also
* allows to not fail when there's an unaccounted for action tag.
* Build the maturity descriptions and append them to the summary description.
* We map from domain maturity to action maturity (rather the the other way
* around) in order to maintain the ordering of the maturity levels. It also
* allows to not fail when there's an unaccounted for action maturity levels.
*/
const tagSet = new Set(tags);
const tagDescriptions = actionDefinition.domain.tags
.filter((tag) => tagSet.has(tag.name))
.map((tag) => tag.description)
const maturitySet = new Set(maturity);
const maturityDescriptions = actionDefinition.domain['x-maturity']
.filter((m) => maturitySet.has(m.name))
.map((m) => m.description)
.join(DESCRIPTION_SEPARATOR);

summaryDescription = `${summaryDescription}${DESCRIPTION_SEPARATOR}${tagDescriptions}`;
summaryDescription = `${summaryDescription}${DESCRIPTION_SEPARATOR}${maturityDescriptions}`;
}
}

Expand Down
20 changes: 10 additions & 10 deletions test/services/twilio-api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,36 +94,36 @@ describe('services', () => {
expect(result).to.equal('remove an ExcellentSubResource resource');
});

test.it('handles actions with tags', () => {
test.it('handles actions with maturity', () => {
const result = getActionDescription({
action: {
description: 'Beeta!',
tags: ['beta'],
'x-maturity': ['beta'],
},
domain: {},
});
expect(result).to.equal('[BETA] Beeta!');
});

test.it('ignores GA tags', () => {
test.it('ignores GA maturity level', () => {
const result = getActionDescription({
action: {
description: 'Generally Beta!',
tags: ['beta', 'ga'],
'x-maturity': ['beta', 'ga'],
},
domain: {},
});
expect(result).to.equal('[BETA] Generally Beta!');
});

test.it('handles actions with tags and descriptions', () => {
test.it('handles actions with maturity and descriptions', () => {
const result = getActionDescription({
action: {
description: 'Pree-vue!',
tags: ['preview'],
'x-maturity': ['preview'],
},
domain: {
tags: [
'x-maturity': [
{
name: 'preview',
description: 'shhhh',
Expand All @@ -134,14 +134,14 @@ describe('services', () => {
expect(result).to.equal('[PREVIEW] Pree-vue!\n\nshhhh');
});

test.it('handles actions with multiple tags and description', () => {
test.it('handles actions with multiple maturities and description', () => {
const result = getActionDescription({
action: {
description: 'Pre-beta!',
tags: ['beta', 'preview'],
'x-maturity': ['beta', 'preview'],
},
domain: {
tags: [
'x-maturity': [
{
name: 'beta',
description: '???',
Expand Down

0 comments on commit 4e91b40

Please sign in to comment.