Skip to content

Commit 1fd3a89

Browse files
committed
fix(customizations): Fix bug where customizations were always registered as new
1 parent 3a175df commit 1fd3a89

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import * as sinon from 'sinon'
2+
import * as assert from 'assert'
3+
import * as customizationModule from '../../../src/codewhisperer/util/customizationUtil'
4+
5+
describe('getNewCustomizations', () => {
6+
let getPersistedCustomizationsStub: sinon.SinonStub
7+
8+
const availableCustomizations = [
9+
{ arn: 'arn1', name: 'custom1' },
10+
{ arn: 'arn2', name: 'custom2' },
11+
]
12+
13+
const persistedCustomizations = [[{ arn: 'arn1', name: 'custom1' }], [{ arn: 'arn2', name: 'custom2' }]]
14+
15+
beforeEach(() => {
16+
getPersistedCustomizationsStub = sinon.stub(customizationModule, 'getPersistedCustomizations')
17+
})
18+
19+
afterEach(() => {
20+
sinon.restore()
21+
})
22+
23+
it('returns new customizations that are not in persisted customizations', () => {
24+
const customizations = [...availableCustomizations, { arn: 'arn3', name: 'custom3' }]
25+
26+
getPersistedCustomizationsStub.returns(persistedCustomizations)
27+
28+
const result = customizationModule.getNewCustomizations(customizations)
29+
30+
assert.deepEqual(result, [{ arn: 'arn3', name: 'custom3' }])
31+
sinon.assert.calledOnce(getPersistedCustomizationsStub)
32+
})
33+
34+
it('returns empty array when all available customizations are persisted', () => {
35+
getPersistedCustomizationsStub.returns(persistedCustomizations)
36+
37+
const result = customizationModule.getNewCustomizations(availableCustomizations)
38+
39+
assert.deepEqual(result.length, 0)
40+
sinon.assert.calledOnce(getPersistedCustomizationsStub)
41+
})
42+
})

0 commit comments

Comments
 (0)