Skip to content

Commit

Permalink
fix(guide): remove sys error after aborting space creation (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
makinwab authored Aug 20, 2019
1 parent 9819525 commit f7bf1c5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/cmds/space_cmds/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import LoggingSystem from '../../core/event-handlers/logging'
import createSpaceIntents from '../../core/event-handlers/intents/create-space-handler'
import createSpaceLogging from '../../core/event-handlers/logging/create-space-handler'

import { AbortedError } from '../../guide/helpers'

export const command = 'create'

export const desc = 'Create a space'
Expand Down Expand Up @@ -82,8 +84,9 @@ the Pricing page: https://www.contentful.com/pricing/?faq_category=payments&faq=

if (!confirm) {
logging.log(warningStyle(`Space creation aborted.`))
return
throw new AbortedError()
}

const intentSystem = new IntentSystem()
intentSystem.addHandler(
createSpaceIntents({
Expand Down
2 changes: 1 addition & 1 deletion test/integration/cmds/space/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ test('should should abort space creation when answering no', done => {
const regex = /Space creation aborted.*/ // name doesn't matter because response is replayed
expect(resultText).toMatch(regex)
})
.code(0)
.code(1)
.end(done)
})

Expand Down
6 changes: 3 additions & 3 deletions test/unit/cmds/space_cmds/create.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { spaceUse } from '../../../../lib/cmds/space_cmds/use'
import { getContext } from '../../../../lib/context'
import { createManagementClient } from '../../../../lib/utils/contentful-clients'
import { confirmation } from '../../../../lib/utils/actions'
import { AbortedError } from '../../../../lib/guide/helpers'

jest.mock('inquirer')
jest.mock('../../../../lib/cmds/space_cmds/use')
Expand Down Expand Up @@ -144,9 +145,8 @@ test('abort space creation when saying no', async () => {
const spaceData = {
name: 'space name'
}
confirmation.mockResolvedValueOnce(false)
const result = await spaceCreate({...defaults, ...spaceData})
expect(result).toBeFalsy()
createSpaceStub.mockRejectedValueOnce(new AbortedError())
await expect(spaceCreate({...defaults, ...spaceData})).rejects.toThrowError()
expect(spaceUse).not.toHaveBeenCalled()
})

Expand Down

0 comments on commit f7bf1c5

Please sign in to comment.