From 7a5caf93264fb855b221d08d628080a86806ef00 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Mon, 15 Jul 2024 12:42:16 +0800 Subject: [PATCH 1/2] add failing test --- test/commands/app/deploy.test.js | 46 +++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/test/commands/app/deploy.test.js b/test/commands/app/deploy.test.js index 13884052..04b75f6a 100644 --- a/test/commands/app/deploy.test.js +++ b/test/commands/app/deploy.test.js @@ -239,6 +239,19 @@ test('flags', async () => { describe('run', () => { let command + /** @private */ + function createFullConfig ({ workspaceName }) { + return { + aio: { + project: { + workspace: { + name: workspaceName + } + } + } + } + } + beforeEach(() => { command = new TheCommand([]) command.error = jest.fn() @@ -250,15 +263,7 @@ describe('run', () => { command.buildOneExt = jest.fn() command.getAppExtConfigs = jest.fn() command.getLibConsoleCLI = jest.fn(() => mockLibConsoleCLI) - command.getFullConfig = jest.fn().mockReturnValue({ - aio: { - project: { - workspace: { - name: 'foo' - } - } - } - }) + command.getFullConfig = jest.fn().mockReturnValue(createFullConfig({ workspaceName: 'foo' })) mockRuntimeLib.deployActions.mockResolvedValue({ actions: [] }) mockWebLib.bundle.mockResolvedValue({ run: mockBundleFunc }) @@ -308,6 +313,28 @@ describe('run', () => { expect(command.buildOneExt).toHaveBeenCalledWith('application', appConfig.application, expect.objectContaining({ 'force-build': true, 'web-assets': false }), expect.anything()) }) + test('build & deploy only some actions using --action (workspace: Production, standalone-app: false)', async () => { + // set the workspace name in the config to Production + command.getFullConfig.mockReturnValue(createFullConfig({ workspaceName: 'Production' })) + + // make it not a standalone-app + const appConfig = createAppConfig(command.appConfig, 'app-exc-nui') + command.getAppExtConfigs.mockResolvedValueOnce(appConfig) + + command.argv = ['--action', 'c'] + await command.run() + expect(command.error).toHaveBeenCalledTimes(0) + expect(mockRuntimeLib.deployActions).toHaveBeenCalledTimes(1) + expect(mockWebLib.deployWeb).toHaveBeenCalledTimes(0) + expect(command.buildOneExt).toHaveBeenCalledTimes(1) + expect(mockLibConsoleCLI.getApplicationExtensions).toHaveBeenCalledTimes(0) + + expect(mockRuntimeLib.deployActions).toHaveBeenCalledWith(appConfig.application, { + filterEntities: { actions: ['c'] } + }, + expect.any(Function)) + }) + test('build & deploy only some actions using --action', async () => { const appConfig = createAppConfig(command.appConfig) command.getAppExtConfigs.mockResolvedValueOnce(appConfig) @@ -318,6 +345,7 @@ describe('run', () => { expect(mockRuntimeLib.deployActions).toHaveBeenCalledTimes(1) expect(mockWebLib.deployWeb).toHaveBeenCalledTimes(0) expect(command.buildOneExt).toHaveBeenCalledTimes(1) + expect(mockLibConsoleCLI.getApplicationExtensions).toHaveBeenCalledTimes(0) expect(command.buildOneExt).toHaveBeenCalledWith('application', appConfig.application, expect.objectContaining({ 'force-build': true, 'web-assets': false, action: ['a', 'b', 'c'] }), expect.anything()) expect(mockRuntimeLib.deployActions).toHaveBeenCalledWith(appConfig.application, { From 9098f3bd276c98b866bf64f8612e6b2e64d46918 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Mon, 15 Jul 2024 14:45:32 +0800 Subject: [PATCH 2/2] fix failing test --- src/commands/app/deploy.js | 17 +++++----- test/commands/app/deploy.test.js | 54 ++++++++++++++++---------------- 2 files changed, 35 insertions(+), 36 deletions(-) diff --git a/src/commands/app/deploy.js b/src/commands/app/deploy.js index 2f54fabc..7094a9c2 100644 --- a/src/commands/app/deploy.js +++ b/src/commands/app/deploy.js @@ -41,11 +41,6 @@ class Deploy extends BuildCommand { // if there are no extensions, then set publish to false flags.publish = flags.publish && !isStandaloneApp - let libConsoleCLI // <= this can be undefined later on, and it was not checked - if (flags.publish) { - // force login at beginning (if required) - libConsoleCLI = await this.getLibConsoleCLI() - } if ( (!flags.publish && !flags['web-assets'] && !flags.actions) @@ -86,7 +81,7 @@ class Deploy extends BuildCommand { // 2. If workspace is prod and has extensions, check if the app is published if (!isStandaloneApp && aioConfig?.project?.workspace?.name === 'Production') { - const extension = await this.getApplicationExtension(libConsoleCLI, aioConfig) + const extension = await this.getApplicationExtension(aioConfig) if (extension && extension.status === 'PUBLISHED') { flags.publish = false // if the app is production and published, then skip publish later on // if the app is published and no force-deploy flag is set, then skip deployment @@ -109,7 +104,7 @@ class Deploy extends BuildCommand { // 4. deploy extension manifest if (flags.publish) { - const payload = await this.publishExtensionPoints(libConsoleCLI, deployConfigs, aioConfig, flags['force-publish']) + const payload = await this.publishExtensionPoints(deployConfigs, aioConfig, flags['force-publish']) this.log(chalk.blue(chalk.bold(`New Extension Point(s) in Workspace '${aioConfig.project.workspace.name}': '${Object.keys(payload.endpoints)}'`))) } else { this.log('skipping publish phase...') @@ -263,7 +258,9 @@ class Deploy extends BuildCommand { } } - async publishExtensionPoints (libConsoleCLI, deployConfigs, aioConfig, force) { + async publishExtensionPoints (deployConfigs, aioConfig, force) { + const libConsoleCLI = await this.getLibConsoleCLI() + const payload = buildExtensionPointPayloadWoMetadata(deployConfigs) // build metadata if (payload.endpoints['dx/excshell/1'] && payload.endpoints['dx/excshell/1'].view) { @@ -281,7 +278,9 @@ class Deploy extends BuildCommand { return newPayload } - async getApplicationExtension (libConsoleCLI, aioConfig) { + async getApplicationExtension (aioConfig) { + const libConsoleCLI = await this.getLibConsoleCLI() + const { appId } = await libConsoleCLI.getProject(aioConfig.project.org.id, aioConfig.project.id) const applicationExtensions = await libConsoleCLI.getApplicationExtensions(aioConfig.project.org.id, appId) return applicationExtensions.find(extension => extension.appId === appId) diff --git a/test/commands/app/deploy.test.js b/test/commands/app/deploy.test.js index 04b75f6a..efa8288b 100644 --- a/test/commands/app/deploy.test.js +++ b/test/commands/app/deploy.test.js @@ -239,18 +239,6 @@ test('flags', async () => { describe('run', () => { let command - /** @private */ - function createFullConfig ({ workspaceName }) { - return { - aio: { - project: { - workspace: { - name: workspaceName - } - } - } - } - } beforeEach(() => { command = new TheCommand([]) @@ -263,7 +251,15 @@ describe('run', () => { command.buildOneExt = jest.fn() command.getAppExtConfigs = jest.fn() command.getLibConsoleCLI = jest.fn(() => mockLibConsoleCLI) - command.getFullConfig = jest.fn().mockReturnValue(createFullConfig({ workspaceName: 'foo' })) + command.getFullConfig = jest.fn().mockReturnValue({ + aio: { + project: { + workspace: { + name: 'foo' + } + } + } + }) mockRuntimeLib.deployActions.mockResolvedValue({ actions: [] }) mockWebLib.bundle.mockResolvedValue({ run: mockBundleFunc }) @@ -313,26 +309,30 @@ describe('run', () => { expect(command.buildOneExt).toHaveBeenCalledWith('application', appConfig.application, expect.objectContaining({ 'force-build': true, 'web-assets': false }), expect.anything()) }) - test('build & deploy only some actions using --action (workspace: Production, standalone-app: false)', async () => { - // set the workspace name in the config to Production - command.getFullConfig.mockReturnValue(createFullConfig({ workspaceName: 'Production' })) - - // make it not a standalone-app - const appConfig = createAppConfig(command.appConfig, 'app-exc-nui') - command.getAppExtConfigs.mockResolvedValueOnce(appConfig) + test('build & deploy only one action using --action (workspace: Production)', async () => { + command.getAppExtConfigs.mockResolvedValueOnce(createAppConfig(command.appConfig, 'exc')) + mockGetExtensionPointsRetractedApp() // not published + mockGetProject() + command.getFullConfig.mockResolvedValue({ + aio: { + project: { + workspace: { + name: 'Production' + }, + org: { + id: '1111' + } + } + } + }) - command.argv = ['--action', 'c'] + command.argv = ['--no-web-assets', '--action', 'c'] await command.run() expect(command.error).toHaveBeenCalledTimes(0) expect(mockRuntimeLib.deployActions).toHaveBeenCalledTimes(1) expect(mockWebLib.deployWeb).toHaveBeenCalledTimes(0) expect(command.buildOneExt).toHaveBeenCalledTimes(1) - expect(mockLibConsoleCLI.getApplicationExtensions).toHaveBeenCalledTimes(0) - - expect(mockRuntimeLib.deployActions).toHaveBeenCalledWith(appConfig.application, { - filterEntities: { actions: ['c'] } - }, - expect.any(Function)) + expect(mockLibConsoleCLI.getApplicationExtensions).toHaveBeenCalledTimes(1) }) test('build & deploy only some actions using --action', async () => {