From cf42dca7776774293068db42b3de43c17104bf88 Mon Sep 17 00:00:00 2001 From: Scott Lowe Date: Thu, 14 Nov 2019 10:53:38 +0100 Subject: [PATCH] Hide discontinued device types in `balena app create`. Add basic tests for `balena app create` Connects-to: #1485 Change-type: patch Signed-off-by: Scott Lowe --- lib/utils/patterns.ts | 4 ++- tests/commands/app/create.spec.ts | 35 +++++++++++++++++++++++++ tests/commands/device/supported.spec.ts | 14 +--------- tests/helpers.ts | 13 +++++++++ 4 files changed, 52 insertions(+), 14 deletions(-) create mode 100644 tests/commands/app/create.spec.ts diff --git a/lib/utils/patterns.ts b/lib/utils/patterns.ts index ed53afd4..59d7125a 100644 --- a/lib/utils/patterns.ts +++ b/lib/utils/patterns.ts @@ -130,7 +130,9 @@ export function selectDeviceType() { return getBalenaSdk() .models.config.getDeviceTypes() .then(deviceTypes => { - deviceTypes = _.sortBy(deviceTypes, 'name'); + deviceTypes = _.sortBy(deviceTypes, 'name').filter( + dt => dt.state !== 'DISCONTINUED', + ); return getForm().ask({ message: 'Device Type', type: 'list', diff --git a/tests/commands/app/create.spec.ts b/tests/commands/app/create.spec.ts new file mode 100644 index 00000000..393b474b --- /dev/null +++ b/tests/commands/app/create.spec.ts @@ -0,0 +1,35 @@ +import { expect } from 'chai'; +import * as _ from 'lodash'; +import { cleanOutput, runCommand } from '../../helpers'; + +const HELP_MESSAGE = ` +Usage: app create + +Use this command to create a new balena application. + +You can specify the application device type with the \`--type\` option. +Otherwise, an interactive dropdown will be shown for you to select from. + +You can see a list of supported device types with + +\t$ balena devices supported + +Examples: + +\t$ balena app create MyApp +\t$ balena app create MyApp --type raspberry-pi + +Options: + + --type, -t application device type (Check available types with \`balena devices supported\`) +`; + +describe('balena app create', function() { + it('should print help text with the -h flag', async () => { + const { out, err } = await runCommand('app create -h'); + + expect(cleanOutput(out)).to.deep.equal(cleanOutput([HELP_MESSAGE])); + + expect(err).to.have.lengthOf(0); + }); +}); diff --git a/tests/commands/device/supported.spec.ts b/tests/commands/device/supported.spec.ts index 720ce0aa..cd67d212 100644 --- a/tests/commands/device/supported.spec.ts +++ b/tests/commands/device/supported.spec.ts @@ -1,6 +1,6 @@ import { expect } from 'chai'; import * as _ from 'lodash'; -import { runCommand } from '../../helpers'; +import { cleanOutput, runCommand } from '../../helpers'; const HELP = ` Usage: devices supported @@ -12,18 +12,6 @@ Examples: \t$ balena devices supported `; -const cleanOutput = (output: string[] | string) => { - return _(_.castArray(output)) - .map(log => { - return log.split('\n').map(line => { - return line.trim(); - }); - }) - .flatten() - .compact() - .value(); -}; - describe('balena devices supported', function() { it('should list currently supported devices', async () => { const { out, err } = await runCommand('devices supported'); diff --git a/tests/helpers.ts b/tests/helpers.ts index ed33e0a5..9a138572 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -16,6 +16,7 @@ */ import intercept = require('intercept-stdout'); +import * as _ from 'lodash'; import * as nock from 'nock'; import * as path from 'path'; @@ -78,3 +79,15 @@ export const balenaAPIMock = () => { configVarSchema: [], }); }; + +export function cleanOutput(output: string[] | string) { + return _(_.castArray(output)) + .map(log => { + return log.split('\n').map(line => { + return line.trim(); + }); + }) + .flatten() + .compact() + .value(); +}