Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests and thread bug #79

Merged
merged 4 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 20 additions & 10 deletions src/auth.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { getScraper } from './test-utils';

test('scraper can log in', async () => {
const scraper = await getScraper({ authMethod: 'password' });
await expect(scraper.isLoggedIn()).resolves.toBeTruthy();
}, 15000);
const testLogin = process.env['TWITTER_PASSWORD'] ? test : test.skip;

testLogin(
'scraper can log in',
async () => {
const scraper = await getScraper({ authMethod: 'password' });
await expect(scraper.isLoggedIn()).resolves.toBeTruthy();
},
15000,
);

test('scraper can log in with cookies', async () => {
const scraper = await getScraper();
Expand All @@ -22,11 +28,15 @@ test('scraper can restore its login state from cookies', async () => {
await expect(scraper2.isLoggedIn()).resolves.toBeTruthy();
});

test('scraper can log out', async () => {
const scraper = await getScraper({ authMethod: 'password' });
await expect(scraper.isLoggedIn()).resolves.toBeTruthy();
testLogin(
'scraper can log out',
async () => {
const scraper = await getScraper({ authMethod: 'password' });
await expect(scraper.isLoggedIn()).resolves.toBeTruthy();

await scraper.logout();
await scraper.logout();

await expect(scraper.isLoggedIn()).resolves.toBeFalsy();
}, 15000);
await expect(scraper.isLoggedIn()).resolves.toBeFalsy();
},
15000,
);
3 changes: 2 additions & 1 deletion src/profile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ test('scraper can get partial private profile', async () => {

test('scraper cannot get suspended profile', async () => {
const scraper = await getScraper();
expect(scraper.getProfile('123')).rejects.toThrow();
// taken from https://en.wikipedia.org/wiki/Twitter_suspensions#List_of_notable_suspensions
expect(scraper.getProfile('RobertC20041800')).rejects.toThrow();
});

test('scraper cannot get not found profile', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/timeline-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ export function parseThreadedConversation(
}

for (const item of entry.content?.items ?? []) {
const itemContent = item.item?.content;
const itemContent = item.item?.itemContent;
if (itemContent) {
parseAndPush(tweets, itemContent, entry.entryId, true);
}
Expand Down
32 changes: 19 additions & 13 deletions src/tweets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,23 +223,29 @@ test('scraper can get tweet quotes and replies', async () => {

test('scraper can get retweet', async () => {
const expected: Tweet = {
conversationId: '1359151057872580612',
html: `We’ve seen an increase in attacks against Asian communities and individuals around the world. It’s important to know that this isn’t new; throughout history, Asians have experienced violence and exclusion. However, their diverse lived experiences have largely been overlooked.`,
id: '1359151057872580612',
conversationId: '1776276954435481937',
html: `<br><a href=\"https://t.co/qqiu5ntffp\"><img src=\"https://pbs.twimg.com/amplify_video_thumb/1776276900580622336/img/UknAtyWSZ286nCD3.jpg\"/></a>`,
id: '1776276954435481937',
hashtags: [],
mentions: [],
name: 'Twitter Together',
permanentUrl:
'https://twitter.com/TwitterTogether/status/1359151057872580612',
name: 'federico.',
permanentUrl: 'https://twitter.com/federicosmos/status/1776276954435481937',
photos: [],
text: 'We’ve seen an increase in attacks against Asian communities and individuals around the world. It’s important to know that this isn’t new; throughout history, Asians have experienced violence and exclusion. However, their diverse lived experiences have largely been overlooked.',
text: 'https://t.co/qqiu5ntffp',
thread: [],
timeParsed: new Date(Date.UTC(2021, 1, 9, 14, 43, 58, 0)),
timestamp: 1612881838,
timeParsed: new Date(Date.UTC(2024, 3, 5, 15, 53, 22, 0)),
timestamp: 1712332402,
urls: [],
userId: '773578328498372608',
username: 'TwitterTogether',
videos: [],
userId: '2376017065',
username: 'federicosmos',
videos: [
{
id: '1776276900580622336',
preview:
'https://pbs.twimg.com/amplify_video_thumb/1776276900580622336/img/UknAtyWSZ286nCD3.jpg',
url: 'https://video.twimg.com/amplify_video/1776276900580622336/vid/avc1/640x360/uACt_egp_hmvPOZF.mp4?tag=14',
},
],
isQuoted: false,
isReply: false,
isRetweet: false,
Expand All @@ -248,7 +254,7 @@ test('scraper can get retweet', async () => {
};

const scraper = await getScraper();
const retweet = await scraper.getTweet('1685032881872330754');
const retweet = await scraper.getTweet('1776285549566808397');
expect(retweet?.isRetweet).toBeTruthy();
delete retweet?.retweetedStatus?.likes;
delete retweet?.retweetedStatus?.replies;
Expand Down
Loading