Skip to content

Commit 1d23c20

Browse files
committed
fix(test): Add test for error handling
1 parent 3cf000a commit 1d23c20

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

test/run-contentful-export-test.js

+21-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import test from 'tape'
22
import sinon from 'sinon'
33
import Promise from 'bluebird'
44
import runContentfulExport from '../lib/run-contentful-export'
5-
5+
import dumpErrorBuffer from '../lib/dump-error-buffer'
66
const fullSpaceResponse = {
77
'contentTypes': [],
88
'entries': [],
@@ -16,22 +16,40 @@ runContentfulExport.__Rewire__('createClients', createClientsStub)
1616
const getFullSourceSpaceStub = sinon.stub().returns(Promise.resolve(fullSpaceResponse))
1717
runContentfulExport.__Rewire__('getFullSourceSpace', getFullSourceSpaceStub)
1818

19+
const getFullSourceSpaceWithErrorStub = sinon.stub().returns(Promise.reject({request: {uri: 'erroruri'}}))
1920
const fsMock = {
2021
writeFile: sinon.stub().returns(Promise.resolve())
2122
}
2223
runContentfulExport.__Rewire__('fs', fsMock)
24+
dumpErrorBuffer.__Rewire__('fs', fsMock)
25+
const dumpErrorBufferStub = sinon.stub()
26+
runContentfulExport.__Rewire__('dumpErrorBuffer', dumpErrorBufferStub)
2327

24-
test('Runs space sync', (t) => {
28+
test('Runs Contentful Export', (t) => {
2529
runContentfulExport({
2630
opts: {},
2731
errorLogFile: 'errorlogfile'
2832
})
2933
.then(() => {
3034
t.ok(createClientsStub.called, 'create clients')
3135
t.ok(getFullSourceSpaceStub.called, 'get full space')
36+
runContentfulExport.__ResetDependency__('getFullSourceSpace')
37+
t.end()
38+
})
39+
})
3240

33-
runContentfulExport.__ResetDependency__('createClients')
41+
test('Runs Contentful fails', (t) => {
42+
runContentfulExport.__Rewire__('getFullSourceSpace', getFullSourceSpaceWithErrorStub)
43+
runContentfulExport({
44+
opts: {},
45+
errorLogFile: 'errorlogfile'
46+
})
47+
.then(() => {})
48+
.catch(() => {
49+
t.ok(dumpErrorBufferStub.called)
3450
runContentfulExport.__ResetDependency__('getFullSourceSpace')
51+
runContentfulExport.__ResetDependency__('createClients')
52+
runContentfulExport.__ResetDependency__('dumpErrorBuffer')
3553
t.end()
3654
})
3755
})

0 commit comments

Comments
 (0)