Skip to content

Commit 813efa0

Browse files
authored
fix(customizations): Fix bug where customizations were always registered as new (#7352)
## Problem All cached customizations are always marked as new, so a notification for new customizations always appears when switching profiles. ## Solution Fix the bug by flattening the cached customization array and add some unit tests --- - Treat all work as PUBLIC. Private `feature/x` branches will not be squash-merged at release time. - Your code changes must meet the guidelines in [CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines). - License: I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 3a175df commit 813efa0

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

packages/core/src/codewhisperer/util/customizationUtil.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ export const onProfileChangedListener: (event: ProfileChangedEvent) => any = asy
8989
*/
9090
export const getNewCustomizations = (availableCustomizations: Customization[]) => {
9191
const persistedCustomizations = getPersistedCustomizations()
92-
return availableCustomizations.filter((c) => !persistedCustomizations.map((p) => p.arn).includes(c.arn))
92+
const newCustomizations = availableCustomizations.filter(
93+
(c) =>
94+
!persistedCustomizations
95+
.flat()
96+
.map((p) => p.arn)
97+
.includes(c.arn)
98+
)
99+
return newCustomizations
93100
}
94101

95102
export async function notifyNewCustomizations() {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import * as sinon from 'sinon'
7+
import * as assert from 'assert'
8+
import * as customizationModule from '../../../src/codewhisperer/util/customizationUtil'
9+
10+
describe('getNewCustomizations', () => {
11+
let getPersistedCustomizationsStub: sinon.SinonStub
12+
13+
const availableCustomizations = [
14+
{ arn: 'arn1', name: 'custom1' },
15+
{ arn: 'arn2', name: 'custom2' },
16+
]
17+
18+
const persistedCustomizations = [[{ arn: 'arn1', name: 'custom1' }], [{ arn: 'arn2', name: 'custom2' }]]
19+
20+
beforeEach(() => {
21+
getPersistedCustomizationsStub = sinon.stub(customizationModule, 'getPersistedCustomizations')
22+
})
23+
24+
afterEach(() => {
25+
sinon.restore()
26+
})
27+
28+
it('returns new customizations that are not in persisted customizations', () => {
29+
const customizations = [...availableCustomizations, { arn: 'arn3', name: 'custom3' }]
30+
31+
getPersistedCustomizationsStub.returns(persistedCustomizations)
32+
33+
const result = customizationModule.getNewCustomizations(customizations)
34+
35+
assert.deepEqual(result, [{ arn: 'arn3', name: 'custom3' }])
36+
sinon.assert.calledOnce(getPersistedCustomizationsStub)
37+
})
38+
39+
it('returns empty array when all available customizations are persisted', () => {
40+
getPersistedCustomizationsStub.returns(persistedCustomizations)
41+
42+
const result = customizationModule.getNewCustomizations(availableCustomizations)
43+
44+
assert.deepEqual(result.length, 0)
45+
sinon.assert.calledOnce(getPersistedCustomizationsStub)
46+
})
47+
})

0 commit comments

Comments
 (0)