|
| 1 | +/* |
| 2 | +Copyright 2021 Adobe. All rights reserved. |
| 3 | +This file is licensed to you under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. You may obtain a copy |
| 5 | +of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +
|
| 7 | +Unless required by applicable law or agreed to in writing, software distributed under |
| 8 | +the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS |
| 9 | +OF ANY KIND, either express or implied. See the License for the specific language |
| 10 | +governing permissions and limitations under the License. |
| 11 | +*/ |
| 12 | + |
| 13 | +const { init, mockSdk } = require('@adobe/aio-lib-cloudmanager') |
| 14 | +const { resetCurrentOrgId, setCurrentOrgId } = require('@adobe/aio-lib-ims') |
| 15 | +const InvalidatePipelineCacheCommand = require('../../../src/commands/cloudmanager/pipeline/invalidate-cache') |
| 16 | + |
| 17 | +beforeEach(() => { |
| 18 | + resetCurrentOrgId() |
| 19 | +}) |
| 20 | + |
| 21 | +test('invalidate-cache - missing arg', async () => { |
| 22 | + expect.assertions(2) |
| 23 | + |
| 24 | + const runResult = InvalidatePipelineCacheCommand.run([]) |
| 25 | + await expect(runResult instanceof Promise).toBeTruthy() |
| 26 | + await expect(runResult).rejects.toThrow(/^Missing 1 required arg/) |
| 27 | +}) |
| 28 | + |
| 29 | +test('invalidate-cache - missing config', async () => { |
| 30 | + expect.assertions(2) |
| 31 | + |
| 32 | + const runResult = InvalidatePipelineCacheCommand.run(['--programId', '5', '10']) |
| 33 | + await expect(runResult instanceof Promise).toBeTruthy() |
| 34 | + await expect(runResult).rejects.toThrow('[CloudManagerCLI:NO_IMS_CONTEXT] Unable to find IMS context aio-cli-plugin-cloudmanager.') |
| 35 | +}) |
| 36 | + |
| 37 | +test('invalidate-cache - configured', async () => { |
| 38 | + setCurrentOrgId('good') |
| 39 | + |
| 40 | + expect.assertions(5) |
| 41 | + |
| 42 | + const runResult = InvalidatePipelineCacheCommand.run(['--programId', '5', '7']) |
| 43 | + await expect(runResult instanceof Promise).toBeTruthy() |
| 44 | + await runResult |
| 45 | + await expect(init.mock.calls.length).toEqual(1) |
| 46 | + await expect(init).toHaveBeenCalledWith('good', 'test-client-id', 'fake-token', 'https://cloudmanager.adobe.io') |
| 47 | + await expect(mockSdk.invalidatePipelineCache.mock.calls.length).toEqual(1) |
| 48 | + await expect(mockSdk.invalidatePipelineCache).toHaveBeenCalledWith('5', '7') |
| 49 | +}) |
0 commit comments