deno.land / x / google_play_scraper@v10.0.0 / test / lib.list.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import { assert } from 'chai';import { assertValidApp, assertValidUrl } from './common.js';import validator from 'validator';import gplay from '../index.js';
describe('List method', () => { const timeout = 20 * 1000;
it('should throw and error if the given collection does not exist', () => { const collection = gplay.collection.TRENDING;
return gplay.list({ collection, num: 100 }) .catch((error) => { assert.equal(error.message, `The collection ${collection} is invalid for the given category, top apps or new apps`); }); });
it('should throw and error if the given collection exists but have no clusters', () => { const collection = gplay.collection.NEW_FREE;
return gplay.list({ collection, category: gplay.category.BUSINESS, num: 100 }) .catch((error) => { assert.equal(error.message, `The collection ${collection} is invalid for the given category, top apps or new apps`); }); });
it('should fetch a valid application list for the top free collection', () => { return gplay.list({ collection: gplay.collection.TOP_FREE, num: 100 }) .then((apps) => apps.map(assertValidApp)) .then((apps) => apps.map((app) => assert(app.free))); }).timeout(timeout);
it('should fetch a valid application list for the top paid collection', () => { return gplay.list({ collection: gplay.collection.TOP_PAID, num: 100 }) .then((apps) => apps.map(assertValidApp)) .then((apps) => apps.map((app) => assert.isFalse(app.free))); }).timeout(timeout);
it('should fetch a valid application list for the new free collection', () => { return gplay.list({ collection: gplay.collection.NEW_FREE, num: 100 }) .then((apps) => apps.map(assertValidApp)) .then((apps) => apps.map((app) => assert(app.free))); }).timeout(timeout);
it('should fetch a valid application list for the new games free collection', () => { return gplay.list({ collection: gplay.collection.NEW_FREE_GAMES, num: 100 }) .then((apps) => apps.map(assertValidApp)) .then((apps) => apps.map((app) => assert(app.free))); }).timeout(timeout);
it('should fetch a valid application on a given collection regardless of the language', () => { return gplay.list({ collection: gplay.collection.TOP_FREE, country: 'ru', lang: 'ru', num: 5 }) .then((apps) => apps.map(assertValidApp)) .then((apps) => apps.map((app) => assert(app.free))); }).timeout(timeout);
it('should fetch a valid application list for the given category and collection', () => { return gplay.list({ category: gplay.category.GAME_ACTION, collection: gplay.collection.TOP_FREE }) .then((apps) => apps.map(assertValidApp)) .then((apps) => apps.map((app) => assert(app.free))); }).timeout(timeout);
it('should fetch a valid application list for the new free collection and GAME category', () => { return gplay.list({ collection: gplay.collection.NEW_FREE, category: gplay.category.GAME, num: 100 }) .then((apps) => apps.map(assertValidApp)) .then((apps) => apps.map((app) => assert(app.free))); }).timeout(timeout);
it('should return error for application list for the new paid collection and FAMILY category', () => { const collection = gplay.collection.NEW_PAID;
return gplay.list({ collection, category: gplay.category.FAMILY, num: 100 }) .catch((error) => assert.equal(error.message, `The collection ${collection} is invalid for the given category, top apps or new apps`)); }).timeout(timeout);
it('should fetch apps for application list for the new free collection and FAMILY category', () => { return gplay.list({ collection: gplay.category.NEW_FREE, category: gplay.category.FAMILY, num: 100 }) .then((apps) => apps.map(assertValidApp)) .then((apps) => apps.map((app) => assert(app.free))); }).timeout(timeout);
it('should validate the category', () => { return gplay.list({ category: 'wrong', collection: gplay.collection.TOP_FREE }) .then(assert.fail) .catch((e) => assert.equal(e.message, 'Invalid category wrong')); });
it('should validate the collection', () => { return gplay.list({ category: gplay.category.GAME_ACTION, collection: 'wrong' }) .then(assert.fail) .catch((e) => assert.equal(e.message, 'Invalid collection wrong')); });
it('should validate the age range', () => { return gplay.list({ category: gplay.category.GAME_ACTION, collection: gplay.collection.TOP_FREE, age: 'elderly' }) .then(assert.fail) .catch((e) => assert.equal(e.message, 'Invalid age range elderly')); });
it('should fetch apps with fullDetail', () => { return gplay.list({ category: gplay.category.GAME_ACTION, collection: gplay.collection.TOP_FREE, fullDetail: true, num: 5 }) .then((apps) => apps.map(assertValidApp)) .then((apps) => apps.forEach((app) => { assert.isNumber(app.minInstalls); assert.isNumber(app.reviews);
assert.isString(app.description); assert.isString(app.descriptionHTML); assert.isString(app.released);
assert.equal(app.genre, 'Action'); assert.equal(app.genreId, 'GAME_ACTION');
assert.isString(app.version || ''); assert.isString(app.size || ''); assert.isString(app.androidVersionText); assert.isString(app.androidVersion); assert.isString(app.contentRating);
assert.equal(app.priceText, 'Free'); assert(app.free);
assert.isString(app.developer); assert.isString(app.developerId); if (app.developerWebsite) { assertValidUrl(app.developerWebsite); } assert(validator.isEmail(app.developerEmail), `${app.developerEmail} is not an email`);
['1', '2', '3', '4', '5'].map((v) => assert.property(app.histogram, v)); app.screenshots.map(assertValidUrl); app.comments.map(assert.isString); })); }).timeout(timeout);
// fetch last page of new paid apps, which have a bigger chance of including // results with no downloads (less fields, prone to failures) it('It should not fail with apps with no downloads', () => gplay.list({ category: gplay.category.GAME_ACTION, collection: gplay.collection.TOP_PAID, num: 20 }) .then((apps) => apps.map(assertValidApp)));
it('It should not fail with apps with no downloads and fullDetail', () => gplay.list({ category: gplay.category.GAME_ACTION, collection: gplay.collection.TOP_FREE, num: 10, fullDetail: true }) .then((apps) => apps.map(assertValidApp)) ).timeout(timeout);
it('should be able to retreive a list for each category', () => { const categoryIds = Object.keys(gplay.category);
const fetchCategory = (category) => gplay.list({ category, collection: gplay.collection.TOP_FREE, num: 10 }).catch(() => { if (category !== gplay.category.WATCH_FACE) { assert.equal(category, 0, 'invalid category'); } });
return Promise.all(categoryIds.map(fetchCategory)); }).timeout(200 * 1000);});
google_play_scraper

Version Info

Tagged at
9 months ago