-
-
Notifications
You must be signed in to change notification settings - Fork 244
/
lib.app.js
166 lines (144 loc) · 5.26 KB
/
lib.app.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
'use strict';
const assert = require('chai').assert;
const assertValidUrl = require('./common').assertValidUrl;
const store = require('../index');
describe('App method', () => {
it('should fetch valid application data', () => {
return store.app({id: '553834731'})
.then((app) => {
assert.equal(app.appId, 'com.midasplayer.apps.candycrushsaga');
assert.equal(app.title, 'Candy Crush Saga');
assert.equal(app.url, 'https://apps.apple.com/us/app/candy-crush-saga/id553834731?uo=4');
assertValidUrl(app.icon);
assert.isNumber(app.score);
assert(app.score > 0);
assert(app.score <= 5);
assert.isNotOk(app.ratings);
assert.isNotOk(app.histogram);
assert.isNumber(app.reviews);
assert.isString(app.description);
assert.isString(app.updated);
assert.equal(app.primaryGenre, 'Games');
assert.equal(app.primaryGenreId, 6014);
assert.isArray(app.genres);
assert.isAtLeast(app.genres.length, 1);
assert.isArray(app.genreIds);
assert.isAtLeast(app.genreIds.length, 1);
assert.isString(app.version);
if (app.size) {
assert.isString(app.size);
}
assert.isString(app.contentRating);
assert.isString(app.requiredOsVersion);
assert.equal(app.price, '0');
assert(app.free === true);
assert.equal(app.developer, 'King');
if (app.developerWebsite) {
assertValidUrl(app.developerWebsite);
}
assert(app.screenshots.length);
app.screenshots.map(assertValidUrl);
assert.isString(app.releaseNotes);
});
});
describe('with ratings option enabled', () => {
it('should fetch valid application data', () => {
return store.app({id: '553834731', ratings: true})
.then((app) => {
assert.isNumber(app.ratings);
assert.isObject(app.histogram);
assert.isNumber(app.histogram['1']);
assert.isNumber(app.histogram['2']);
assert.isNumber(app.histogram['3']);
assert.isNumber(app.histogram['4']);
assert.isNumber(app.histogram['5']);
});
});
it('should fetch app with bundle id', () => {
return store.app({appId: 'com.midasplayer.apps.candycrushsaga', ratings: true})
.then((app) => {
assert.isNumber(app.ratings);
assert.isObject(app.histogram);
assert.isNumber(app.histogram['1']);
assert.isNumber(app.histogram['2']);
assert.isNumber(app.histogram['3']);
assert.isNumber(app.histogram['4']);
assert.isNumber(app.histogram['5']);
});
});
});
it('should fetch app with bundle id', () => {
return store.app({appId: 'com.midasplayer.apps.candycrushsaga'})
.then((app) => {
assert.equal(app.id, '553834731');
assert.equal(app.title, 'Candy Crush Saga');
assert.equal(app.url, 'https://apps.apple.com/us/app/candy-crush-saga/id553834731?uo=4');
assert.isNotOk(app.ratings);
assert.isNotOk(app.histogram);
});
});
it('should fetch app in spanish', () => {
return store.app({id: '553834731', country: 'ar'})
.then((app) => {
assert.equal(app.appId, 'com.midasplayer.apps.candycrushsaga');
assert.equal(app.title, 'Candy Crush Saga');
assert.equal(app.url, 'https://apps.apple.com/ar/app/candy-crush-saga/id553834731?uo=4');
});
});
it('should fetch app in french', () => {
return store.app({id: '553834731', country: 'fr'})
.then((app) => {
assert.equal(app.appId, 'com.midasplayer.apps.candycrushsaga');
assert.equal(app.title, 'Candy Crush Saga');
assert.equal(app.url, 'https://apps.apple.com/fr/app/candy-crush-saga/id553834731?uo=4');
});
});
it('should reject the promise for an invalid id', (done) => {
store.app({id: '123'})
.then(() => done('should not resolve'))
.catch((err) => {
assert.equal(err.message, 'App not found (404)');
done();
})
.catch(done);
});
it('should reject the promise for an invalid appId', (done) => {
store.app({appId: '123'})
.then(() => done('should not resolve'))
.catch((err) => {
assert.equal(err.message, 'App not found (404)');
done();
})
.catch(done);
});
it('should memoize the results when memoize enabled', () => {
const memoized = store.memoized();
return memoized.app({id: '553834731'})
.then((app) => {
assert.equal(app.appId, 'com.midasplayer.apps.candycrushsaga');
assert.equal(app.title, 'Candy Crush Saga');
});
});
it('should memoize the results with custom options', () => {
const memoized = store.memoized({maxAge: 1000, max: 10});
return memoized.app({id: '553834731'})
.then((app) => {
assert.equal(app.appId, 'com.midasplayer.apps.candycrushsaga');
assert.equal(app.title, 'Candy Crush Saga');
});
});
it('should be able to set requestOptions', (done) => {
store.app({
id: '553834731',
requestOptions: {
method: 'DELETE'
}
})
.then(() => done('should not resolve'))
.catch((err) => {
assert.equal(err.response.statusCode, 501);
done();
})
.catch(done);
});
});