Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stage env detection #407

Merged
merged 2 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/lib/app-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 }
}

Expand Down
7 changes: 5 additions & 2 deletions test/commands/app/add/service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions test/commands/app/delete/service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down
30 changes: 7 additions & 23 deletions test/commands/app/init.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -61,7 +64,6 @@ afterAll(() => {

const savedDataDir = process.env.XDG_DATA_HOME
beforeEach(() => {
mockGetCli.mockReturnValue({})
mockRegister.mockReset()
mockRun.mockReset()
yeoman.createEnv.mockClear()
Expand Down Expand Up @@ -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'])
Expand Down Expand Up @@ -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')
})
})