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

Handle Undeploy for UI only apps #170

Merged
merged 14 commits into from
Mar 9, 2020
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
7 changes: 6 additions & 1 deletion src/commands/app/undeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ governing permissions and limitations under the License.

const ora = require('ora')
const chalk = require('chalk')
const fs = require('fs-extra')
// const path = require('path')

const { flags } = require('@oclif/command')
Expand Down Expand Up @@ -59,7 +60,11 @@ class Undeploy extends BaseCommand {

// undeploy
if (!flags.static) {
await scripts.undeployActions()
if (fs.existsSync('manifest.yml')) {
await scripts.undeployActions()
} else {
this.log('no action src, skipping action undeploy')
}
}
if (!flags.actions) {
await scripts.undeployUI()
Expand Down
19 changes: 14 additions & 5 deletions test/commands/app/undeploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ governing permissions and limitations under the License.
const TheCommand = require('../../../src/commands/app/undeploy')
const BaseCommand = require('../../../src/BaseCommand')

const mockFS = require('fs-extra')

// mocks
const mockScripts = require('@adobe/aio-app-scripts')()

beforeEach(() => {
mockFS.existsSync.mockReset()
jest.restoreAllMocks()
})

Expand Down Expand Up @@ -48,6 +51,7 @@ test('flags', async () => {
describe('run', () => {
let command
beforeEach(() => {
mockFS.existsSync.mockReset()
command = new TheCommand([])
command.error = jest.fn()
})
Expand All @@ -57,13 +61,15 @@ describe('run', () => {
})

test('undeploy an App with no flags', async () => {
mockFS.existsSync.mockReturnValue(true)
await command.run()
expect(command.error).toHaveBeenCalledTimes(0)
expect(mockScripts.undeployActions).toHaveBeenCalledTimes(1)
expect(mockScripts.undeployUI).toHaveBeenCalledTimes(1)
})

test('undeploy an App with --verbose', async () => {
mockFS.existsSync.mockReturnValue(true)
command.argv = ['-v']
await command.run()
expect(command.error).toHaveBeenCalledTimes(0)
Expand All @@ -72,6 +78,7 @@ describe('run', () => {
})

test('undeploy only actions', async () => {
mockFS.existsSync.mockReturnValue(true)
command.argv = ['-a']
await command.run()
expect(command.error).toHaveBeenCalledTimes(0)
Expand All @@ -80,6 +87,7 @@ describe('run', () => {
})

test('undeploy only actions --verbose', async () => {
mockFS.existsSync.mockReturnValue(true)
command.argv = ['-a']
await command.run()
expect(command.error).toHaveBeenCalledTimes(0)
Expand All @@ -104,18 +112,19 @@ describe('run', () => {
})

test('should fail if scripts.undeployActions fails', async () => {
mockFS.existsSync.mockReturnValue(true)
const error = new Error('mock failure')
mockScripts.undeployActions.mockRejectedValue(error)
await command.run()
expect(command.error).toHaveBeenCalledWith(error)
expect(mockScripts.undeployActions).toHaveBeenCalledTimes(1)
})

test('should fail if scripts.undeployUI fails', async () => {
const error = new Error('mock failure')
mockScripts.undeployUI.mockRejectedValue(error)
test('undeploy an App with no backend', async () => {
mockFS.existsSync.mockReturnValue(false)
await command.run()
expect(command.error).toHaveBeenCalledWith(error)
expect(mockScripts.undeployUI).toHaveBeenCalledTimes(0)
expect(command.error).toHaveBeenCalledTimes(0)
expect(mockScripts.undeployActions).toHaveBeenCalledTimes(0)
expect(mockScripts.undeployUI).toHaveBeenCalledTimes(1)
})
})