1+ import { runCommand } from '@heroku-cli/test-utils'
12import { expect } from 'chai'
23import nock from 'nock'
34import {
@@ -8,7 +9,7 @@ import {join} from 'node:path'
89
910import Pull from '../../src/commands/devcenter/pull.js'
1011import { netrcFilePath } from '../helpers/netrc-path.js'
11- import { runCommand } from '../helpers/run-command .js'
12+ import { PLUGIN_ROOT } from '../helpers/plugin-root .js'
1213import {
1314 applyHomeEnv , type HomeEnvSnapshot , setHomeDirForTests , snapshotHomeEnv ,
1415} from '../helpers/test-home-env.js'
@@ -52,15 +53,15 @@ describe('devcenter:pull', function () {
5253
5354 it ( 'writes a local markdown file from the Dev Center API' , async function ( ) {
5455 nock ( 'https://devcenter.heroku.com' )
55- . get ( '/articles/acme.json' )
56- . reply ( 200 , {
57- content : 'Article **body**.' ,
58- id : 7 ,
59- slug : 'acme' ,
60- title : 'Acme Co' ,
61- } )
62-
63- const { error} = await runCommand ( Pull , [ 'acme' , '--force' ] )
56+ . get ( '/articles/acme.json' )
57+ . reply ( 200 , {
58+ content : 'Article **body**.' ,
59+ id : 7 ,
60+ slug : 'acme' ,
61+ title : 'Acme Co' ,
62+ } )
63+
64+ const { error} = await runCommand ( Pull , [ 'acme' , '--force' ] , { root : PLUGIN_ROOT } )
6465 expect ( error ) . to . equal ( undefined )
6566
6667 const written = readFileSync ( join ( workDir , 'acme.md' ) , 'utf8' )
@@ -71,16 +72,16 @@ describe('devcenter:pull', function () {
7172 it ( 'errors when the article cannot be loaded' , async function ( ) {
7273 nock ( 'https://devcenter.heroku.com' ) . get ( '/articles/nope.json' ) . reply ( 404 , { } )
7374 nock ( 'https://devcenter.heroku.com' )
74- . get ( '/api/v1/search.json' )
75- . query ( { query : 'nope' } )
76- . reply ( 200 , { results : [ ] } )
75+ . get ( '/api/v1/search.json' )
76+ . query ( { query : 'nope' } )
77+ . reply ( 200 , { results : [ ] } )
7778
78- const { error} = await runCommand ( Pull , [ 'nope' , '--force' ] )
79+ const { error} = await runCommand ( Pull , [ 'nope' , '--force' ] , { root : PLUGIN_ROOT } )
7980 expect ( error ?. message ) . to . contain ( 'No nope article found' )
8081 } )
8182
8283 it ( 'errors when slug is empty after parsing' , async function ( ) {
83- const { error} = await runCommand ( Pull , [ ' ' ] )
84+ const { error} = await runCommand ( Pull , [ ' ' ] , { root : PLUGIN_ROOT } )
8485 expect ( error ?. message ) . to . contain ( 'Please provide an article slug' )
8586 } )
8687
@@ -99,15 +100,15 @@ describe('devcenter:pull', function () {
99100 nock ( 'https://devcenter.heroku.com' , {
100101 reqheaders : { authorization : `Basic ${ Buffer . from ( token ) . toString ( 'base64' ) } ` } ,
101102 } )
102- . get ( '/articles/draftish.json' )
103- . reply ( 200 , {
104- content : 'Draft **body**.' ,
105- id : 99 ,
106- slug : 'draftish' ,
107- title : 'Draft Title' ,
108- } )
109-
110- const { error} = await runCommand ( Pull , [ 'draftish' , '--force' ] )
103+ . get ( '/articles/draftish.json' )
104+ . reply ( 200 , {
105+ content : 'Draft **body**.' ,
106+ id : 99 ,
107+ slug : 'draftish' ,
108+ title : 'Draft Title' ,
109+ } )
110+
111+ const { error} = await runCommand ( Pull , [ 'draftish' , '--force' ] , { root : PLUGIN_ROOT } )
111112 expect ( error ) . to . equal ( undefined )
112113 expect ( readFileSync ( join ( workDir , 'draftish.md' ) , 'utf8' ) ) . to . contain ( 'Draft **body**.' )
113114 } )
@@ -126,35 +127,35 @@ describe('devcenter:pull', function () {
126127
127128 nock ( 'https://devcenter.heroku.com' ) . get ( '/articles/private-only.json' ) . reply ( 401 , { error : 'Authentication required' } )
128129 nock ( 'https://devcenter.heroku.com' , { reqheaders : auth } )
129- . get ( '/articles/private-only.json' )
130- . reply ( 401 , { error : 'Authentication required' } )
130+ . get ( '/articles/private-only.json' )
131+ . reply ( 401 , { error : 'Authentication required' } )
131132 nock ( 'https://devcenter.heroku.com' , { reqheaders : auth } )
132- . get ( '/api/v1/private/articles/private-only.json' )
133- . reply ( 200 , {
134- content : 'From **private** API.' ,
135- id : 42 ,
136- slug : 'private-only' ,
137- title : 'Private Only Title' ,
138- } )
139-
140- const { error} = await runCommand ( Pull , [ 'private-only' , '--force' ] )
133+ . get ( '/api/v1/private/articles/private-only.json' )
134+ . reply ( 200 , {
135+ content : 'From **private** API.' ,
136+ id : 42 ,
137+ slug : 'private-only' ,
138+ title : 'Private Only Title' ,
139+ } )
140+
141+ const { error} = await runCommand ( Pull , [ 'private-only' , '--force' ] , { root : PLUGIN_ROOT } )
141142 expect ( error ) . to . equal ( undefined )
142143 expect ( readFileSync ( join ( workDir , 'private-only.md' ) , 'utf8' ) ) . to . contain ( 'From **private** API.' )
143144 } )
144145
145146 it ( 'does not overwrite when user declines the prompt' , async function ( ) {
146147 writeFileSync ( join ( workDir , 'keep.md' ) , 'title: Old\nid: 1\n\nold' , 'utf8' )
147148 nock ( 'https://devcenter.heroku.com' )
148- . get ( '/articles/keep.json' )
149- . reply ( 200 , {
150- content : 'new body' ,
151- id : 1 ,
152- slug : 'keep' ,
153- title : 'New' ,
154- } )
149+ . get ( '/articles/keep.json' )
150+ . reply ( 200 , {
151+ content : 'new body' ,
152+ id : 1 ,
153+ slug : 'keep' ,
154+ title : 'New' ,
155+ } )
155156
156157 process . env . DEVCENTER_CLI_TEST_CONFIRM = 'false'
157- const { error} = await runCommand ( Pull , [ 'keep' ] )
158+ const { error} = await runCommand ( Pull , [ 'keep' ] , { root : PLUGIN_ROOT } )
158159 expect ( error ) . to . equal ( undefined )
159160 expect ( readFileSync ( join ( workDir , 'keep.md' ) , 'utf8' ) ) . to . contain ( 'old' )
160161 } )
0 commit comments