Skip to content

Commit

Permalink
fix: usage of load function from @adobe/aio-cli-lib-app-config was no…
Browse files Browse the repository at this point in the history
…t async (#59)

* fix tests to fail with `load` not being async
* add async to loadConfig
  • Loading branch information
shazron authored Jan 12, 2024
1 parent 5e25b9d commit e84c71b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/commands/templates/discover.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DiscoverCommand extends BaseCommand {
const apiKey = env.getCliEnv() === 'prod' ? 'aio-cli-console-auth' : 'aio-cli-console-auth-stage'
const consoleCLI = await LibConsoleCLI.init({ accessToken: this.accessToken, env: env.getCliEnv(), apiKey })

const appConfig = loadConfig({})
const appConfig = await loadConfig({})
let orgId = appConfig?.aio?.project?.org?.id
if (!orgId) {
const organizations = await consoleCLI.getOrganizations()
Expand Down
2 changes: 1 addition & 1 deletion src/commands/templates/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class InstallCommand extends BaseCommand {
const templateManager = await templateHandler.init(this.accessToken, installConfigFile)

// 3. Install the template
const appConfig = loadConfig({})
const appConfig = await loadConfig({})
const orgId = appConfig?.aio?.project?.org?.id
const projectId = appConfig?.aio?.project?.id
if (orgId && projectId) {
Expand Down
8 changes: 4 additions & 4 deletions test/commands/templates/discover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe('interactive install', () => {
test('normal choices', async () => {
getTemplates.mockReturnValue(templates)
libEnv.getCliEnv.mockReturnValue('prod')
loadConfig.mockImplementation(() => mockAIOConfigJSON)
loadConfig.mockResolvedValue(mockAIOConfigJSON)
mockConsoleCLIInstance.getEnabledServicesForOrg.mockResolvedValue(fakeSupportedOrgServices)
// default values for Order By
const orderByCriteria = {
Expand Down Expand Up @@ -234,7 +234,7 @@ describe('interactive install', () => {
test('org does not support all services', async () => {
getTemplates.mockReturnValue(templates)
libEnv.getCliEnv.mockReturnValue('prod')
loadConfig.mockImplementation(() => {})
loadConfig.mockResolvedValue(undefined)
const supportedOrgServices = [{ code: 'ViewSDK', properties: {} }, { code: 'UserMgmtSDK', properties: {} }, { code: 'McPlacesSDK', properties: {} }]
const fakeOrg = { id: 'fakeorgid', name: 'bestorg' }
mockConsoleCLIInstance.promptForSelectOrganization.mockResolvedValue(fakeOrg)
Expand Down Expand Up @@ -266,7 +266,7 @@ describe('interactive install', () => {
test('all templates are already installed', async () => {
getTemplates.mockReturnValue(templates)
libEnv.getCliEnv.mockReturnValue('prod')
loadConfig.mockImplementation(() => mockAIOConfigJSON)
loadConfig.mockResolvedValue(mockAIOConfigJSON)
mockConsoleCLIInstance.getEnabledServicesForOrg.mockResolvedValue(fakeSupportedOrgServices)
// default values for Order By
const orderByCriteria = {
Expand All @@ -293,7 +293,7 @@ describe('interactive install', () => {
test('no choices', async () => {
getTemplates.mockReturnValue([])
libEnv.getCliEnv.mockReturnValue('stage')
loadConfig.mockImplementation(() => mockAIOConfigJSON)
loadConfig.mockResolvedValue(mockAIOConfigJSON)
mockConsoleCLIInstance.getEnabledServicesForOrg.mockResolvedValue(fakeSupportedOrgServices)
// default values for Order By
const orderByCriteria = {
Expand Down
2 changes: 1 addition & 1 deletion test/commands/templates/install.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TemplateHandler.init.mockResolvedValue(mockTemplateHandlerInstance)
jest.mock('@adobe/aio-cli-lib-app-config')
const { load: loadConfig } = require('@adobe/aio-cli-lib-app-config')
const mockAIOConfigJSON = JSON.parse('{"aio": {"project": {"id": "project-id","org": {"id": "org-id"}}}}')
loadConfig.mockImplementation(() => mockAIOConfigJSON)
loadConfig.mockResolvedValue(mockAIOConfigJSON)

// mock ims calls
jest.mock('@adobe/aio-lib-ims', () => ({
Expand Down

0 comments on commit e84c71b

Please sign in to comment.