Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion packages/core/src/codewhisperer/util/customizationUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ export const onProfileChangedListener: (event: ProfileChangedEvent) => any = asy
*/
export const getNewCustomizations = (availableCustomizations: Customization[]) => {
const persistedCustomizations = getPersistedCustomizations()
return availableCustomizations.filter((c) => !persistedCustomizations.map((p) => p.arn).includes(c.arn))
const newCustomizations = availableCustomizations.filter(
(c) =>
!persistedCustomizations
.flat()
.map((p) => p.arn)
.includes(c.arn)
)
return newCustomizations
}

export async function notifyNewCustomizations() {
Expand Down
42 changes: 42 additions & 0 deletions packages/core/src/test/codewhisperer/customizationUtil.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as sinon from 'sinon'

Check failure on line 1 in packages/core/src/test/codewhisperer/customizationUtil.test.ts

View workflow job for this annotation

GitHub Actions / lint (18.x, stable)

missing header
import * as assert from 'assert'
import * as customizationModule from '../../../src/codewhisperer/util/customizationUtil'

describe('getNewCustomizations', () => {
let getPersistedCustomizationsStub: sinon.SinonStub

const availableCustomizations = [
{ arn: 'arn1', name: 'custom1' },
{ arn: 'arn2', name: 'custom2' },
]

const persistedCustomizations = [[{ arn: 'arn1', name: 'custom1' }], [{ arn: 'arn2', name: 'custom2' }]]

beforeEach(() => {
getPersistedCustomizationsStub = sinon.stub(customizationModule, 'getPersistedCustomizations')
})

afterEach(() => {
sinon.restore()
})

it('returns new customizations that are not in persisted customizations', () => {
const customizations = [...availableCustomizations, { arn: 'arn3', name: 'custom3' }]

getPersistedCustomizationsStub.returns(persistedCustomizations)

const result = customizationModule.getNewCustomizations(customizations)

assert.deepEqual(result, [{ arn: 'arn3', name: 'custom3' }])
sinon.assert.calledOnce(getPersistedCustomizationsStub)
})

it('returns empty array when all available customizations are persisted', () => {
getPersistedCustomizationsStub.returns(persistedCustomizations)

const result = customizationModule.getNewCustomizations(availableCustomizations)

assert.deepEqual(result.length, 0)
sinon.assert.calledOnce(getPersistedCustomizationsStub)
})
})
Loading