|
| 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