This repository has been archived by the owner on Nov 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.test.js
267 lines (223 loc) · 10.4 KB
/
main.test.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/* eslint-disable no-underscore-dangle */
const dotenv = require('dotenv');
dotenv.config();
const hive = require('./dist/hive').default;
const hiveAPI = hive({ apiKey: process.env.APIKEY });
// Two types of test, unit tests with mocking and integrations tests using live API
test('API Key returns same API Key in env', () => {
expect(hiveAPI.apiKey).toBe(process.env.APIKEY);
});
describe('Change Defaults', () => {
test('Change format', () => {
const testAPI = hive({ apiKey: process.env.APIKEY, defaultFormat: 'id' });
expect(testAPI.defaultFormat).toBe('id');
});
test('Change Host', () => {
const testAPI = hive({ apiKey: process.env.APIKEY, host: 'https://test.com' });
expect(testAPI.host).toBe('https://test.com');
});
});
describe('Integration Tests With Live API', () => {
describe('Available Influencers', () => {
test('Default params', async () => {
const response = await hiveAPI.availableInfluncers();
expect(typeof (response)).toBe('object');
expect(typeof (response[0])).toBe('string');
});
test('screenName format', async () => {
const response = await hiveAPI.availableInfluncers({ format: 'screenName' });
expect(typeof (response)).toBe('object');
expect(typeof (response[0])).toBe('string');
});
test('Id format', async () => {
const response = await hiveAPI.availableInfluncers({ format: 'id' });
expect(typeof (response)).toBe('object');
expect(typeof (response[0])).toBe('string');
expect(typeof (parseInt(response[0], 10))).toBe('number');
});
test('Nonsense Format', async () => {
await expect(hiveAPI.availableInfluncers({ format: 'nonsense' }))
.rejects
.toThrow(Error);
});
test('Etag', async () => {
const response = await hiveAPI.availableInfluncers({ format: 'id' });
const etagResponse = await hiveAPI.availableInfluncers({ format: 'id', etag: response._etag });
expect(etagResponse).toBe(true);
expect(typeof (etagResponse)).toBe('boolean');
});
});
describe('Top Influencers', () => {
test('Default params', async () => {
const response = await hiveAPI.topInfluencers();
expect(typeof (response)).toBe('object');
expect(typeof (response[0])).toBe('object');
});
test('Crypto', async () => {
const response = await hiveAPI.topInfluencers({ cluster: 'Crypto' });
expect(typeof (response)).toBe('object');
expect(typeof (response[0])).toBe('object');
});
test('BTC', async () => {
const response = await hiveAPI.topInfluencers({ cluster: 'BTC' });
expect(typeof (response)).toBe('object');
expect(typeof (response[0])).toBe('object');
});
test('ETH', async () => {
const response = await hiveAPI.topInfluencers({ cluster: 'ETH' });
expect(typeof (response)).toBe('object');
expect(typeof (response[0])).toBe('object');
});
test('XRP', async () => {
const response = await hiveAPI.topInfluencers({ cluster: 'XRP' });
expect(typeof (response)).toBe('object');
expect(typeof (response[0])).toBe('object');
});
test('Paginate', async () => {
const response = await hiveAPI.topInfluencers({ after: 100 });
expect(typeof (response)).toBe('object');
expect(typeof (response[0])).toBe('object');
});
test('Incorrect Cluster', async () => {
await expect(hiveAPI.topInfluencers({ cluster: 'ECoin' }))
.rejects
.toThrow(Error);
});
test('Change Sort', async () => {
const response = await hiveAPI.topInfluencers({ sort: 'change_week', order: 'desc' });
const firstRank = response[0].rank;
const secondRank = response[1].rank;
expect(secondRank).not.toBe(firstRank + 1);
});
test('Etag', async () => {
const response = await hiveAPI.topInfluencers({ sort: 'change_week', order: 'desc' });
const etagResponse = await hiveAPI.topInfluencers({ sort: 'change_week', order: 'desc', etag: response._etag });
expect(etagResponse).toBe(true);
expect(typeof (etagResponse)).toBe('boolean');
});
});
describe('Influencer Details', () => {
test('Nothing Passed', async () => {
await expect(hiveAPI.influencerDetails())
.rejects
.toThrow(Error);
});
test('Default Params', async () => {
const response = await hiveAPI.influencerDetails({ influencerId: 'aantonop' });
expect(typeof (response)).toBe('object');
expect(response.screenName).toBe('aantonop');
});
test('Rank Type', async () => {
const response = await hiveAPI.influencerDetails({ influencerId: 'aantonop', rankType: 'personal' });
expect(typeof (response)).toBe('object');
expect(response.screenName).toBe('aantonop');
});
test('Include Followers', async () => {
const response = await hiveAPI.influencerDetails({ influencerId: 'aantonop', includeFollowers: 1 });
expect(typeof (response)).toBe('object');
expect(response.screenName).toBe('aantonop');
expect(Object.prototype.hasOwnProperty.call(response.scores[0], 'followers')).toBe(true);
});
test('Unsupported Rank Type', async () => {
await expect(hiveAPI.influencerDetails({ influencerId: 'aantonop', rankType: 'biz' }))
.rejects
.toThrow(Error);
});
test('Unsupported Followers - Int', async () => {
await expect(hiveAPI.influencerDetails({ influencerId: 'aantonop', includeFollowers: 3 }))
.rejects
.toThrow(Error);
});
test('Unsupported Followers - String', async () => {
await expect(hiveAPI.influencerDetails({ influencerId: 'aantonop', includeFollowers: '0' }))
.rejects
.toThrow(Error);
});
test('Etag', async () => {
const response = await hiveAPI.influencerDetails({ influencerId: 'aantonop', includeFollowers: 1 });
const etagResponse = await hiveAPI.influencerDetails({ influencerId: 'aantonop', includeFollowers: 1, etag: response._etag });
expect(etagResponse).toBe(true);
expect(typeof (etagResponse)).toBe('boolean');
});
// TODO: Screen Name
// TODO: ID
});
describe('Influencer Podcasts', () => {
test('Nothing Passed', async () => {
await expect(hiveAPI.influencerPodcasts())
.rejects
.toThrow(Error);
});
test('Default Params', async () => {
const response = await hiveAPI.influencerPodcasts({ influencerId: 'laurashin' });
expect(typeof (response)).toBe('object');
expect(response.screenName).toBe('laurashin');
expect(Object.prototype.hasOwnProperty.call(response, 'podcasts')).toBe(true);
});
test('Appearance Type', async () => {
const response = await hiveAPI.influencerPodcasts({ influencerId: 'laurashin', appearanceType: 'guest' });
expect(typeof (response)).toBe('object');
expect(response.screenName).toBe('laurashin');
expect(Object.prototype.hasOwnProperty.call(response, 'podcasts')).toBe(true);
});
test('After', async () => {
const response = await hiveAPI.influencerPodcasts({ influencerId: 'laurashin', after: 20 });
expect(typeof (response)).toBe('object');
expect(response.screenName).toBe('laurashin');
expect(Object.prototype.hasOwnProperty.call(response, 'podcasts')).toBe(true);
});
test('Unsupported Appearance Type', async () => {
await expect(hiveAPI.influencerPodcasts({ influencerId: 'laurashin', appearanceType: 'audience' }))
.rejects
.toThrow(Error);
});
test('Unsupported After Type', async () => {
await expect(hiveAPI.influencerPodcasts({ influencerId: 'laurashin', after: '20' }))
.rejects
.toThrow(Error);
});
test('Etag', async () => {
const response = await hiveAPI.influencerPodcasts({ influencerId: 'laurashin', appearanceType: 'guest' });
const etagResponse = await hiveAPI.influencerPodcasts({ influencerId: 'laurashin', appearanceType: 'guest', etag: response._etag });
expect(etagResponse).toBe(true);
expect(typeof (etagResponse)).toBe('boolean');
});
});
describe('Influencer Batch', () => {
test('Nothing Passed', async () => {
await expect(hiveAPI.influencerBatch())
.rejects
.toThrow(Error);
});
test('Default Params', async () => {
const response = await hiveAPI.influencerBatch({ influencerIDS: [12, 34] });
expect(typeof (response)).toBe('object');
});
test('Rank Type', async () => {
const response = await hiveAPI.influencerBatch({ influencerIDS: [12, 34], rankType: 'personal' });
expect(typeof (response)).toBe('object');
});
test('Include Followers', async () => {
jest.setTimeout(30000);
const response = await hiveAPI.influencerBatch(
{ influencerIDS: [12, 34], includeFollowers: 1 },
);
expect(typeof (response)).toBe('object');
});
test('Unsupported Rank Type', async () => {
await expect(hiveAPI.influencerBatch({ influencerIDS: [12, 34], rankType: 'biz' }))
.rejects
.toThrow(Error);
});
test('Unsupported Followers - Int', async () => {
await expect(hiveAPI.influencerBatch({ influencerIDS: [12, 34], includeFollowers: 2 }))
.rejects
.toThrow(Error);
});
test('Unsupported Followers - String', async () => {
await expect(hiveAPI.influencerBatch({ influencerIDS: [12, 34], includeFollowers: '1' }))
.rejects
.toThrow(Error);
});
});
});