-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.spec.js
128 lines (124 loc) · 4.82 KB
/
index.spec.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
const
chai = require('chai'),
{ expect } = chai;
const Instagram = require('.');
const {
SESSION_ID,
PUBLIC_PROFILE,
PUBLIC_PROFILE_ID,
PRIVATE_PROFILE,
STORY_PROFILE_ID,
STORY_PROFILE_USERNAME,
HASHTAG = 'cat',
LOCATION_ID = '6889842',
POST,
SEARCH_PROFILE,
SEARCH_HASHTAG = 'cats',
SEARCH_LOCATION = 'Paris',
GET_COUNT = 20
} = process.env;
chai.use(require('chai-as-promised'));
describe('scraper-instagram', () => {
describe('Authentication', () => {
(SESSION_ID ? describe : describe.skip)('By session ID', () => {
let client;
before(() => client = new Instagram());
it('authenticates', () => expect(client.authBySessionId(SESSION_ID)).to.be.fulfilled);
describe('Get own profile', () => {
let profile;
it(
'gets profile',
async () => expect(profile = await client.getProfile()).to.be.an('object')
);
it('has access', () => expect(profile.access).to.be.true);
});
describe('Account', () => {
it('gets notifications', () => expect(client.getAccountNotifications()).to.be.fulfilled);
it('gets stories', () => expect(client.getAccountStories()).to.be.fulfilled).timeout(5000);
});
});
});
describe('Get profile', () => {
let client;
before(() => client = new Instagram());
(PUBLIC_PROFILE ? describe : describe.skip)('Get public profile', () => {
let profile;
it(
'gets profile',
async () => expect(profile = await client.getProfile(PUBLIC_PROFILE)).to.be.an('object')
);
it('has access', () => expect(profile.access).to.be.true);
});
(PRIVATE_PROFILE ? describe : describe.skip)('Get private profile', () => {
describe('Without authentication', () => {
let profile;
it(
'gets profile',
async () => expect(profile = await client.getProfile(PRIVATE_PROFILE)).to.be.an('object')
);
it('has no access', () => expect(profile.access).to.be.false);
});
(SESSION_ID ? describe : describe.skip)('With authentication', () => {
before(async () => await client.authBySessionId(SESSION_ID));
let profile;
it(
'gets profile',
async () => expect(profile = await client.getProfile(PRIVATE_PROFILE)).to.be.an('object')
);
it('has access', () => expect(profile.access).to.be.true);
});
});
});
(SESSION_ID ? describe : describe.skip)('Get profile story', () => {
let client;
before(async () => {
client = new Instagram();
await client.authBySessionId(SESSION_ID);
});
(STORY_PROFILE_ID ? it : it.skip)('gets story by ID', () => expect(client.getProfileStoryById(STORY_PROFILE_ID)).to.be.fulfilled).timeout(5000);
(STORY_PROFILE_USERNAME ? it : it.skip)('gets story by username', () => expect(client.getProfileStory(STORY_PROFILE_USERNAME)).to.be.fulfilled).timeout(5000);
});
(SESSION_ID ? describe : describe.skip)('Get profile posts', () => {
let client;
before(async () => {
client = new Instagram();
await client.authBySessionId(SESSION_ID);
});
(PUBLIC_PROFILE ? it : it.skip)('gets posts by ID', () => expect(client.getProfilePostsById(PUBLIC_PROFILE_ID, +GET_COUNT)).to.be.fulfilled).timeout(5000);
(PUBLIC_PROFILE_ID ? it : it.skip)('gets posts by username', () => expect(client.getProfilePosts(PUBLIC_PROFILE, +GET_COUNT)).to.be.fulfilled).timeout(5000);
});
describe('Get hashtag', () => {
let client;
before(() => client = new Instagram());
it('gets hashtag', () => expect(client.getHashtag(HASHTAG)).to.be.fulfilled).timeout(5000);
(SESSION_ID ? it : it.skip)('gets hashtag posts', () => {
before(async () => await client.authBySessionId(SESSION_ID));
expect(client.getHashtagPosts(HASHTAG, +GET_COUNT)).to.be.fulfilled;
});
});
describe('Get location', () => {
let client;
before(() => client = new Instagram());
it('gets location by ID', () => expect(client.getLocation(LOCATION_ID)).to.be.fulfilled).timeout(8000);
(SESSION_ID ? it : it.skip)('gets location posts by ID', () => {
before(async () => await client.authBySessionId(SESSION_ID));
expect(client.getLocationPostsById(LOCATION_ID, +GET_COUNT)).to.be.fulfilled;
});
});
(POST ? describe : describe.skip)('Get post', () => {
let client;
before(() => client = new Instagram());
it('gets post', () => expect(client.getPost(POST)).to.be.fulfilled);
(SESSION_ID ? it : it.skip)('gets post comments', () => {
before(async () => await client.authBySessionId(SESSION_ID));
expect(client.getPostComments(POST, +GET_COUNT)).to.be.fulfilled;
});
});
describe('Search', () => {
let client;
before(() => client = new Instagram());
(SEARCH_PROFILE ? it : it.skip)('searches profile', () => expect(client.searchProfile(SEARCH_PROFILE)).to.be.fulfilled);
(SEARCH_HASHTAG ? it : it.skip)('searches hashtag', () => expect(client.searchHashtag(SEARCH_HASHTAG)).to.be.fulfilled);
(SEARCH_LOCATION ? it : it.skip)('searches location', () => expect(client.searchLocation(SEARCH_LOCATION)).to.be.fulfilled);
});
});