forked from elizaOS/agent-twitter-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.test.ts
79 lines (61 loc) · 1.82 KB
/
search.test.ts
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
import { getScraper } from './test-utils';
import { SearchMode } from './search';
import { QueryTweetsResponse } from './timeline-v1';
test('scraper can process search cursor', async () => {
const scraper = await getScraper();
let cursor: string | undefined = undefined;
const maxTweets = 30;
let nTweets = 0;
while (nTweets < maxTweets) {
const res: QueryTweetsResponse = await scraper.fetchSearchTweets(
'twitter',
maxTweets,
SearchMode.Top,
cursor,
);
expect(res.next).toBeTruthy();
nTweets += res.tweets.length;
cursor = res.next;
}
}, 30000);
test('scraper can search profiles', async () => {
const scraper = await getScraper();
const seenProfiles = new Map<string, boolean>();
const maxProfiles = 150;
let nProfiles = 0;
const profiles = scraper.searchProfiles('Twitter', maxProfiles);
for await (const profile of profiles) {
nProfiles++;
const profileId = profile.userId;
expect(profileId).toBeTruthy();
if (profileId != null) {
expect(seenProfiles.has(profileId)).toBeFalsy();
seenProfiles.set(profileId, true);
}
}
expect(nProfiles).toEqual(maxProfiles);
}, 30000);
test('scraper can search tweets', async () => {
const scraper = await getScraper();
const seenTweets = new Map<string, boolean>();
const maxTweets = 150;
let nTweets = 0;
const profiles = scraper.searchTweets(
'twitter',
maxTweets,
SearchMode.Latest,
);
for await (const tweet of profiles) {
nTweets++;
const id = tweet.id;
expect(id).toBeTruthy();
if (id != null) {
expect(seenTweets.has(id)).toBeFalsy();
seenTweets.set(id, true);
}
expect(tweet.permanentUrl).toBeTruthy();
expect(tweet.isRetweet).toBeFalsy();
expect(tweet.text).toBeTruthy();
}
expect(nTweets).toEqual(maxTweets);
}, 30000);