@@ -109,4 +109,172 @@ describe('anime-dl', function() {
109
109
} ) . catch ( err => done ( err ) ) ;
110
110
} ) ;
111
111
} ) ;
112
+
113
+ describe ( 'server error in get link' , ( ) => {
114
+ beforeEach ( ( ) => {
115
+ nock . disableNetConnect ( ) ;
116
+ nock ( 'http://jkanime.net' )
117
+ . get ( '/buscar/mob%20psycho%20100' )
118
+ . replyWithFile ( 200 , path . join ( __dirname , 'found.html' ) ) ;
119
+ nock ( 'http://jkanime.net' )
120
+ . get ( '/mob-psycho-100' )
121
+ . replyWithFile ( 200 , path . join ( __dirname , 'chapters.html' ) ) ;
122
+ nock ( 'http://jkanime.net' )
123
+ . get ( '/mob-psycho-100/1' )
124
+ . replyWithError ( 'Server error' ) ;
125
+ } ) ;
126
+
127
+ it ( 'should return an error' , done => {
128
+ const name = 'mob psycho 100' ;
129
+ const chapter = 1 ;
130
+ anime . getLinksByNameAndChapter ( name , chapter ) . catch ( err => {
131
+ expect ( err ) . to . be . an ( 'error' ) ;
132
+ done ( ) ;
133
+ } ) ;
134
+ } ) ;
135
+ } ) ;
136
+
137
+ describe ( 'bad status in get link' , ( ) => {
138
+ beforeEach ( ( ) => {
139
+ nock . disableNetConnect ( ) ;
140
+ nock ( 'http://jkanime.net' )
141
+ . get ( '/buscar/mob%20psycho%20100' )
142
+ . replyWithFile ( 200 , path . join ( __dirname , 'found.html' ) ) ;
143
+ nock ( 'http://jkanime.net' )
144
+ . get ( '/mob-psycho-100' )
145
+ . replyWithFile ( 200 , path . join ( __dirname , 'chapters.html' ) ) ;
146
+ nock ( 'http://jkanime.net' )
147
+ . get ( '/mob-psycho-100/1' )
148
+ . reply ( 301 ) ;
149
+ } ) ;
150
+
151
+ it ( 'should return an error' , done => {
152
+ const name = 'mob psycho 100' ;
153
+ const chapter = 1 ;
154
+ anime . getLinksByNameAndChapter ( name , chapter ) . catch ( err => {
155
+ expect ( err ) . to . be . an ( 'error' ) ;
156
+ done ( ) ;
157
+ } ) ;
158
+ } ) ;
159
+ } ) ;
160
+
161
+ describe ( 'server error in get last chapter' , ( ) => {
162
+ beforeEach ( ( ) => {
163
+ nock . disableNetConnect ( ) ;
164
+ nock ( 'http://jkanime.net' )
165
+ . get ( '/buscar/mob%20psycho%20100' )
166
+ . replyWithFile ( 200 , path . join ( __dirname , 'found.html' ) ) ;
167
+ nock ( 'http://jkanime.net' )
168
+ . get ( '/mob-psycho-100' )
169
+ . replyWithError ( 'Server error' ) ;
170
+ nock ( 'http://jkanime.net' )
171
+ . get ( '/mob-psycho-100/1' )
172
+ . replyWithError ( 'Server error' ) ;
173
+ } ) ;
174
+
175
+ it ( 'should return an error' , done => {
176
+ const name = 'mob psycho 100' ;
177
+ const chapter = 1 ;
178
+ anime . getLinksByNameAndChapter ( name , chapter ) . catch ( err => {
179
+ expect ( err ) . to . be . an ( 'error' ) ;
180
+ done ( ) ;
181
+ } ) ;
182
+ } ) ;
183
+ } ) ;
184
+
185
+ describe ( 'bad status in get last chapter' , ( ) => {
186
+ beforeEach ( ( ) => {
187
+ nock . disableNetConnect ( ) ;
188
+ nock ( 'http://jkanime.net' )
189
+ . get ( '/buscar/mob%20psycho%20100' )
190
+ . replyWithFile ( 200 , path . join ( __dirname , 'found.html' ) ) ;
191
+ nock ( 'http://jkanime.net' )
192
+ . get ( '/mob-psycho-100' )
193
+ . reply ( 301 ) ;
194
+ nock ( 'http://jkanime.net' )
195
+ . get ( '/mob-psycho-100/1' )
196
+ . reply ( 301 ) ;
197
+ } ) ;
198
+
199
+ it ( 'should return an error' , done => {
200
+ const name = 'mob psycho 100' ;
201
+ const chapter = 1 ;
202
+ anime . getLinksByNameAndChapter ( name , chapter ) . catch ( err => {
203
+ expect ( err ) . to . be . an ( 'error' ) ;
204
+ done ( ) ;
205
+ } ) ;
206
+ } ) ;
207
+ } ) ;
208
+
209
+ describe ( 'server error in search' , ( ) => {
210
+ beforeEach ( ( ) => {
211
+ nock . disableNetConnect ( ) ;
212
+ nock ( 'http://jkanime.net' )
213
+ . get ( '/buscar/mob%20psycho%20100' )
214
+ . replyWithError ( 'Server error' ) ;
215
+ nock ( 'http://jkanime.net' )
216
+ . get ( '/mob-psycho-100' )
217
+ . replyWithError ( 'Server error' ) ;
218
+ nock ( 'http://jkanime.net' )
219
+ . get ( '/mob-psycho-100/1' )
220
+ . replyWithError ( 'Server error' ) ;
221
+ } ) ;
222
+
223
+ it ( 'should return an error' , done => {
224
+ const name = 'mob psycho 100' ;
225
+ const chapter = 1 ;
226
+ anime . getLinksByNameAndChapter ( name , chapter ) . catch ( err => {
227
+ expect ( err ) . to . be . an ( 'error' ) ;
228
+ done ( ) ;
229
+ } ) ;
230
+ } ) ;
231
+ } ) ;
232
+
233
+ describe ( 'bad status code in search' , ( ) => {
234
+ beforeEach ( ( ) => {
235
+ nock . disableNetConnect ( ) ;
236
+ nock ( 'http://jkanime.net' )
237
+ . get ( '/buscar/mob%20psycho%20100' )
238
+ . reply ( 301 ) ;
239
+ nock ( 'http://jkanime.net' )
240
+ . get ( '/mob-psycho-100' )
241
+ . reply ( 301 ) ;
242
+ nock ( 'http://jkanime.net' )
243
+ . get ( '/mob-psycho-100/1' )
244
+ . reply ( 301 ) ;
245
+ } ) ;
246
+
247
+ it ( 'should return an error' , done => {
248
+ const name = 'mob psycho 100' ;
249
+ const chapter = 1 ;
250
+ anime . getLinksByNameAndChapter ( name , chapter ) . catch ( err => {
251
+ expect ( err ) . to . be . an ( 'error' ) ;
252
+ done ( ) ;
253
+ } ) ;
254
+ } ) ;
255
+ } ) ;
256
+
257
+ describe ( 'error in search name' , ( ) => {
258
+ beforeEach ( ( ) => {
259
+ nock . disableNetConnect ( ) ;
260
+ nock ( 'http://jkanime.net' )
261
+ . get ( '/buscar/mob%20psycho%20100' )
262
+ . replyWithFile ( 200 , path . join ( __dirname , 'found_invalid.html' ) ) ;
263
+ nock ( 'http://jkanime.net' )
264
+ . get ( '/mob-psycho-100' )
265
+ . replyWithFile ( 200 , path . join ( __dirname , 'chapters.html' ) ) ;
266
+ nock ( 'http://jkanime.net' )
267
+ . get ( '/mob-psycho-100/1' )
268
+ . replyWithFile ( 200 , path . join ( __dirname , 'chapter2.html' ) ) ;
269
+ } ) ;
270
+
271
+ it ( 'should return an error' , done => {
272
+ const name = 'mob psycho 100' ;
273
+ const chapter = 1 ;
274
+ anime . getLinksByNameAndChapter ( name , chapter ) . catch ( err => {
275
+ expect ( err ) . to . be . an ( 'error' ) ;
276
+ done ( ) ;
277
+ } ) ;
278
+ } ) ;
279
+ } ) ;
112
280
} ) ;
0 commit comments