@@ -43,11 +43,11 @@ describe('apiFunctions', () => {
43
43
) ;
44
44
45
45
it ( 'should return table of pastes' , async ( ) => {
46
- const apiRes = await listPastes ( 1 , 'paste key' , 'paste name' ) ;
46
+ const actualResponse = await listPastes ( 1 , 'paste key' , 'paste name' ) ;
47
47
48
48
// this sucks, but hardcoding the expected table as a string
49
49
// is even worse because of newlines, etc.
50
- expect ( apiRes ) . toBe (
50
+ expect ( actualResponse ) . toBe (
51
51
table ( [
52
52
[ ...TABLE_HEADERS ] ,
53
53
[ 'paste key' , 'paste name' , 'public' , 'Never' , 'text' ] , // values set in node-fetch.js mock
@@ -59,9 +59,9 @@ describe('apiFunctions', () => {
59
59
__setStatusCode ( 500 ) ;
60
60
__setResponseText ( 'API Error' ) ;
61
61
62
- const apiRes = await listPastes ( 1 , 'testi' , 'testo' ) ;
62
+ const actualResponse = await listPastes ( 1 , 'testi' , 'testo' ) ;
63
63
64
- expect ( apiRes ) . toBe ( 'Error! API Error' ) ;
64
+ expect ( actualResponse ) . toBe ( 'Error! API Error' ) ;
65
65
} ) ;
66
66
} ) ;
67
67
@@ -81,13 +81,17 @@ describe('apiFunctions', () => {
81
81
) ;
82
82
83
83
it ( 'should return successfull response if paste was deleted' , async ( ) => {
84
- const responseText = 'Paste removed' ;
84
+ const expectedResponse = 'Paste removed' ;
85
85
86
- __setResponseText ( responseText ) ;
86
+ __setResponseText ( expectedResponse ) ;
87
87
88
- const apiRes = await deletePaste ( 'paste key' , 'api token' , 'user token' ) ;
88
+ const actualResponse = await deletePaste (
89
+ 'paste key' ,
90
+ 'api token' ,
91
+ 'user token'
92
+ ) ;
89
93
90
- expect ( apiRes ) . toBe ( `Success! ${ responseText } ` ) ;
94
+ expect ( actualResponse ) . toBe ( `Success! ${ expectedResponse } ` ) ;
91
95
} ) ;
92
96
93
97
it ( 'should return error if api returns error' , async ( ) => {
@@ -96,9 +100,13 @@ describe('apiFunctions', () => {
96
100
__setResponseText ( resonseText ) ;
97
101
__setStatusCode ( 403 ) ;
98
102
99
- const apiRes = await deletePaste ( 'pastey key' , 'api token' , 'user token' ) ;
103
+ const actualResponse = await deletePaste (
104
+ 'pastey key' ,
105
+ 'api token' ,
106
+ 'user token'
107
+ ) ;
100
108
101
- expect ( apiRes ) . toBe ( `Error! ${ resonseText } ` ) ;
109
+ expect ( actualResponse ) . toBe ( `Error! ${ resonseText } ` ) ;
102
110
} ) ;
103
111
} ) ;
104
112
@@ -118,28 +126,29 @@ describe('apiFunctions', () => {
118
126
) ;
119
127
120
128
it ( 'should create paste and return paste url' , async ( ) => {
121
- const responseText = 'https://pastebin.com/12345678' ;
129
+ const expectedResponse = 'https://pastebin.com/12345678' ;
122
130
123
- __setResponseText ( responseText ) ;
131
+ __setResponseText ( expectedResponse ) ;
124
132
125
- const apiRes = await createPaste (
126
- { format : 'text' , string : 'string' } ,
133
+ const actualResponse = await createPaste (
134
+ { format : 'text' , string : 'string' , folder : '' } ,
127
135
'api token' ,
128
136
'user token'
129
137
) ;
130
138
131
- expect ( apiRes ) . toBe ( `Success! ${ responseText } ` ) ;
139
+ expect ( actualResponse ) . toBe ( `Success! ${ expectedResponse } ` ) ;
132
140
} ) ;
133
141
134
142
it ( 'should create paste from file' , async ( ) => {
135
- const responseText = 'https://pastebin.com/12345678' ;
143
+ const expectedResponse = 'https://pastebin.com/12345678' ;
136
144
137
- __setResponseText ( responseText ) ;
145
+ __setResponseText ( expectedResponse ) ;
138
146
139
- const apiRes = await createPaste (
147
+ const actualResponse = await createPaste (
140
148
{
141
149
format : 'text' ,
142
150
file : '/some/path/to/file' ,
151
+ folder : '' ,
143
152
} ,
144
153
'api token' ,
145
154
'user token'
@@ -149,69 +158,82 @@ describe('apiFunctions', () => {
149
158
'/some/path/to/file' ,
150
159
'utf-8'
151
160
) ;
152
- expect ( apiRes ) . toBe ( `Success! ${ responseText } ` ) ;
161
+ expect ( actualResponse ) . toBe ( `Success! ${ expectedResponse } ` ) ;
153
162
} ) ;
154
163
155
164
it ( 'should return error if api returns error' , async ( ) => {
156
- const responseText = 'Ran out of storage' ;
165
+ const expectedResponse = 'Ran out of storage' ;
157
166
158
- __setResponseText ( responseText ) ;
167
+ __setResponseText ( expectedResponse ) ;
159
168
__setStatusCode ( 500 ) ;
160
169
161
- const apiRes = await createPaste (
162
- { format : 'text' , string : 'string' } ,
170
+ const actualResponse = await createPaste (
171
+ { format : 'text' , string : 'string' , folder : '' } ,
163
172
'api token' ,
164
173
'user token'
165
174
) ;
166
175
167
- expect ( apiRes ) . toBe ( `Error! ${ responseText } ` ) ;
176
+ expect ( actualResponse ) . toBe ( `Error! ${ expectedResponse } ` ) ;
168
177
} ) ;
169
178
170
179
it ( 'should return error if format is not supported by pastebin' , async ( ) => {
171
180
const resonseText =
172
181
'Error! Format option is not supported by pastebin. See https://pastebin.com/doc_api#8 for supported formats' ;
173
182
174
- const apiRes = await createPaste (
175
- { format : 'does not exist' , string : 'string' } ,
183
+ const actualResponse = await createPaste (
184
+ { format : 'does not exist' , string : 'string' , folder : '' } ,
185
+ 'api token' ,
186
+ 'user token'
187
+ ) ;
188
+
189
+ expect ( actualResponse ) . toBe ( resonseText ) ;
190
+ } ) ;
191
+
192
+ it ( 'should return error if folder name is longer than 8 characters' , async ( ) => {
193
+ const expectedResponse =
194
+ 'Pastebin only allows up to 8 characters for a folder name.' ;
195
+
196
+ const actualResponse = await createPaste (
197
+ { format : 'text' , string : 'string' , folder : 'longerthan8characters' } ,
176
198
'api token' ,
177
199
'user token'
178
200
) ;
179
201
180
- expect ( apiRes ) . toBe ( resonseText ) ;
202
+ expect ( actualResponse ) . toBe ( `Error! ${ expectedResponse } ` ) ;
181
203
} ) ;
182
204
183
205
it ( 'should return error if neither file or string are supplied' , async ( ) => {
184
- const responseText =
206
+ const expectedResponse =
185
207
'You need to supply either -f (--file) OR -s (--string)' ;
186
208
187
- const apiRes = await createPaste (
209
+ const actualResponse = await createPaste (
188
210
{ format : 'text' } ,
189
211
'api token' ,
190
212
'user token'
191
213
) ;
192
214
193
- expect ( apiRes ) . toBe ( responseText ) ;
215
+ expect ( actualResponse ) . toBe ( expectedResponse ) ;
194
216
} ) ;
195
217
} ) ;
196
218
197
219
describe ( 'logOut' , ( ) => {
198
220
it ( 'should delete the ~/.pasty.user file' , ( ) => {
199
- const responseText = 'Successfully logged you out.' ;
221
+ const expectedResponse = 'Successfully logged you out.' ;
200
222
201
- const apiRes = logout ( ) ;
223
+ const actualResponse = logout ( ) ;
202
224
203
- expect ( apiRes ) . toBe ( responseText ) ;
225
+ expect ( actualResponse ) . toBe ( expectedResponse ) ;
204
226
expect ( fs . rmSync ) . toHaveBeenCalledWith ( 'mockHomeDir/.pasty.user' ) ;
205
227
} ) ;
206
228
207
229
it ( 'should return error if there is no ~/.pasty.user file' , ( ) => {
208
- const responseText =
230
+ const expectedResponse =
209
231
"You're currently not logged in (could not find ~/.pasty.user)" ;
210
232
211
233
fs . __setFileExists ( false ) ;
212
- const apiRes = logout ( ) ;
234
+ const actualResponse = logout ( ) ;
213
235
214
- expect ( apiRes ) . toBe ( responseText ) ;
236
+ expect ( actualResponse ) . toBe ( expectedResponse ) ;
215
237
expect ( fs . rmSync ) . not . toHaveBeenCalled ( ) ;
216
238
} ) ;
217
239
} ) ;
@@ -227,29 +249,29 @@ describe('apiFunctions', () => {
227
249
it ( 'should write user token to file if login was successfull' , async ( ) => {
228
250
const username = 'dummyUser' ;
229
251
const tokenFromApi = 'token from api' ;
230
- const responseText = `You're now logged in as ${ username } ` ;
252
+ const expectedResponse = `You're now logged in as ${ username } ` ;
231
253
232
254
__setResponseText ( tokenFromApi ) ;
233
255
234
- const apiRes = await loginUser ( { username } , 'api token' ) ;
256
+ const actualResponse = await loginUser ( { username } , 'api token' ) ;
235
257
236
258
expect ( fs . writeFileSync ) . toHaveBeenCalledWith (
237
259
'mockHomeDir/.pasty.user' ,
238
260
tokenFromApi ,
239
261
'utf-8'
240
262
) ;
241
- expect ( apiRes ) . toBe ( `Success! ${ responseText } ` ) ;
263
+ expect ( actualResponse ) . toBe ( `Success! ${ expectedResponse } ` ) ;
242
264
} ) ;
243
265
244
266
it ( 'should return error if api returns error' , async ( ) => {
245
- const responseText = 'Login service unavailable' ;
267
+ const expectedResponse = 'Login service unavailable' ;
246
268
247
- __setResponseText ( responseText ) ;
269
+ __setResponseText ( expectedResponse ) ;
248
270
__setStatusCode ( 500 ) ;
249
271
250
- const apiRes = await loginUser ( { } , 'api token' ) ;
272
+ const actualResponse = await loginUser ( { } , 'api token' ) ;
251
273
252
- expect ( apiRes ) . toBe ( `Error! ${ responseText } ` ) ;
274
+ expect ( actualResponse ) . toBe ( `Error! ${ expectedResponse } ` ) ;
253
275
} ) ;
254
276
} ) ;
255
277
} ) ;
0 commit comments