@@ -2,10 +2,16 @@ const { Client } = require('podcast-api');
2
2
3
3
test ( 'Test search endpoint with mock' , ( ) => {
4
4
const client = Client ( ) ;
5
+ const term = 'elon musk' ;
5
6
return client . search ( {
6
- q : 'elon musk' ,
7
+ q : term ,
7
8
} ) . then ( ( response ) => {
8
- expect ( response . data . count ) . toBe ( 10 ) ;
9
+ expect ( response . config . params . q ) . toBe ( term ) ;
10
+ expect ( response . config . url ) . toBe ( '/search' ) ;
11
+ expect ( response . config . method ) . toBe ( 'get' ) ;
12
+ expect ( response . data . count > 0 ) . toBe ( true ) ;
13
+ } ) . catch ( ( ) => {
14
+ fail ( 'Failed!' ) ;
9
15
} ) ;
10
16
} ) ;
11
17
@@ -32,3 +38,259 @@ test('Test search endpoint with authentication error', () => {
32
38
}
33
39
} ) ;
34
40
} ) ;
41
+
42
+ test ( 'Test typeahead with mock' , ( ) => {
43
+ const client = Client ( ) ;
44
+ const term = 'elon musk2' ;
45
+ return client . typeahead ( {
46
+ q : term ,
47
+ show_podcasts : 1 ,
48
+ } ) . then ( ( response ) => {
49
+ expect ( response . config . params . q ) . toBe ( term ) ;
50
+ expect ( response . config . params . show_podcasts ) . toBe ( 1 ) ;
51
+ expect ( response . config . url ) . toBe ( '/typeahead' ) ;
52
+ expect ( response . config . method ) . toBe ( 'get' ) ;
53
+ expect ( response . data . terms . length > 0 ) . toBe ( true ) ;
54
+ } ) . catch ( ( ) => {
55
+ fail ( 'Failed!' ) ;
56
+ } ) ;
57
+ } ) ;
58
+
59
+ test ( 'Test fetchBestPodcasts with mock' , ( ) => {
60
+ const client = Client ( ) ;
61
+ const genreId = 123 ;
62
+ return client . fetchBestPodcasts ( {
63
+ genre_id : genreId ,
64
+ } ) . then ( ( response ) => {
65
+ expect ( response . config . params . genre_id ) . toBe ( genreId ) ;
66
+ expect ( response . config . url ) . toBe ( '/best_podcasts' ) ;
67
+ expect ( response . config . method ) . toBe ( 'get' ) ;
68
+ expect ( response . data . total > 0 ) . toBe ( true ) ;
69
+ } ) . catch ( ( ) => {
70
+ fail ( 'Failed!' ) ;
71
+ } ) ;
72
+ } ) ;
73
+
74
+ test ( 'Test fetchPodcastById with mock' , ( ) => {
75
+ const client = Client ( ) ;
76
+ const podcastId = 'abcde' ;
77
+ return client . fetchPodcastById ( {
78
+ id : podcastId ,
79
+ } ) . then ( ( response ) => {
80
+ expect ( response . config . url ) . toBe ( `/podcasts/${ podcastId } ` ) ;
81
+ expect ( response . config . method ) . toBe ( 'get' ) ;
82
+ expect ( response . data . episodes . length > 0 ) . toBe ( true ) ;
83
+ } ) . catch ( ( ) => {
84
+ fail ( 'Failed!' ) ;
85
+ } ) ;
86
+ } ) ;
87
+
88
+ test ( 'Test fetchEpisodeById with mock' , ( ) => {
89
+ const client = Client ( ) ;
90
+ const episodeId = 'abc222de' ;
91
+ return client . fetchEpisodeById ( {
92
+ id : episodeId ,
93
+ } ) . then ( ( response ) => {
94
+ expect ( response . config . url ) . toBe ( `/episodes/${ episodeId } ` ) ;
95
+ expect ( response . config . method ) . toBe ( 'get' ) ;
96
+ expect ( response . data . podcast . rss . length > 0 ) . toBe ( true ) ;
97
+ } ) . catch ( ( ) => {
98
+ fail ( 'Failed!' ) ;
99
+ } ) ;
100
+ } ) ;
101
+
102
+ test ( 'Test batchFetchPodcasts with mock' , ( ) => {
103
+ const client = Client ( ) ;
104
+ const ids = '996,777,888,1000' ;
105
+ return client . batchFetchPodcasts ( {
106
+ ids,
107
+ } ) . then ( ( response ) => {
108
+ expect ( response . config . url ) . toBe ( '/podcasts' ) ;
109
+ expect ( response . config . method ) . toBe ( 'post' ) ;
110
+ expect ( JSON . parse ( response . config . data ) . ids ) . toBe ( ids ) ;
111
+ expect ( response . data . podcasts . length > 0 ) . toBe ( true ) ;
112
+ } ) . catch ( ( ) => {
113
+ fail ( 'Failed!' ) ;
114
+ } ) ;
115
+ } ) ;
116
+
117
+ test ( 'Test batchFetchEpisodes with mock' , ( ) => {
118
+ const client = Client ( ) ;
119
+ const ids = '996,777,222,888,1000' ;
120
+ return client . batchFetchEpisodes ( {
121
+ ids,
122
+ } ) . then ( ( response ) => {
123
+ expect ( response . config . url ) . toBe ( '/episodes' ) ;
124
+ expect ( response . config . method ) . toBe ( 'post' ) ;
125
+ expect ( JSON . parse ( response . config . data ) . ids ) . toBe ( ids ) ;
126
+ expect ( response . data . episodes . length > 0 ) . toBe ( true ) ;
127
+ } ) . catch ( ( ) => {
128
+ fail ( 'Failed!' ) ;
129
+ } ) ;
130
+ } ) ;
131
+
132
+ test ( 'Test fetchCuratedPodcastsListById with mock' , ( ) => {
133
+ const client = Client ( ) ;
134
+ const curatedListId = '23232' ;
135
+ return client . fetchCuratedPodcastsListById ( {
136
+ id : curatedListId ,
137
+ } ) . then ( ( response ) => {
138
+ expect ( response . config . url ) . toBe ( `/curated_podcasts/${ curatedListId } ` ) ;
139
+ expect ( response . config . method ) . toBe ( 'get' ) ;
140
+ expect ( response . data . podcasts . length > 0 ) . toBe ( true ) ;
141
+ } ) . catch ( ( ) => {
142
+ fail ( 'Failed!' ) ;
143
+ } ) ;
144
+ } ) ;
145
+
146
+ test ( 'Test fetchCuratedPodcastsLists with mock' , ( ) => {
147
+ const client = Client ( ) ;
148
+ const page = 2 ;
149
+ return client . fetchCuratedPodcastsLists ( {
150
+ page : 2 ,
151
+ } ) . then ( ( response ) => {
152
+ expect ( response . config . url ) . toBe ( '/curated_podcasts' ) ;
153
+ expect ( response . config . params . page ) . toBe ( page ) ;
154
+ expect ( response . config . method ) . toBe ( 'get' ) ;
155
+ expect ( response . data . total > 0 ) . toBe ( true ) ;
156
+ } ) . catch ( ( ) => {
157
+ fail ( 'Failed!' ) ;
158
+ } ) ;
159
+ } ) ;
160
+
161
+ test ( 'Test fetchPodcastGenres with mock' , ( ) => {
162
+ const client = Client ( ) ;
163
+ const topLevelOnly = 1 ;
164
+ return client . fetchPodcastGenres ( {
165
+ top_level_only : topLevelOnly ,
166
+ } ) . then ( ( response ) => {
167
+ expect ( response . config . url ) . toBe ( '/genres' ) ;
168
+ expect ( response . config . params . top_level_only ) . toBe ( topLevelOnly ) ;
169
+ expect ( response . config . method ) . toBe ( 'get' ) ;
170
+ expect ( response . data . genres . length > 0 ) . toBe ( true ) ;
171
+ } ) . catch ( ( ) => {
172
+ fail ( 'Failed!' ) ;
173
+ } ) ;
174
+ } ) ;
175
+
176
+ test ( 'Test fetchPodcastRegions with mock' , ( ) => {
177
+ const client = Client ( ) ;
178
+ return client . fetchPodcastRegions ( {
179
+ } ) . then ( ( response ) => {
180
+ expect ( response . config . url ) . toBe ( '/regions' ) ;
181
+ expect ( response . config . method ) . toBe ( 'get' ) ;
182
+ expect ( response . data . regions ) . not . toBeNull ( ) ;
183
+ } ) . catch ( ( ) => {
184
+ fail ( 'Failed!' ) ;
185
+ } ) ;
186
+ } ) ;
187
+
188
+ test ( 'Test fetchPodcastLanguages with mock' , ( ) => {
189
+ const client = Client ( ) ;
190
+ return client . fetchPodcastLanguages ( {
191
+ } ) . then ( ( response ) => {
192
+ expect ( response . config . url ) . toBe ( '/languages' ) ;
193
+ expect ( response . config . method ) . toBe ( 'get' ) ;
194
+ expect ( response . data . languages . length > 0 ) . toBe ( true ) ;
195
+ } ) . catch ( ( ) => {
196
+ fail ( 'Failed!' ) ;
197
+ } ) ;
198
+ } ) ;
199
+
200
+ test ( 'Test justListen with mock' , ( ) => {
201
+ const client = Client ( ) ;
202
+ return client . justListen ( {
203
+ } ) . then ( ( response ) => {
204
+ expect ( response . config . url ) . toBe ( '/just_listen' ) ;
205
+ expect ( response . config . method ) . toBe ( 'get' ) ;
206
+ expect ( response . data . audio_length_sec > 0 ) . toBe ( true ) ;
207
+ } ) . catch ( ( ) => {
208
+ fail ( 'Failed!' ) ;
209
+ } ) ;
210
+ } ) ;
211
+
212
+ test ( 'Test fetchRecommendationsForPodcast with mock' , ( ) => {
213
+ const client = Client ( ) ;
214
+ const podcastId = 'abcde' ;
215
+ return client . fetchRecommendationsForPodcast ( {
216
+ id : podcastId ,
217
+ } ) . then ( ( response ) => {
218
+ expect ( response . config . url ) . toBe ( `/podcasts/${ podcastId } /recommendations` ) ;
219
+ expect ( response . config . method ) . toBe ( 'get' ) ;
220
+ expect ( response . data . recommendations . length > 0 ) . toBe ( true ) ;
221
+ } ) . catch ( ( ) => {
222
+ fail ( 'Failed!' ) ;
223
+ } ) ;
224
+ } ) ;
225
+
226
+ test ( 'Test fetchRecommendationsForEpisode with mock' , ( ) => {
227
+ const client = Client ( ) ;
228
+ const episodeId = 'abc222de' ;
229
+ return client . fetchRecommendationsForEpisode ( {
230
+ id : episodeId ,
231
+ } ) . then ( ( response ) => {
232
+ expect ( response . config . url ) . toBe ( `/episodes/${ episodeId } /recommendations` ) ;
233
+ expect ( response . config . method ) . toBe ( 'get' ) ;
234
+ expect ( response . data . recommendations . length > 0 ) . toBe ( true ) ;
235
+ } ) . catch ( ( ) => {
236
+ fail ( 'Failed!' ) ;
237
+ } ) ;
238
+ } ) ;
239
+
240
+ test ( 'Test fetchPlaylistById with mock' , ( ) => {
241
+ const client = Client ( ) ;
242
+ const playlistId = 'abddc222de' ;
243
+ return client . fetchPlaylistById ( {
244
+ id : playlistId ,
245
+ } ) . then ( ( response ) => {
246
+ expect ( response . config . url ) . toBe ( `/playlists/${ playlistId } ` ) ;
247
+ expect ( response . config . method ) . toBe ( 'get' ) ;
248
+ expect ( response . data . items . length > 0 ) . toBe ( true ) ;
249
+ } ) . catch ( ( ) => {
250
+ fail ( 'Failed!' ) ;
251
+ } ) ;
252
+ } ) ;
253
+
254
+ test ( 'Test fetchMyPlaylists with mock' , ( ) => {
255
+ const client = Client ( ) ;
256
+ return client . fetchMyPlaylists ( {
257
+ } ) . then ( ( response ) => {
258
+ expect ( response . config . url ) . toBe ( '/playlists' ) ;
259
+ expect ( response . config . method ) . toBe ( 'get' ) ;
260
+ expect ( response . data . total > 0 ) . toBe ( true ) ;
261
+ } ) . catch ( ( ) => {
262
+ fail ( 'Failed!' ) ;
263
+ } ) ;
264
+ } ) ;
265
+
266
+ test ( 'Test submitPodcast with mock' , ( ) => {
267
+ const client = Client ( ) ;
268
+ const rss = 'http://myrss.com/rss' ;
269
+ return client . submitPodcast ( {
270
+ rss,
271
+ } ) . then ( ( response ) => {
272
+ expect ( response . config . url ) . toBe ( '/podcasts/submit' ) ;
273
+ expect ( response . config . method ) . toBe ( 'post' ) ;
274
+ expect ( JSON . parse ( response . config . data ) . rss ) . toBe ( rss ) ;
275
+ expect ( response . data . status . length > 0 ) . toBe ( true ) ;
276
+ } ) . catch ( ( ) => {
277
+ fail ( 'Failed!' ) ;
278
+ } ) ;
279
+ } ) ;
280
+
281
+ test ( 'Test deletePodcast with mock' , ( ) => {
282
+ const client = Client ( ) ;
283
+ const podcastId = 'asdfasdf' ;
284
+ const reason = 'abv' ;
285
+ return client . deletePodcast ( {
286
+ id : podcastId ,
287
+ reason,
288
+ } ) . then ( ( response ) => {
289
+ expect ( response . config . url ) . toBe ( `/podcasts/${ podcastId } ?reason=${ reason } ` ) ;
290
+ expect ( response . config . method ) . toBe ( 'delete' ) ;
291
+ expect ( response . data . status . length > 0 ) . toBe ( true ) ;
292
+ } ) . catch ( ( error ) => {
293
+ console . log ( error ) ;
294
+ fail ( 'Failed!' ) ;
295
+ } ) ;
296
+ } ) ;
0 commit comments