diff --git a/src/lib/app-helper.js b/src/lib/app-helper.js index 6ff2a2ae..2e47eb0d 100644 --- a/src/lib/app-helper.js +++ b/src/lib/app-helper.js @@ -21,6 +21,7 @@ const chalk = require('chalk') const aioConfig = require('@adobe/aio-lib-core-config') const { AIO_CONFIG_WORKSPACE_SERVICES, AIO_CONFIG_ORG_SERVICES } = require('./defaults') const { EOL } = require('os') +const { getCliEnv } = require('@adobe/aio-lib-env') /** @private */ function isNpmInstalled () { @@ -105,12 +106,12 @@ function wrapError (err) { /** @private */ async function getCliInfo () { - const { env = 'prod' } = await context.getCli() || {} await context.setCli({ 'cli.bare-output': true }, false) // set this globally aioLogger.debug('Retrieving CLI Token') const accessToken = await getToken(CLI) + const env = getCliEnv() return { accessToken, env } } diff --git a/test/commands/app/add/service.test.js b/test/commands/app/add/service.test.js index 266ab866..8a3519b2 100644 --- a/test/commands/app/add/service.test.js +++ b/test/commands/app/add/service.test.js @@ -59,17 +59,20 @@ function setDefaultMockConfig () { // mock login - mocks underlying methods behind getCliInfo const mockAccessToken = 'some-access-token' -const mockGetCli = jest.fn(() => {}) const mockSetCli = jest.fn() jest.mock('@adobe/aio-lib-ims', () => { return { context: { - getCli: () => mockGetCli(), setCli: () => mockSetCli() }, getToken: () => mockAccessToken } }) +jest.mock('@adobe/aio-lib-env', () => { + return { + getCliEnv: () => 'prod' + } +}) // mock data dir const savedDataDir = process.env.XDG_DATA_HOME diff --git a/test/commands/app/delete/service.test.js b/test/commands/app/delete/service.test.js index 24b11901..5339770f 100644 --- a/test/commands/app/delete/service.test.js +++ b/test/commands/app/delete/service.test.js @@ -54,17 +54,20 @@ function setDefaultMockConfig () { // mock login - mocks underlying methods behind getCliInfo const mockAccessToken = 'some-access-token' -const mockGetCli = jest.fn(() => {}) const mockSetCli = jest.fn() jest.mock('@adobe/aio-lib-ims', () => { return { context: { - getCli: () => mockGetCli(), setCli: () => mockSetCli() }, getToken: () => mockAccessToken } }) +jest.mock('@adobe/aio-lib-env', () => { + return { + getCliEnv: () => 'prod' + } +}) const logSpy = jest.spyOn(console, 'error') diff --git a/test/commands/app/init.test.js b/test/commands/app/init.test.js index ff525cf6..c0d9340b 100644 --- a/test/commands/app/init.test.js +++ b/test/commands/app/init.test.js @@ -21,17 +21,20 @@ jest.mock('../../../src/lib/import') jest.mock('fs-extra') const mockAccessToken = 'some-access-token' -const mockGetCli = jest.fn() const mockSetCli = jest.fn() jest.mock('@adobe/aio-lib-ims', () => { return { context: { - getCli: () => mockGetCli(), setCli: () => mockSetCli() }, getToken: () => mockAccessToken } }) +jest.mock('@adobe/aio-lib-env', () => { + return { + getCliEnv: () => 'prod' + } +}) jest.mock('yeoman-environment') const yeoman = require('yeoman-environment') @@ -61,7 +64,6 @@ afterAll(() => { const savedDataDir = process.env.XDG_DATA_HOME beforeEach(() => { - mockGetCli.mockReturnValue({}) mockRegister.mockReset() mockRun.mockReset() yeoman.createEnv.mockClear() @@ -326,8 +328,8 @@ describe('run', () => { }) test('getCliInfo error', async () => { - mockGetCli.mockReset() - mockGetCli.mockImplementationOnce(() => { throw new Error('Error') }) + mockSetCli.mockReset() + mockSetCli.mockImplementationOnce(() => { throw new Error('Error') }) const project = mockValidConfig() await TheCommand.run(['--skip-install']) @@ -689,22 +691,4 @@ describe('run', () => { { interactive: false, merge: true }, { SERVICE_API_KEY: 'fakeId123' }) }) - - test('no cli context', async () => { - mockGetCli.mockReturnValue(null) - mockValidConfig() - await TheCommand.run([]) - - expect(yeoman.createEnv).toHaveBeenCalled() - expect(mockRegister).toHaveBeenCalledTimes(2) - const genConsole = mockRegister.mock.calls[0][1] - expect(mockRun).toHaveBeenNthCalledWith(1, genConsole, { - 'access-token': mockAccessToken, - 'destination-file': 'console.json', - 'ims-env': 'prod', - 'allow-create': true, - 'cert-dir': certDir - }) - expect(fs.unlinkSync).toHaveBeenCalledWith('console.json') - }) })