Skip to content

Commit

Permalink
test(unit): make extensions tests work without .contentfulrc.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Benedikt Rötsch authored and axe312ger committed Jan 18, 2018
1 parent 23ca1e9 commit bbc2bc1
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 4 deletions.
10 changes: 10 additions & 0 deletions test/unit/cmds/extension_cmds/create.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import test from 'ava'
import { stub } from 'sinon'

import {
emptyContext,
setContext
} from '../../../../lib/context'
import { successEmoji } from '../../../../lib/utils/emojis'

import {
Expand Down Expand Up @@ -38,6 +42,12 @@ test.before(() => {
}
const createManagementClientStub = stub().returns(fakeClient)

emptyContext()
setContext({
cmaToken: 'mockedToken',
activeSpaceId: 'someSpaceId'
})

createRewireAPI.__Rewire__('createManagementClient', createManagementClientStub)
createRewireAPI.__Rewire__('success', successStub)
logRewireAPI.__Rewire__('log', logStub)
Expand Down
10 changes: 10 additions & 0 deletions test/unit/cmds/extension_cmds/delete.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import test from 'ava'
import { stub } from 'sinon'

import {
emptyContext,
setContext
} from '../../../../lib/context'
import { successEmoji } from '../../../../lib/utils/emojis'

import {
Expand All @@ -25,6 +29,12 @@ test.before(() => {
}
const createManagementClientStub = stub().returns(fakeClient)

emptyContext()
setContext({
cmaToken: 'mockedToken',
activeSpaceId: 'someSpaceId'
})

deleteRewireAPI.__Rewire__('createManagementClient', createManagementClientStub)
deleteRewireAPI.__Rewire__('success', successStub)
})
Expand Down
11 changes: 10 additions & 1 deletion test/unit/cmds/extension_cmds/get.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
handler,
__RewireAPI__ as getRewireAPI
} from '../../../../lib/cmds/extension_cmds/get'

import {
emptyContext,
setContext
} from '../../../../lib/context'
import {
__RewireAPI__ as logRewireAPI
} from '../../../../lib/cmds/extension_cmds/utils/log-as-table'
Expand All @@ -30,6 +33,12 @@ test.before(() => {
}
const createManagementClientStub = stub().returns(fakeClient)

emptyContext()
setContext({
cmaToken: 'mockedToken',
activeSpaceId: 'someSpaceId'
})

getRewireAPI.__Rewire__('createManagementClient', createManagementClientStub)
logRewireAPI.__Rewire__('log', logStub)
})
Expand Down
14 changes: 12 additions & 2 deletions test/unit/cmds/extension_cmds/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import {
handler,
__RewireAPI__ as rewireAPI
} from '../../../../lib/cmds/extension_cmds/list'
import {
emptyContext,
setContext
} from '../../../../lib/context'

const logStub = stub()
const getSpaceStub = stub()
Expand Down Expand Up @@ -39,6 +43,12 @@ test.before(() => {

const createManagementClientStub = stub().returns(fakeClient)

emptyContext()
setContext({
cmaToken: 'mockedToken',
activeSpaceId: 'someSpaceId'
})

rewireAPI.__Rewire__('createManagementClient', createManagementClientStub)
rewireAPI.__Rewire__('log', logStub)
})
Expand All @@ -48,7 +58,7 @@ test.after.always(() => {
rewireAPI.__ResetDependency__('log')
})

test('Lists extensions', async (t) => {
test.serial('Lists extensions', async (t) => {
await handler({spaceId: 'space'})

const outputValues = [ 'Widget', '123', 'Widget 2', '456' ]
Expand All @@ -58,7 +68,7 @@ test('Lists extensions', async (t) => {
})
})

test('Displays message if list is empty', async (t) => {
test.serial('Displays message if list is empty', async (t) => {
await handler({spaceId: 'empty-space'})

t.true(logStub.calledWith('No extensions found'))
Expand Down
11 changes: 10 additions & 1 deletion test/unit/cmds/extension_cmds/update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import {
updateExtension,
__RewireAPI__ as rewireAPI
} from '../../../../lib/cmds/extension_cmds/update'

import {
emptyContext,
setContext
} from '../../../../lib/context'
import { ValidationError } from '../../../../lib/utils/error'

const updateStub = stub()
Expand All @@ -32,6 +35,12 @@ test.before(() => {
}
const createManagementClientStub = stub().returns(fakeClient)

emptyContext()
setContext({
cmaToken: 'mockedToken',
activeSpaceId: 'someSpaceId'
})

rewireAPI.__Rewire__('createManagementClient', createManagementClientStub)
rewireAPI.__Rewire__('logExtension', logStub)
rewireAPI.__Rewire__('success', successStub)
Expand Down

0 comments on commit bbc2bc1

Please sign in to comment.