Skip to content

Commit

Permalink
Fix variable number of reviews returned #676 (#677)
Browse files Browse the repository at this point in the history
  • Loading branch information
petskratt authored Apr 9, 2024
1 parent 2fa6157 commit c0bdcec
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 5 deletions.
6 changes: 6 additions & 0 deletions lib/utils/request.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import requestLib from 'got';
import throttled from './throttle.js';
import { CookieJar } from 'tough-cookie';
import createDebug from 'debug';

const cookieJar = new CookieJar();
const debug = createDebug('google-play-scraper');

function doRequest (opts, limit) {
let req;

// cookies are necessary for pagination to work consistently across requests
opts.cookieJar = cookieJar;

if (limit) {
req = throttled(
requestLib, {
Expand Down
93 changes: 89 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"debug": "^3.1.0",
"got": "^11.8.6",
"memoizee": "^0.4.14",
"ramda": "^0.29.0"
"ramda": "^0.29.0",
"tough-cookie": "^4.1.3"
},
"devDependencies": {
"chai": "^4.3.7",
Expand Down
21 changes: 21 additions & 0 deletions test/lib.reviews.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,25 @@ describe('Reviews method', () => {
assert.isNotNull(secondPaginationToken);
assert.notDeepEqual(data, dataSecondPage);
});

it('should get same set of reviews on each run', async () => {
const firstPageReviews = await gplay.reviews({
appId: 'com.facebook.katana',
num: 1500,
sort: constants.sort.HELPFULNESS
});
const { data } = firstPageReviews;

assert.equal(data.length, 1500);

const secondPageReviews = await gplay.reviews({
appId: 'com.facebook.katana',
num: 1500,
sort: constants.sort.HELPFULNESS
});
const { data: dataSecondPage } = secondPageReviews;

assert.equal(dataSecondPage.length, 1500);
assert.deepEqual(data, dataSecondPage);
});
});

0 comments on commit c0bdcec

Please sign in to comment.