@@ -41,82 +41,82 @@ const test = base
4141
4242describe ( 'api_client' , ( ) => {
4343 test
44- . it ( 'makes an HTTP request' , async ctx => {
45- api = nock ( 'https://api.heroku.com' , {
46- reqheaders : { authorization : 'Bearer mypass' } ,
47- } )
48- api . get ( '/apps' ) . reply ( 200 , [ { name : 'myapp' } ] )
44+ . it ( 'makes an HTTP request' , async ctx => {
45+ api = nock ( 'https://api.heroku.com' , {
46+ reqheaders : { authorization : 'Bearer mypass' } ,
47+ } )
48+ api . get ( '/apps' ) . reply ( 200 , [ { name : 'myapp' } ] )
4949
50- const cmd = new Command ( [ ] , ctx . config )
51- const { body} = await cmd . heroku . get ( '/apps' )
52- expect ( body ) . to . deep . equal ( [ { name : 'myapp' } ] )
50+ const cmd = new Command ( [ ] , ctx . config )
51+ const { body} = await cmd . heroku . get ( '/apps' )
52+ expect ( body ) . to . deep . equal ( [ { name : 'myapp' } ] )
5353 // expect(netrc.loadSync).toBeCalled()
54- } )
55-
56- test
57- . it ( 'can override authorization header' , async ctx => {
58- api = nock ( 'https://api.heroku.com' , {
59- reqheaders : { authorization : 'Bearer myotherpass' } ,
6054 } )
61- api . get ( '/apps' ) . reply ( 200 , [ { name : 'myapp' } ] )
62-
63- const cmd = new Command ( [ ] , ctx . config )
64- const { body} = await cmd . heroku . get ( '/apps' , { headers : { Authorization : 'Bearer myotherpass' } } )
65- expect ( body ) . to . deep . equal ( [ { name : 'myapp' } ] )
66- } )
6755
68- describe ( 'with HEROKU_HEADERS' , ( ) => {
69- test
70- . it ( 'makes an HTTP request with HEROKU_HEADERS' , async ctx => {
71- process . env . HEROKU_HEADERS = '{"x-foo": "bar"}'
56+ test
57+ . it ( 'can override authorization header' , async ctx => {
7258 api = nock ( 'https://api.heroku.com' , {
73- reqheaders : { 'x-foo' : 'bar ' } ,
59+ reqheaders : { authorization : 'Bearer myotherpass ' } ,
7460 } )
7561 api . get ( '/apps' ) . reply ( 200 , [ { name : 'myapp' } ] )
7662
7763 const cmd = new Command ( [ ] , ctx . config )
78- const { body} = await cmd . heroku . get ( '/apps' )
64+ const { body} = await cmd . heroku . get ( '/apps' , { headers : { Authorization : 'Bearer myotherpass' } } )
7965 expect ( body ) . to . deep . equal ( [ { name : 'myapp' } ] )
8066 } )
67+
68+ describe ( 'with HEROKU_HEADERS' , ( ) => {
69+ test
70+ . it ( 'makes an HTTP request with HEROKU_HEADERS' , async ctx => {
71+ process . env . HEROKU_HEADERS = '{"x-foo": "bar"}'
72+ api = nock ( 'https://api.heroku.com' , {
73+ reqheaders : { 'x-foo' : 'bar' } ,
74+ } )
75+ api . get ( '/apps' ) . reply ( 200 , [ { name : 'myapp' } ] )
76+
77+ const cmd = new Command ( [ ] , ctx . config )
78+ const { body} = await cmd . heroku . get ( '/apps' )
79+ expect ( body ) . to . deep . equal ( [ { name : 'myapp' } ] )
80+ } )
8181 } )
8282
8383 test
84- . it ( '2fa no preauth' , async ctx => {
85- api = nock ( 'https://api.heroku.com' )
86- api . get ( '/apps' ) . reply ( 403 , { id : 'two_factor' } )
87- let _api = api as any
88- _api . get ( '/apps' ) . matchHeader ( 'heroku-two-factor-code' , '123456' ) . reply ( 200 , [ { name : 'myapp' } ] )
89-
90- const cmd = new Command ( [ ] , ctx . config )
91- Object . defineProperty ( cli , 'prompt' , {
92- get : ( ) => ( ) => Promise . resolve ( '123456' )
84+ . it ( '2fa no preauth' , async ctx => {
85+ api = nock ( 'https://api.heroku.com' )
86+ api . get ( '/apps' ) . reply ( 403 , { id : 'two_factor' } )
87+ let _api = api as any
88+ _api . get ( '/apps' ) . matchHeader ( 'heroku-two-factor-code' , '123456' ) . reply ( 200 , [ { name : 'myapp' } ] )
89+
90+ const cmd = new Command ( [ ] , ctx . config )
91+ Object . defineProperty ( cli , 'prompt' , {
92+ get : ( ) => ( ) => Promise . resolve ( '123456' )
93+ } )
94+ const { body} = await cmd . heroku . get ( '/apps' )
95+ expect ( body ) . to . deep . equal ( [ { name : 'myapp' } ] )
9396 } )
94- const { body} = await cmd . heroku . get ( '/apps' )
95- expect ( body ) . to . deep . equal ( [ { name : 'myapp' } ] )
96- } )
9797
9898 test
99- . it ( '2fa preauth' , async ctx => {
100- api = nock ( 'https://api.heroku.com' )
101- api . get ( '/apps/myapp' ) . reply ( 403 , { id : 'two_factor' , app : { name : 'myapp' } } )
102- let _api = api as any
103- _api . put ( '/apps/myapp/pre-authorizations' ) . matchHeader ( 'heroku-two-factor-code' , '123456' ) . reply ( 200 , { } )
104- api . get ( '/apps/myapp' ) . reply ( 200 , { name : 'myapp' } )
105- api . get ( '/apps/anotherapp' ) . reply ( 200 , { name : 'anotherapp' } )
106- api . get ( '/apps/myapp/config' ) . reply ( 200 , { foo : 'bar' } )
107- api . get ( '/apps/myapp/dynos' ) . reply ( 200 , { web : 1 } )
108-
109- const cmd = new Command ( [ ] , ctx . config )
110- Object . defineProperty ( cli , 'prompt' , {
111- get : ( ) => ( ) => Promise . resolve ( '123456' )
99+ . it ( '2fa preauth' , async ctx => {
100+ api = nock ( 'https://api.heroku.com' )
101+ api . get ( '/apps/myapp' ) . reply ( 403 , { id : 'two_factor' , app : { name : 'myapp' } } )
102+ let _api = api as any
103+ _api . put ( '/apps/myapp/pre-authorizations' ) . matchHeader ( 'heroku-two-factor-code' , '123456' ) . reply ( 200 , { } )
104+ api . get ( '/apps/myapp' ) . reply ( 200 , { name : 'myapp' } )
105+ api . get ( '/apps/anotherapp' ) . reply ( 200 , { name : 'anotherapp' } )
106+ api . get ( '/apps/myapp/config' ) . reply ( 200 , { foo : 'bar' } )
107+ api . get ( '/apps/myapp/dynos' ) . reply ( 200 , { web : 1 } )
108+
109+ const cmd = new Command ( [ ] , ctx . config )
110+ Object . defineProperty ( cli , 'prompt' , {
111+ get : ( ) => ( ) => Promise . resolve ( '123456' )
112+ } )
113+ const info = cmd . heroku . get ( '/apps/myapp' )
114+ const anotherapp = cmd . heroku . get ( '/apps/anotherapp' )
115+ const _config = cmd . heroku . get ( '/apps/myapp/config' )
116+ const dynos = cmd . heroku . get ( '/apps/myapp/dynos' )
117+ expect ( ( await info ) . body ) . to . deep . equal ( { name : 'myapp' } )
118+ expect ( ( await anotherapp ) . body ) . to . deep . equal ( { name : 'anotherapp' } )
119+ expect ( ( await _config ) . body ) . to . deep . equal ( { foo : 'bar' } )
120+ expect ( ( await dynos ) . body ) . to . deep . equal ( { web : 1 } )
112121 } )
113- const info = cmd . heroku . get ( '/apps/myapp' )
114- const anotherapp = cmd . heroku . get ( '/apps/anotherapp' )
115- const _config = cmd . heroku . get ( '/apps/myapp/config' )
116- const dynos = cmd . heroku . get ( '/apps/myapp/dynos' )
117- expect ( ( await info ) . body ) . to . deep . equal ( { name : 'myapp' } )
118- expect ( ( await anotherapp ) . body ) . to . deep . equal ( { name : 'anotherapp' } )
119- expect ( ( await _config ) . body ) . to . deep . equal ( { foo : 'bar' } )
120- expect ( ( await dynos ) . body ) . to . deep . equal ( { web : 1 } )
121- } )
122122} )
0 commit comments