Skip to content

Commit 722a811

Browse files
author
taub
committed
add unit tests for config-validate and fix formatting
1 parent 49b6091 commit 722a811

File tree

23 files changed

+89
-73
lines changed

23 files changed

+89
-73
lines changed

src/BaseCommand.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,13 @@ const {
3232

3333
class BaseCommand extends Command {
3434
// default error handler for app commands
35-
async catch(error) {
35+
async catch (error) {
3636
const { flags } = await this.parse(this.prototype)
3737
aioLogger.error(error) // debug log
3838
this.error(flags.verbose && error.stack ? error.stack : error.message)
3939
}
4040

41-
async init() {
41+
async init () {
4242
await super.init()
4343
// setup a prompt that outputs to stderr
4444
this.prompt = inquirer.createPromptModule({ output: process.stderr })
@@ -51,7 +51,7 @@ class BaseCommand extends Command {
5151
`aio-cli-plugin-app/${vs?.cliVersion} (${vs?.architecture}; ${vs?.nodeVersion}; ${vs?.shell})`
5252
}
5353

54-
async getLibConsoleCLI() {
54+
async getLibConsoleCLI () {
5555
if (!this.consoleCLI) {
5656
// requires valid login
5757
const { accessToken, env } = await getAccessToken()
@@ -61,11 +61,11 @@ class BaseCommand extends Command {
6161
return this.consoleCLI
6262
}
6363

64-
async cleanConsoleCLIOutput() {
64+
async cleanConsoleCLIOutput () {
6565
LibConsoleCLI.cleanStdOut()
6666
}
6767

68-
async getAppExtConfigs(flags, options = {}) {
68+
async getAppExtConfigs (flags, options = {}) {
6969
const all = (await this.getFullConfig(options, flags)).all
7070

7171
// default case: no flags, return all
@@ -96,7 +96,7 @@ class BaseCommand extends Command {
9696
return ret
9797
}
9898

99-
async getRuntimeManifestConfigFile(implName, flags) {
99+
async getRuntimeManifestConfigFile (implName, flags) {
100100
let configKey
101101
if (implName === APPLICATION_CONFIG_KEY) {
102102
configKey = APPLICATION_CONFIG_KEY
@@ -112,7 +112,7 @@ class BaseCommand extends Command {
112112
return configData
113113
}
114114

115-
async getEventsConfigFile(implName, flags) {
115+
async getEventsConfigFile (implName, flags) {
116116
let configKey
117117
if (implName === APPLICATION_CONFIG_KEY) {
118118
configKey = APPLICATION_CONFIG_KEY
@@ -128,7 +128,7 @@ class BaseCommand extends Command {
128128
return configData
129129
}
130130

131-
async getConfigFileForKey(fullKey, flags = {}) {
131+
async getConfigFileForKey (fullKey, flags = {}) {
132132
// NOTE: the index returns undefined if the key is loaded from a legacy configuration file
133133
const fullConfig = await this.getFullConfig({}, flags)
134134
// full key like 'extensions.dx/excshell/1.runtimeManifest'
@@ -142,19 +142,18 @@ class BaseCommand extends Command {
142142
return configData || {}
143143
}
144144

145-
async getFullConfig(options = {}, flags = {}) {
145+
async getFullConfig (options = {}, flags = {}) {
146146
// validate appConfig defaults to true unless flag is explicitly set to off
147147
const validateAppConfig = flags['config-validation'] !== false
148148
aioLogger.debug(`validateAppConfig=${validateAppConfig}`)
149149

150150
if (!this.appConfig) {
151-
// this will explicitly set validateAppConfig=false if not set
152151
this.appConfig = await appConfig.load({ ...options, validateAppConfig })
153152
}
154153
return this.appConfig
155154
}
156155

157-
getLaunchUrlPrefix() {
156+
getLaunchUrlPrefix () {
158157
// todo: it might make sense to have a value that defines if this is an ExC hosted app, or otherwise
159158
// so we can decide what type of url to return here.
160159
// at some point we could also just delete the .env value and return our expected url here.
@@ -173,19 +172,19 @@ class BaseCommand extends Command {
173172
return (launchPrefix || defaultLaunchPrefix)
174173
}
175174

176-
get pjson() {
175+
get pjson () {
177176
return this.config.pjson
178177
}
179178

180-
get appName() {
179+
get appName () {
181180
return this.pjson.name
182181
}
183182

184-
get appVersion() {
183+
get appVersion () {
185184
return this.pjson.version
186185
}
187186

188-
preRelease() {
187+
preRelease () {
189188
this.log(chalk.yellow('Pre-release warning: This command is in pre-release, and not suitable for production.'))
190189
}
191190
}

src/commands/app/add/action.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const TemplateRegistryAPI = require('@adobe/aio-lib-templates')
1818
const inquirer = require('inquirer')
1919

2020
class AddActionCommand extends TemplatesCommand {
21-
async run() {
21+
async run () {
2222
const { flags } = await this.parse(AddActionCommand)
2323

2424
aioLogger.debug(`add actions with flags: ${JSON.stringify(flags)}`)
@@ -63,7 +63,7 @@ class AddActionCommand extends TemplatesCommand {
6363
}
6464
}
6565

66-
async getSearchCriteria(orgSupportedServices) {
66+
async getSearchCriteria (orgSupportedServices) {
6767
const choices = [
6868
{
6969
name: 'All Action Templates',

src/commands/app/add/event.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const path = require('path')
1717
const TemplateRegistryAPI = require('@adobe/aio-lib-templates')
1818

1919
class AddEventCommand extends TemplatesCommand {
20-
async run() {
20+
async run () {
2121
const { flags } = await this.parse(AddEventCommand)
2222

2323
aioLogger.debug(`add events with flags: ${JSON.stringify(flags)}`)
@@ -56,7 +56,7 @@ class AddEventCommand extends TemplatesCommand {
5656
}
5757
}
5858

59-
async getSearchCriteria() {
59+
async getSearchCriteria () {
6060
const TEMPLATE_CATEGORIES = ['events', 'helper-template']
6161
const searchCriteria = {
6262
[TemplateRegistryAPI.SEARCH_CRITERIA_STATUSES]: TemplateRegistryAPI.TEMPLATE_STATUS_APPROVED,

src/commands/app/add/extension.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const { Flags } = require('@oclif/core')
1515
const TemplateRegistryAPI = require('@adobe/aio-lib-templates')
1616

1717
class AddExtensionCommand extends TemplatesCommand {
18-
async run() {
18+
async run () {
1919
const { flags } = await this.parse(AddExtensionCommand)
2020

2121
aioLogger.debug(`add extensions with flags: ${JSON.stringify(flags)}`)
@@ -34,7 +34,7 @@ class AddExtensionCommand extends TemplatesCommand {
3434
}
3535
}
3636

37-
async selectExtensionsToInstall(alreadyImplemented, useDefaultValues, installNpm) {
37+
async selectExtensionsToInstall (alreadyImplemented, useDefaultValues, installNpm) {
3838
const excludeExtensions = alreadyImplemented.map(e => `${TemplateRegistryAPI.SEARCH_CRITERIA_FILTER_NOT}${e}`)
3939

4040
const orderByCriteria = {

src/commands/app/add/web-assets.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const { Flags } = require('@oclif/core')
1515
const TemplateRegistryAPI = require('@adobe/aio-lib-templates')
1616

1717
class AddWebAssetsCommand extends TemplatesCommand {
18-
async run() {
18+
async run () {
1919
const { flags } = await this.parse(AddWebAssetsCommand)
2020
aioLogger.debug(`add web-assets with flags: ${JSON.stringify(flags)}`)
2121

src/commands/app/config/get/log-forwarding.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const LogForwarding = require('../../../../lib/log-forwarding')
1414
const { setRuntimeApiHostAndAuthHandler } = require('../../../../lib/auth-helper')
1515

1616
class LogForwardingCommand extends BaseCommand {
17-
async run() {
17+
async run () {
1818
const { flags } = await this.parse(LogForwardingCommand)
1919
let aioConfig = (await this.getFullConfig({}, flags)).aio
2020
aioConfig = setRuntimeApiHostAndAuthHandler(aioConfig)
@@ -38,7 +38,7 @@ class LogForwardingCommand extends BaseCommand {
3838
this.printConfig(serverConfig)
3939
}
4040

41-
printConfig(config) {
41+
printConfig (config) {
4242
if (config.isDefined()) {
4343
this.log(`destination: ${config.getDestination()}`)
4444
this.log('settings:', config.getSettings())

src/commands/app/config/get/log-forwarding/errors.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const ora = require('ora')
1515
const { setRuntimeApiHostAndAuthHandler } = require('../../../../../lib/auth-helper')
1616

1717
class ErrorsCommand extends BaseCommand {
18-
async run() {
18+
async run () {
1919
const { flags } = await this.parse(ErrorsCommand)
2020
const spinner = ora()
2121
const lf = await this.getLogForwarding(flags)
@@ -31,7 +31,7 @@ class ErrorsCommand extends BaseCommand {
3131
}
3232
}
3333

34-
async getLogForwarding(flags) {
34+
async getLogForwarding (flags) {
3535
let aioConfig = (await this.getFullConfig({}, flags)).aio
3636
aioConfig = setRuntimeApiHostAndAuthHandler(aioConfig)
3737

src/commands/app/config/set/log-forwarding.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-
1515
const { setRuntimeApiHostAndAuthHandler } = require('../../../../lib/auth-helper')
1616

1717
class LogForwardingCommand extends BaseCommand {
18-
async run() {
18+
async run () {
1919
const { flags } = await this.parse(LogForwardingCommand)
2020
let aioConfig = (await this.getFullConfig({}, flags)).aio
2121
aioConfig = setRuntimeApiHostAndAuthHandler(aioConfig)
@@ -38,7 +38,7 @@ class LogForwardingCommand extends BaseCommand {
3838
})
3939
}
4040

41-
async promptDestination(supportedDestinations) {
41+
async promptDestination (supportedDestinations) {
4242
const responses = await this.prompt([{
4343
name: 'type',
4444
message: 'select log forwarding destination',

src/commands/app/delete/action.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const { EOL } = require('os')
2020
const { atLeastOne, deleteUserConfig } = require('../../../lib/app-helper')
2121

2222
class DeleteActionCommand extends BaseCommand {
23-
async run() {
23+
async run () {
2424
const { args, flags } = await this.parse(DeleteActionCommand)
2525

2626
aioLogger.debug(`deleting actions from the project, with args ${JSON.stringify(args)}, and flags: ${JSON.stringify(flags)}`)
@@ -108,7 +108,7 @@ class DeleteActionCommand extends BaseCommand {
108108
)))
109109
}
110110

111-
async getAllActions(config, flags = {}) {
111+
async getAllActions (config, flags = {}) {
112112
const actions = []
113113
const actionsByImpl = {}
114114
const allConfigEntries = Object.entries(config.all)

src/commands/app/delete/extension.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const fs = require('fs-extra')
1919
const { EOL } = require('os')
2020

2121
class DeleteExtensionCommand extends BaseCommand {
22-
async run() {
22+
async run () {
2323
const { flags } = await this.parse(DeleteExtensionCommand)
2424

2525
aioLogger.debug(`delete extension with flags: ${JSON.stringify(flags)}`)
@@ -52,7 +52,7 @@ class DeleteExtensionCommand extends BaseCommand {
5252
)))
5353
}
5454

55-
async selectOrGetConfigsToDelete(flags, config) {
55+
async selectOrGetConfigsToDelete (flags, config) {
5656
const alreadyImplemented = config.implements
5757
if (alreadyImplemented.length <= 0) {
5858
throw new Error('There are no implementations left in the project')
@@ -71,7 +71,7 @@ class DeleteExtensionCommand extends BaseCommand {
7171
return await this.getAppExtConfigs(flags)
7272
}
7373

74-
async deleteImplementations(configs, flags) {
74+
async deleteImplementations (configs, flags) {
7575
for (const [id, c] of Object.entries(configs)) {
7676
// delete actions
7777
if (c.app.hasBackend) {

0 commit comments

Comments
 (0)