-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
85 additions
and
11 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import sinon from 'sinon'; | ||
import { expect } from 'chai'; | ||
import { CGX } from './cgx'; | ||
import * as logger from './utils/logger.util'; | ||
import * as questions from './questions'; | ||
import { ProviderValue, Answer, LicenseValue } from './models/choice'; | ||
import * as actions from './actions'; | ||
import Bluebird from 'bluebird'; | ||
|
||
describe('src/cgx', () => { | ||
let sandbox: sinon.SinonSandbox; | ||
let showTitleAndBannerStub: sinon.SinonStub; | ||
let providerQuestionStub: sinon.SinonStub; | ||
|
||
const mockAnswer: Answer = { | ||
files: {}, | ||
userName: 'someUser', | ||
licenses: LicenseValue.MIT, | ||
provider: ProviderValue.GITHUB, | ||
overwrite: false, | ||
} | ||
beforeEach(() => { | ||
sandbox = sinon.createSandbox(); | ||
showTitleAndBannerStub = sandbox.stub(logger, 'showTitleAndBanner'); | ||
}); | ||
|
||
afterEach(() => { | ||
sandbox.restore(); | ||
}); | ||
|
||
it('should always call showTitleAndBanner and providerQuestion', async () => { | ||
providerQuestionStub = sandbox.stub(questions, 'providerQuestion').resolves(mockAnswer); | ||
await CGX(); | ||
expect(showTitleAndBannerStub).to.be.calledOnce; | ||
expect(providerQuestionStub).to.be.calledOnce; | ||
}); | ||
const cases = [ | ||
{ | ||
name: 'gitlab', | ||
provider: ProviderValue.GITLAB, | ||
stub: sinon.stub(actions, 'gitlabActions'), | ||
function: actions.gitlabActions, | ||
}, | ||
{ | ||
name: 'github', | ||
provider: ProviderValue.GITHUB, | ||
stub: sinon.stub(actions, 'githubActions'), | ||
function: actions.githubActions, | ||
}, | ||
{ | ||
name: 'bitbucket', | ||
provider: ProviderValue.BITBUCKET, | ||
stub: sinon.stub(actions, 'bitbucketActions'), | ||
function: actions.bitbucketActions, | ||
}, | ||
{ | ||
name: 'codecommit', | ||
provider: ProviderValue.CODECOMMIT, | ||
stub: sinon.stub(actions, 'codecommitActions'), | ||
function: actions.codecommitActions, | ||
}, | ||
]; | ||
Bluebird.each(cases, (caseItem) => { | ||
it(`should return ${caseItem.name} actions if the choice is made for it`, async () => { | ||
sandbox = sinon.createSandbox(); | ||
mockAnswer.provider = caseItem.provider; | ||
showTitleAndBannerStub = sandbox.stub(logger, 'showTitleAndBanner'); | ||
providerQuestionStub = sandbox.stub(questions, 'providerQuestion').resolves(mockAnswer); | ||
const cgx: Promise<any> = await CGX(); | ||
expect(caseItem.stub).to.be.calledOnce; | ||
expect(cgx).to.be.equal(caseItem.function()) | ||
sandbox.restore(); | ||
}) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,3 @@ | |
"trailing-comma": [true, {"multiline": "always", "singleline": "never"}] | ||
} | ||
} | ||
|