-
-
Notifications
You must be signed in to change notification settings - Fork 621
/
lib.reviews.js
105 lines (94 loc) · 3.04 KB
/
lib.reviews.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
import gplay from '../index.js';
import { assert } from 'chai';
import { assertValidUrl } from './common.js';
import { constants } from '../lib/constants.js';
function assertValid (review) {
assert.isString(review.id);
assert(review.id);
assert.isString(review.userName);
assertValidUrl(review.userImage);
assert(review.userName);
assert.isNotNull(new Date(review.date).toJSON());
assert.isString(review.date);
assert(review.date);
assert.isNull(review.title);
assert.isString(review.text);
assert.isNumber(review.score);
assert(review.score > 0);
assert(review.score <= 5);
assertValidUrl(review.url);
assert.hasAnyKeys(review, 'replyDate');
assert.hasAnyKeys(review, 'replyText');
assert.hasAnyKeys(review, 'version');
assert.hasAnyKeys(review, 'thumbsUp');
assert.hasAnyKeys(review, 'criterias');
}
describe('Reviews method', () => {
it('should retrieve the most recent reviews of an app', () => {
return gplay.reviews({ appId: 'com.dxco.pandavszombies' })
.then((reviews) => {
reviews.data.map(assertValid);
});
});
it('should retrieve the most helpfull reviews of an app', () => {
return gplay.reviews({
appId: 'com.dxco.pandavszombies',
sort: constants.sort.HELPFULNESS
})
.then((reviews) => {
reviews.data.map(assertValid);
});
});
it('should retrieve the most rated reviews of an app', () => {
return gplay.reviews({
appId: 'com.dxco.pandavszombies',
sort: constants.sort.RATING
})
.then((reviews) => {
reviews.data.map(assertValid);
});
});
it('should validate the sort', () => {
return gplay.reviews({
appId: 'com.dxco.pandavszombies',
sort: 'invalid'
})
.then(assert.fail)
.catch((e) => assert.equal(e.message, 'Invalid sort invalid'));
});
it('should retrieve the reviews of an app in Japanese', () => {
return gplay.reviews({ appId: 'com.dxco.pandavszombies', lang: 'ja' })
.then((reviews) => {
reviews.data.map(assertValid);
});
});
it('should accept pagination', () => {
return gplay.reviews({
appId: 'com.facebook.katana',
paginate: true
})
.then((reviews) => {
reviews.data.map(assertValid);
assert.equal(reviews.data.length, 150);
assert.isNotNull(reviews.nextPaginationToken);
});
});
it('should get different reviews for nextPageToken', async () => {
const firstPageReviews = await gplay.reviews({
appId: 'com.facebook.katana',
paginate: true
});
const { data, nextPaginationToken } = firstPageReviews;
assert.equal(data.length, 150);
assert.isNotNull(nextPaginationToken);
const secondPageReviews = await gplay.reviews({
appId: 'com.facebook.katana',
paginate: true,
nextPaginationToken
});
const { data: dataSecondPage, nextPaginationToken: secondPaginationToken } = secondPageReviews;
assert.equal(dataSecondPage.length, 150);
assert.isNotNull(secondPaginationToken);
assert.notDeepEqual(data, dataSecondPage);
});
});