Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: ACNA-3024 - deploy single action error #808

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/commands/app/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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...')
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions test/commands/app/deploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ test('flags', async () => {

describe('run', () => {
let command

beforeEach(() => {
command = new TheCommand([])
command.error = jest.fn()
Expand Down Expand Up @@ -308,6 +309,32 @@ describe('run', () => {
expect(command.buildOneExt).toHaveBeenCalledWith('application', appConfig.application, expect.objectContaining({ 'force-build': true, 'web-assets': false }), expect.anything())
})

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 = ['--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(1)
})

test('build & deploy only some actions using --action', async () => {
const appConfig = createAppConfig(command.appConfig)
command.getAppExtConfigs.mockResolvedValueOnce(appConfig)
Expand All @@ -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, {
Expand Down