Skip to content

Commit

Permalink
coverage, linting, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
purplecabbage committed Nov 8, 2024
1 parent e07bff9 commit 769fa44
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/lib/audit-logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const fs = require('fs')
const path = require('path')
const chalk = require('chalk')
const { getCliEnv, PROD_ENV } = require('@adobe/aio-lib-env')
const aioLogger = require('@adobe/aio-lib-core-logging')('@adobe/aio-cli-plugin-app:lib-audit-logger', { provider: 'debug' })

const OPERATIONS = {
AB_APP_DEPLOY: 'ab_app_deploy',
Expand Down Expand Up @@ -67,8 +68,8 @@ async function sendAuditLogs (accessToken, logEvent, env = 'prod') {
*/
function getAuditLogEvent (flags, project, event) {
if (getCliEnv() === PROD_ENV) {
console.log('Audit logging is currently disabled in production environment')
return
aioLogger.debug('Audit logging is currently disabled in production environment')
return null
}

let logEvent, logStrMsg
Expand Down
1 change: 1 addition & 0 deletions test/BaseCommand.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ test('getLaunchUrlPrefix() warns on older url', async () => {
test('getLaunchUrlPrefix() uses stage launch prefix', async () => {
const cmd = new TheCommand()
libEnv.getCliEnv.mockReturnValue('stage')
mockAioConfig.get.mockReturnValue(0)
expect(cmd.getLaunchUrlPrefix()).toBe('https://experience-stage.adobe.com/?devMode=true#/custom-apps/?localDevUrl=')
})

Expand Down
19 changes: 19 additions & 0 deletions test/__mocks__/@adobe/aio-lib-env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
Copyright 2024 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

module.exports = {
getCliEnv: jest.fn(() => {
return 'stage'
}),
PROD_ENV: 'prod',
STAGE_ENV: 'stage'
}
10 changes: 9 additions & 1 deletion test/commands/lib/audit-logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const chalk = require('chalk')
const fetch = require('node-fetch')
jest.mock('node-fetch', () => jest.fn())
const auditLogger = require('../../../src/lib/audit-logger')
const { getCliEnv } = require('@adobe/aio-lib-env')

jest.mock('fs')
jest.mock('chalk', () => ({
Expand Down Expand Up @@ -193,7 +194,14 @@ describe('getAuditLogEvent', () => {
const event = 'AB_APP_DEPLOY'
const result = auditLogger.getAuditLogEvent(flags, {}, event)

expect(result).toBeUndefined()
expect(result).toBeFalsy()
})

test('should return undefined in PROD (for now)', () => {
getCliEnv.mockReturnValueOnce('prod')
const event = 'AB_APP_DEPLOY'
const result = auditLogger.getAuditLogEvent(flags, project, event)
expect(result).toBeFalsy()
})

test('should default operation to APP_TEST if event is not found in OPERATIONS', () => {
Expand Down

0 comments on commit 769fa44

Please sign in to comment.