Skip to content

Commit d7fc4cb

Browse files
committed
test: migrate pipelines/add to @oclif/test v4
1 parent 548ee0c commit d7fc4cb

File tree

2 files changed

+122
-123
lines changed

2 files changed

+122
-123
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
import {expect} from 'chai'
2+
import inquirer from 'inquirer'
3+
import nock from 'nock'
4+
import sinon from 'sinon'
5+
import {stderr, stdout} from 'stdout-stderr'
6+
import runCommandHelper from '../../../helpers/runCommand.js'
7+
import AddCommand from '../../../../src/commands/pipelines/add.js'
8+
9+
describe('pipelines:add', function () {
10+
afterEach(function () {
11+
sinon.restore()
12+
nock.cleanAll()
13+
})
14+
15+
it('adds a pipeline', async function () {
16+
const coupling = {id: '0123', stage: 'production'}
17+
const pipeline = {id: '0123', name: 'example-pipeline'}
18+
const pipelines = [pipeline]
19+
20+
nock('https://api.heroku.com')
21+
.post('/pipeline-couplings')
22+
.reply(201, coupling)
23+
.get('/pipelines')
24+
.query(true)
25+
.reply(200, pipelines)
26+
27+
await runCommandHelper(AddCommand, [
28+
'--app',
29+
'example-app',
30+
'--stage',
31+
'production',
32+
'example-pipeline',
33+
])
34+
35+
expect(stdout.output).to.equal('')
36+
expect(stderr.output).to.contain('Adding ⬢ example-app to example-pipeline pipeline as production... done')
37+
})
38+
39+
it('adds a pipeline with stage specified from prompt', async function () {
40+
// this `stub` overrides the prompt function on
41+
// the inquirer package to simulate what would be
42+
// returned from answering if "development" was
43+
// selected by the user
44+
sinon.stub(inquirer, 'prompt').callsFake(function (questions: any) {
45+
if (questions[0].name === 'stage') {
46+
return Promise.resolve({stage: 'development'})
47+
}
48+
49+
return Promise.resolve({})
50+
})
51+
52+
const coupling = {id: '0123', stage: 'development'}
53+
const pipeline = {id: '0123', name: 'example-pipeline'}
54+
const pipelines = [pipeline]
55+
56+
nock('https://api.heroku.com')
57+
.post('/pipeline-couplings')
58+
.reply(201, coupling)
59+
.get('/pipelines')
60+
.query(true)
61+
.reply(200, pipelines)
62+
63+
await runCommandHelper(AddCommand, [
64+
'--app',
65+
'example-app',
66+
'example-pipeline',
67+
])
68+
69+
expect(stdout.output).to.equal('')
70+
expect(stderr.output).to.contain('Adding ⬢ example-app to example-pipeline pipeline as development... done')
71+
})
72+
73+
it('adds a pipeline by disambiguating by user choice of identically named pipelines', async function () {
74+
// this `stub` overrides the prompt function,
75+
// simulating that the user picked the identical
76+
// pipeline value with id: '0987' for the pipeline
77+
// question
78+
sinon.stub(inquirer, 'prompt').callsFake(function (questions: any) {
79+
const question = questions[0]
80+
81+
if (question && question.name === 'pipeline') {
82+
return Promise.resolve({pipeline: {
83+
name: 'pipeline-with-identical-name-to-another-pipeline',
84+
id: '0987',
85+
}})
86+
}
87+
88+
return Promise.resolve({})
89+
})
90+
91+
const coupling = {id: '0123', stage: 'development'}
92+
93+
const firstIdenticallyNamedPipeline = {id: '0123', name: 'pipeline-with-identical-name-to-another-pipeline'}
94+
const secondIdenticallyNamedPipeline = {id: '0987', name: 'pipeline-with-identical-name-to-another-pipeline'}
95+
96+
// by returning to a query for pipeline names with
97+
// multiple results we trigger a choice from the
98+
// user to disambiguate between the choices
99+
const pipelinesWithIdenticalNames = [
100+
firstIdenticallyNamedPipeline,
101+
secondIdenticallyNamedPipeline,
102+
]
103+
104+
nock('https://api.heroku.com')
105+
.post('/pipeline-couplings')
106+
.reply(201, coupling)
107+
.get('/pipelines')
108+
.query({eq: {name: 'pipeline-with-identical-name-to-another-pipeline'}})
109+
.reply(200, pipelinesWithIdenticalNames)
110+
111+
await runCommandHelper(AddCommand, [
112+
'--app',
113+
'example-app',
114+
'--stage',
115+
'staging',
116+
'pipeline-with-identical-name-to-another-pipeline',
117+
])
118+
119+
expect(stdout.output).to.equal('')
120+
expect(stderr.output).to.contain('Adding ⬢ example-app to pipeline-with-identical-name-to-another-pipeline pipeline as staging... done')
121+
})
122+
})

packages/cli/test/unit/commands/pipelines/add.unit.test.ts.skip

Lines changed: 0 additions & 123 deletions
This file was deleted.

0 commit comments

Comments
 (0)