@@ -23,21 +23,20 @@ const header = file.__get__('header')
23
23
const fs = require ( 'fs' )
24
24
25
25
// HELPERS
26
- function fetch_cmd ( name ) {
26
+ function fetchCMD ( name ) {
27
27
return commands . find ( ( c ) => c . command === name )
28
28
}
29
29
30
30
function setup ( ) {
31
31
cli . raiseErrors = true
32
32
}
33
33
34
- function default_fs ( ) {
34
+ function defaultFS ( ) {
35
35
// this is so I can setup without affecting other tests
36
36
return {
37
37
'.env' : fixtures . local_file ,
38
38
'other.txt' : fixtures . local_file ,
39
- 'dnt' : mock . file ( { mode : '000' } ) ,
40
- totally : { }
39
+ 'dnt' : mock . file ( { mode : '000' } )
41
40
}
42
41
}
43
42
@@ -62,12 +61,14 @@ let fixtures = {
62
61
DB_STRING : 'mongo://blah@thing.mongo.thing.com:4567' ,
63
62
NAME : 'david'
64
63
} ,
64
+
65
65
local_file : '#comment\nNODE_ENV=test\nSOURCE=local\n\nDB_STRING=mongo://blah@thing.mongo.thing.com:4567\n' ,
66
66
merged_local_file : header + 'DB_STRING="mongo://blah@thing.mongo.thing.com:4567"\nNAME="david"\nNODE_ENV="test"\nSOURCE="local"\n' ,
67
+
67
68
// test both quote styles
68
- sample_file : header + 'NAME ="david"\n\n#this is a comment!\nCITY=boulder\n\n\n' ,
69
- clean_sample_file : header + 'CITY="boulder"\nNAME="david"\n' ,
70
- sample_obj : { NAME : 'david' , CITY : 'boulder' }
69
+ sample_file : header + 'PIZZA="Abo\'s"\nNAME ="david"\n\n#this is a comment!\nCITY=boulder\n\n\n' ,
70
+ clean_sample_file : header + 'CITY="boulder"\nNAME="david"\nPIZZA="Abo\'s"\ n' ,
71
+ sample_obj : { NAME : 'david' , CITY : 'boulder' , PIZZA : "Abo's" }
71
72
}
72
73
73
74
// TESTS
@@ -92,7 +93,7 @@ describe('Merging', () => {
92
93
93
94
describe ( 'Reading' , ( ) => {
94
95
beforeEach ( ( ) => {
95
- mock ( default_fs ( ) )
96
+ mock ( defaultFS ( ) )
96
97
} )
97
98
98
99
it ( 'should return empty object from non-existant file' , ( ) => {
@@ -111,20 +112,19 @@ describe('Reading', () => {
111
112
describe ( 'Writing' , ( ) => {
112
113
beforeEach ( ( ) => {
113
114
cli . mockConsole ( )
114
- mock ( default_fs ( ) )
115
+ mock ( defaultFS ( ) )
115
116
} )
116
117
117
118
it ( 'should fail to read from a file it lacks permissions for' , ( ) => {
118
- return file . write ( { } , 'dnt' ) . then ( ( ) => {
119
- expect ( cli . stderr ) . to . contain ( 'EACCES, permission denied' )
120
- } )
119
+ return expect ( file . write ( { } , 'dnt' ) ) . to . be . rejectedWith ( Error )
121
120
} )
122
121
123
- // it('should successfully write a file', () => {
124
- // return file.write(fixtures.local_obj).then(() => {
125
- // let res = require('fs').readFileSync('.env')
126
- // })
127
- // })
122
+ it ( 'should successfully write a file' , ( ) => {
123
+ return file . write ( fixtures . sample_obj ) . then ( ( ) => {
124
+ let res = fs . readFileSync ( '.env' , 'utf-8' )
125
+ expect ( res ) . to . equal ( fixtures . clean_sample_file )
126
+ } )
127
+ } )
128
128
129
129
afterEach ( ( ) => {
130
130
mock . restore ( )
@@ -133,40 +133,64 @@ describe('Writing', () => {
133
133
134
134
describe ( 'Transforming' , ( ) => {
135
135
it ( 'should decode files correctly' , ( ) => {
136
- expect ( file . __get__ ( 'obj_from_file_format ' ) ( fixtures . sample_file ) ) . to . deep . equal ( fixtures . sample_obj )
136
+ expect ( file . __get__ ( 'objFromFileFormat ' ) ( fixtures . sample_file ) ) . to . deep . equal ( fixtures . sample_obj )
137
137
} )
138
138
139
139
it ( 'should encode file correctly' , ( ) => {
140
- expect ( file . __get__ ( 'obj_to_file_format ' ) ( fixtures . sample_obj ) ) . to . equal ( fixtures . clean_sample_file )
140
+ expect ( file . __get__ ( 'objToFileFormat ' ) ( fixtures . sample_obj ) ) . to . equal ( fixtures . clean_sample_file )
141
141
} )
142
142
} )
143
143
144
- // describe('Pushing', {skip: true}, (t) => {
145
- // let api_get = nock('https://api.heroku.com:443')
146
- // .get('/apps/test/config-vars')
147
- // .reply(200, remote)
144
+ describe ( 'Pushing' , ( ) => {
145
+ beforeEach ( ( ) => {
146
+ cli . mockConsole ( )
147
+ mock ( defaultFS ( ) )
148
+ } )
149
+
150
+ it ( 'should correctly push configs w/ flags' , ( ) => {
151
+ nock ( 'https://api.heroku.com:443' )
152
+ . get ( '/apps/test/config-vars' )
153
+ . reply ( 200 , fixtures . remote_obj )
154
+
155
+ // this will fail if we don't pass the correct body, as intended
156
+ nock ( 'https://api.heroku.com:443' )
157
+ . patch ( '/apps/test/config-vars' , fixtures . remote_win_obj )
158
+ . reply ( 200 , fixtures . remote_win_obj )
148
159
149
- // let api_patch = nock('https://api.heroku.com:443')
150
- // .patch('/apps/test/config-vars')
151
- // .reply(200, remote_win_obj)
160
+ // fetch the updated value
161
+ nock ( 'https://api.heroku.com:443' )
162
+ . get ( '/apps/test/config-vars' )
163
+ . reply ( 200 , fixtures . remote_win_obj )
164
+
165
+ let cmd = fetchCMD ( 'mypush' )
166
+ let fname = 'other.txt'
167
+ return cmd . run ( { flags : { file : fname } , app : 'test' } ) . then ( ( ) => {
168
+ return cli . got ( 'https://api.heroku.com:443/apps/test/config-vars' )
169
+ } ) . then ( ( res ) => {
170
+ expect ( JSON . parse ( res . body ) ) . to . deep . equal ( fixtures . remote_win_obj )
171
+ } )
172
+ } )
152
173
153
- // let cmd = fetch_cmd('mypush')
154
- // })
174
+ afterEach ( ( ) => {
175
+ mock . restore ( )
176
+ } )
177
+ } )
155
178
156
179
describe ( 'Pulling' , ( ) => {
157
180
beforeEach ( ( ) => {
158
181
cli . mockConsole ( )
159
- mock ( default_fs ( ) )
182
+ mock ( defaultFS ( ) )
160
183
} )
161
184
162
185
it ( 'should correctly pull configs' , ( ) => {
163
186
nock ( 'https://api.heroku.com:443' )
164
187
. get ( '/apps/test/config-vars' )
165
188
. reply ( 200 , fixtures . remote_obj )
166
189
167
- let cmd = fetch_cmd ( 'mypull' )
168
- return cmd . run ( { flags : { } , app : 'test' } ) . then ( ( ) => {
169
- let res = fs . readFileSync ( '.env' , 'utf-8' )
190
+ let cmd = fetchCMD ( 'mypull' )
191
+ let fname = 'other.txt'
192
+ return cmd . run ( { flags : { file : fname } , app : 'test' } ) . then ( ( ) => {
193
+ let res = fs . readFileSync ( fname , 'utf-8' )
170
194
expect ( res ) . to . include ( fixtures . merged_local_file )
171
195
} )
172
196
} )
0 commit comments