Skip to content

Commit 1ad330e

Browse files
authored
fix: ACNA-3953 - activity logs not showing for extensions (#878)
* fix: getting cached access token returns undefined * add failing tests * fix getAccessToken failing test for --no-publish and --no-unpublish (logic error)
1 parent a2922db commit 1ad330e

File tree

6 files changed

+25
-5
lines changed

6 files changed

+25
-5
lines changed

src/commands/app/deploy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class Deploy extends BuildCommand {
5858

5959
try {
6060
const { aio: aioConfig, packagejson: packageJson } = await this.getFullConfig()
61-
const cliDetails = await getAccessToken({ useCachedToken: flags.publish })
61+
const cliDetails = await getAccessToken({ useCachedToken: !flags.publish })
6262
const appInfo = {
6363
name: packageJson.name,
6464
version: packageJson.version,

src/commands/app/undeploy.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Undeploy extends BaseCommand {
5252
const spinner = ora()
5353
try {
5454
const { aio: aioConfig, packagejson: packageJson } = await this.getFullConfig()
55-
const cliDetails = await getAccessToken({ useCachedToken: flags.unpublish })
55+
const cliDetails = await getAccessToken({ useCachedToken: !flags.unpublish })
5656
const appInfo = {
5757
name: packageJson.name,
5858
version: packageJson.version,

src/lib/auth-helper.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ async function getAccessToken ({ useCachedToken = false } = {}) {
4747

4848
let accessToken = null
4949
if (useCachedToken) {
50-
const contextConfig = await context.get(contextName)
51-
accessToken = contextConfig?.access_token?.token
50+
const { data } = await context.get(contextName)
51+
accessToken = data?.access_token?.token
5252
} else {
5353
accessToken = await getToken(contextName)
5454
}

test/commands/app/deploy.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const BaseCommand = require('../../../src/BaseCommand')
1515
const cloneDeep = require('lodash.clonedeep')
1616
const dataMocks = require('../../data-mocks/config-loader')
1717
const helpersActual = jest.requireActual('../../../src/lib/app-helper.js')
18+
const authHelpersActual = jest.requireActual('../../../src/lib/auth-helper')
19+
1820
const open = require('open')
1921
const mockBundleFunc = jest.fn()
2022

@@ -394,6 +396,8 @@ describe('run', () => {
394396
})
395397

396398
test('deploy does not require logged in user with --no-publish (workspace: Production)', async () => {
399+
authHelper.getAccessToken.mockImplementation(authHelpersActual.getAccessToken)
400+
397401
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig, 'exc'))
398402
mockGetExtensionPointsRetractedApp() // not published
399403
command.getFullConfig.mockResolvedValue({
@@ -420,6 +424,9 @@ describe('run', () => {
420424
expect(mockWebLib.deployWeb).toHaveBeenCalledTimes(1)
421425
expect(command.buildOneExt).toHaveBeenCalledTimes(1)
422426
expect(mockLibConsoleCLI.getApplicationExtensions).not.toHaveBeenCalled()
427+
428+
expect(auditLogger.sendAppDeployAuditLog).toHaveBeenCalledTimes(0)
429+
expect(auditLogger.sendAppAssetsDeployedAuditLog).toHaveBeenCalledTimes(0)
423430
})
424431

425432
test('build & deploy only some actions using --action', async () => {

test/commands/app/undeploy.test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const TheCommand = require('../../../src/commands/app/undeploy')
1414
const BaseCommand = require('../../../src/BaseCommand')
1515
const dataMocks = require('../../data-mocks/config-loader')
1616
const cloneDeep = require('lodash.clonedeep')
17+
const authHelperActual = jest.requireActual('../../../src/lib/auth-helper.js')
1718

1819
jest.mock('../../../src/lib/app-helper.js')
1920
const helpers = require('../../../src/lib/app-helper.js')
@@ -474,6 +475,18 @@ describe('run', () => {
474475
expect(command.error).toHaveBeenCalledWith(expect.stringMatching(/Nothing to be done/))
475476
})
476477

478+
test('undeploy does not require logged in user with --no-unpublish', async () => {
479+
authHelper.getAccessToken.mockImplementation(authHelperActual.getAccessToken)
480+
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig())
481+
482+
command.argv = ['--no-unpublish']
483+
await command.run()
484+
expect(command.error).toHaveBeenCalledTimes(0)
485+
486+
expect(auditLogger.sendAppAssetsUndeployedAuditLog).toHaveBeenCalledTimes(0)
487+
expect(auditLogger.sendAppUndeployAuditLog).toHaveBeenCalledTimes(0)
488+
})
489+
477490
test('does NOT fire `event` hooks when feature flag is NOT enabled', async () => {
478491
command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig))
479492
command.argv = []

test/commands/lib/auth-helper.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('getAccessToken', () => {
4444
test('should use cached token when requested', async () => {
4545
const mockToken = 'cached-token'
4646
const mockEnv = 'prod'
47-
const mockContext = { access_token: { token: mockToken } }
47+
const mockContext = { data: { access_token: { token: mockToken } } }
4848
getCliEnv.mockReturnValue(mockEnv)
4949
context.getCurrent.mockResolvedValue(CLI)
5050
context.get.mockResolvedValue(mockContext)

0 commit comments

Comments
 (0)