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