@@ -41,82 +41,82 @@ const test = base
41
41
42
42
describe ( 'api_client' , ( ) => {
43
43
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' } ] )
49
49
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' } ] )
53
53
// 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' } ,
60
54
} )
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
- } )
67
55
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 => {
72
58
api = nock ( 'https://api.heroku.com' , {
73
- reqheaders : { 'x-foo' : 'bar ' } ,
59
+ reqheaders : { authorization : 'Bearer myotherpass ' } ,
74
60
} )
75
61
api . get ( '/apps' ) . reply ( 200 , [ { name : 'myapp' } ] )
76
62
77
63
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' } } )
79
65
expect ( body ) . to . deep . equal ( [ { name : 'myapp' } ] )
80
66
} )
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
+ } )
81
81
} )
82
82
83
83
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' } ] )
93
96
} )
94
- const { body} = await cmd . heroku . get ( '/apps' )
95
- expect ( body ) . to . deep . equal ( [ { name : 'myapp' } ] )
96
- } )
97
97
98
98
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 } )
112
121
} )
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
- } )
122
122
} )
0 commit comments