Fixed tests

This commit is contained in:
dangered wolf 2022-10-22 20:24:25 -04:00
parent f63b4e74f8
commit 46fdb19457
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
2 changed files with 112 additions and 122 deletions

View file

@ -9,8 +9,6 @@
[![License][licensebadge]][license]
![Uptime][uptimebadge]
[![Join the Discord server][discordbadge]][discord]
<!-- Links & Badges -->
[icons]: https://skillicons.dev/icons?i=typescript,webpack,workers
@ -18,8 +16,6 @@
[webpackbadge]: https://github.com/FixTweet/FixTweet/actions/workflows/webpack.yml/badge.svg
[tests]: https://github.com/FixTweet/FixTweet/actions/workflows/tests.yml
[testsbadge]: https://github.com/FixTweet/FixTweet/actions/workflows/tests.yml/badge.svg
[discord]: https://discord.gg/6CQTTTkGaH
[discordbadge]: https://dcbadge.vercel.app/api/server/6CQTTTkGaH?style=flat
[license]: https://github.com/FixTweet/FixTweet/blob/main/LICENSE.md
[licensebadge]: https://img.shields.io/github/license/FixTweet/FixTweet
[uptimebadge]: https://img.shields.io/uptimerobot/ratio/m792476277-53add6f22c4e6f4d3a2d7e98

View file

@ -139,7 +139,7 @@ test('API fetch video Tweet', async () => {
test('API fetch multi-photo Tweet', async () => {
const result = await cacheWrapper(
new Request('https://api.fxtwitter.com/dangeredwolf/status/1554870933449482240', {
new Request('https://api.fxtwitter.com/Twitter/status/1445094085593866246', {
method: 'GET',
headers: botHeaders
})
@ -153,123 +153,117 @@ test('API fetch multi-photo Tweet', async () => {
const tweet = response.tweet as APITweet;
expect(tweet).toBeTruthy();
expect(tweet.url).toEqual(
'https://twitter.com/dangeredwolf/status/1554870933449482240'
'https://twitter.com/Twitter/status/1445094085593866246'
);
expect(tweet.id).toEqual('1554870933449482240');
expect(tweet.text).toEqual('4 photos');
expect(tweet.author.screen_name?.toLowerCase()).toEqual('dangeredwolf');
expect(tweet.id).toEqual('1445094085593866246');
expect(tweet.text).toEqual('@netflix');
expect(tweet.author.screen_name?.toLowerCase()).toEqual('twitter');
expect(tweet.author.name).toBeTruthy();
expect(tweet.author.avatar_url).toBeTruthy();
expect(tweet.author.banner_url).toBeTruthy();
expect(tweet.author.avatar_color).toBeTruthy();
expect(tweet.twitter_card).toEqual('summary_large_image');
expect(tweet.created_at).toEqual('Wed Aug 03 16:44:53 +0000 2022');
expect(tweet.created_timestamp).toEqual(1659545093);
expect(tweet.replying_to).toBeNull();
expect(tweet.created_at).toEqual('Mon Oct 04 18:30:53 +0000 2021');
expect(tweet.created_timestamp).toEqual(1633372253);
expect(tweet.replying_to?.toLowerCase()).toEqual('netflix');
expect(tweet.media?.photos).toBeTruthy();
const photos = tweet.media?.photos as APIPhoto[];
expect(photos[0].url).toEqual('https://pbs.twimg.com/media/FZQCeMmXwAAOJTt.png');
expect(photos[0].width).toEqual(800);
expect(photos[0].height).toEqual(418);
expect(photos[1].url).toEqual('https://pbs.twimg.com/media/FZQCl-lWIAMtoW9.png');
expect(photos[1].width).toEqual(800);
expect(photos[1].height).toEqual(418);
expect(photos[2].url).toEqual('https://pbs.twimg.com/media/FZQCsQPX0AIbY6H.png');
expect(photos[2].width).toEqual(800);
expect(photos[2].height).toEqual(418);
expect(photos[3].url).toEqual('https://pbs.twimg.com/media/FZQCxmLXEAMST4q.png');
expect(photos[3].width).toEqual(800);
expect(photos[3].height).toEqual(418);
expect(photos[0].url).toEqual('https://pbs.twimg.com/media/FA4BaFaXoBUV3di.jpg');
expect(photos[0].width).toEqual(950);
expect(photos[0].height).toEqual(620);
expect(photos[1].url).toEqual('https://pbs.twimg.com/media/FA4BaUyXEAcAHvK.jpg');
expect(photos[1].width).toEqual(1386);
expect(photos[1].height).toEqual(706);
expect(tweet.media?.mosaic).toBeTruthy();
const mosaic = tweet.media?.mosaic as APIMosaicPhoto;
expect(mosaic.formats?.jpeg).toEqual(
'https://mosaic.fxtwitter.com/jpeg/1554870933449482240/FZQCeMmXwAAOJTt/FZQCl-lWIAMtoW9/FZQCsQPX0AIbY6H/FZQCxmLXEAMST4q'
'https://mosaic.fxtwitter.com/jpeg/1445094085593866246/FA4BaFaXoBUV3di/FA4BaUyXEAcAHvK'
);
expect(mosaic.formats?.webp).toEqual(
'https://mosaic.fxtwitter.com/webp/1554870933449482240/FZQCeMmXwAAOJTt/FZQCl-lWIAMtoW9/FZQCsQPX0AIbY6H/FZQCxmLXEAMST4q'
'https://mosaic.fxtwitter.com/webp/1445094085593866246/FA4BaFaXoBUV3di/FA4BaUyXEAcAHvK'
);
});
test('API fetch multi-video Tweet', async () => {
const result = await cacheWrapper(
new Request('https://api.fxtwitter.com/dangeredwolf/status/1557914172763127808', {
method: 'GET',
headers: botHeaders
})
);
expect(result.status).toEqual(200);
const response = (await result.json()) as APIResponse;
expect(response).toBeTruthy();
expect(response.code).toEqual(200);
expect(response.message).toEqual('OK');
// test('API fetch multi-video Tweet', async () => {
// const result = await cacheWrapper(
// new Request('https://api.fxtwitter.com/dangeredwolf/status/1557914172763127808', {
// method: 'GET',
// headers: botHeaders
// })
// );
// expect(result.status).toEqual(200);
// const response = (await result.json()) as APIResponse;
// expect(response).toBeTruthy();
// expect(response.code).toEqual(200);
// expect(response.message).toEqual('OK');
const tweet = response.tweet as APITweet;
expect(tweet).toBeTruthy();
expect(tweet.url).toEqual(
'https://twitter.com/dangeredwolf/status/1557914172763127808'
);
expect(tweet.id).toEqual('1557914172763127808');
expect(tweet.text).toEqual('');
expect(tweet.author.screen_name?.toLowerCase()).toEqual('dangeredwolf');
expect(tweet.author.name).toBeTruthy();
expect(tweet.author.avatar_url).toBeTruthy();
expect(tweet.author.banner_url).toBeTruthy();
expect(tweet.author.avatar_color).toBeTruthy();
expect(tweet.twitter_card).toEqual('player');
expect(tweet.created_at).toEqual('Fri Aug 12 02:17:38 +0000 2022');
expect(tweet.created_timestamp).toEqual(1660270658);
expect(tweet.replying_to).toBeNull();
expect(tweet.media?.videos).toBeTruthy();
const videos = tweet.media?.videos as APIVideo[];
expect(videos[0].url).toEqual(
'https://video.twimg.com/ext_tw_video/1539029945124528130/pu/vid/1662x1080/ZQP4eoQhnGnKcLEb.mp4?tag=14'
);
expect(videos[0].thumbnail_url).toEqual(
'https://pbs.twimg.com/ext_tw_video_thumb/1539029945124528130/pu/img/6Z1MXMliums60j03.jpg'
);
expect(videos[0].width).toEqual(3548);
expect(videos[0].height).toEqual(2304);
expect(videos[0].duration).toEqual(37.75);
expect(videos[0].format).toEqual('video/mp4');
expect(videos[0].type).toEqual('video');
expect(videos[1].url).toEqual(
'https://video.twimg.com/ext_tw_video/1543316856697769984/pu/vid/1920x1080/3fo7b4EnWv2WO8Z1.mp4?tag=14'
);
expect(videos[1].thumbnail_url).toEqual(
'https://pbs.twimg.com/ext_tw_video_thumb/1543316856697769984/pu/img/eCl67JRWO8r4r8A4.jpg'
);
expect(videos[1].width).toEqual(1920);
expect(videos[1].height).toEqual(1080);
expect(videos[1].duration).toEqual(71.855);
expect(videos[1].format).toEqual('video/mp4');
expect(videos[1].type).toEqual('video');
expect(videos[2].url).toEqual(
'https://video.twimg.com/ext_tw_video/1543797953105625088/pu/vid/1920x1080/GHSLxzBrwiDLhLYD.mp4?tag=14'
);
expect(videos[2].thumbnail_url).toEqual(
'https://pbs.twimg.com/ext_tw_video_thumb/1543797953105625088/pu/img/2eX2QQkd7b2S1YDl.jpg'
);
expect(videos[2].width).toEqual(1920);
expect(videos[2].height).toEqual(1080);
expect(videos[2].duration).toEqual(22.018);
expect(videos[2].format).toEqual('video/mp4');
expect(videos[2].type).toEqual('video');
expect(videos[3].url).toEqual(
'https://video.twimg.com/ext_tw_video/1548602342488129536/pu/vid/720x1280/I_D3svYfjBl7_xGS.mp4?tag=14'
);
expect(videos[3].thumbnail_url).toEqual(
'https://pbs.twimg.com/ext_tw_video_thumb/1548602342488129536/pu/img/V_1u5Nv5BwKBynwv.jpg'
);
expect(videos[3].width).toEqual(720);
expect(videos[3].height).toEqual(1280);
expect(videos[3].duration).toEqual(25.133);
expect(videos[3].format).toEqual('video/mp4');
expect(videos[3].type).toEqual('video');
});
// const tweet = response.tweet as APITweet;
// expect(tweet).toBeTruthy();
// expect(tweet.url).toEqual(
// 'https://twitter.com/dangeredwolf/status/1557914172763127808'
// );
// expect(tweet.id).toEqual('1557914172763127808');
// expect(tweet.text).toEqual('');
// expect(tweet.author.screen_name?.toLowerCase()).toEqual('dangeredwolf');
// expect(tweet.author.name).toBeTruthy();
// expect(tweet.author.avatar_url).toBeTruthy();
// expect(tweet.author.banner_url).toBeTruthy();
// expect(tweet.author.avatar_color).toBeTruthy();
// expect(tweet.twitter_card).toEqual('player');
// expect(tweet.created_at).toEqual('Fri Aug 12 02:17:38 +0000 2022');
// expect(tweet.created_timestamp).toEqual(1660270658);
// expect(tweet.replying_to).toBeNull();
// expect(tweet.media?.videos).toBeTruthy();
// const videos = tweet.media?.videos as APIVideo[];
// expect(videos[0].url).toEqual(
// 'https://video.twimg.com/ext_tw_video/1539029945124528130/pu/vid/1662x1080/ZQP4eoQhnGnKcLEb.mp4?tag=14'
// );
// expect(videos[0].thumbnail_url).toEqual(
// 'https://pbs.twimg.com/ext_tw_video_thumb/1539029945124528130/pu/img/6Z1MXMliums60j03.jpg'
// );
// expect(videos[0].width).toEqual(3548);
// expect(videos[0].height).toEqual(2304);
// expect(videos[0].duration).toEqual(37.75);
// expect(videos[0].format).toEqual('video/mp4');
// expect(videos[0].type).toEqual('video');
// expect(videos[1].url).toEqual(
// 'https://video.twimg.com/ext_tw_video/1543316856697769984/pu/vid/1920x1080/3fo7b4EnWv2WO8Z1.mp4?tag=14'
// );
// expect(videos[1].thumbnail_url).toEqual(
// 'https://pbs.twimg.com/ext_tw_video_thumb/1543316856697769984/pu/img/eCl67JRWO8r4r8A4.jpg'
// );
// expect(videos[1].width).toEqual(1920);
// expect(videos[1].height).toEqual(1080);
// expect(videos[1].duration).toEqual(71.855);
// expect(videos[1].format).toEqual('video/mp4');
// expect(videos[1].type).toEqual('video');
// expect(videos[2].url).toEqual(
// 'https://video.twimg.com/ext_tw_video/1543797953105625088/pu/vid/1920x1080/GHSLxzBrwiDLhLYD.mp4?tag=14'
// );
// expect(videos[2].thumbnail_url).toEqual(
// 'https://pbs.twimg.com/ext_tw_video_thumb/1543797953105625088/pu/img/2eX2QQkd7b2S1YDl.jpg'
// );
// expect(videos[2].width).toEqual(1920);
// expect(videos[2].height).toEqual(1080);
// expect(videos[2].duration).toEqual(22.018);
// expect(videos[2].format).toEqual('video/mp4');
// expect(videos[2].type).toEqual('video');
// expect(videos[3].url).toEqual(
// 'https://video.twimg.com/ext_tw_video/1548602342488129536/pu/vid/720x1280/I_D3svYfjBl7_xGS.mp4?tag=14'
// );
// expect(videos[3].thumbnail_url).toEqual(
// 'https://pbs.twimg.com/ext_tw_video_thumb/1548602342488129536/pu/img/V_1u5Nv5BwKBynwv.jpg'
// );
// expect(videos[3].width).toEqual(720);
// expect(videos[3].height).toEqual(1280);
// expect(videos[3].duration).toEqual(25.133);
// expect(videos[3].format).toEqual('video/mp4');
// expect(videos[3].type).toEqual('video');
// });
test('API fetch poll Tweet', async () => {
const result = await cacheWrapper(
new Request('https://api.fxtwitter.com/status/1547441637739184128', {
new Request('https://api.fxtwitter.com/status/1055475950543167488', {
method: 'GET',
headers: botHeaders
})
@ -283,37 +277,37 @@ test('API fetch poll Tweet', async () => {
const tweet = response.tweet as APITweet;
expect(tweet).toBeTruthy();
expect(tweet.url).toEqual(
'https://twitter.com/dangeredwolf/status/1547441637739184128'
'https://twitter.com/Twitter/status/1055475950543167488'
);
expect(tweet.id).toEqual('1547441637739184128');
expect(tweet.text).toEqual('Poll with 4 values');
expect(tweet.author.screen_name?.toLowerCase()).toEqual('dangeredwolf');
expect(tweet.id).toEqual('1055475950543167488');
expect(tweet.text).toEqual('A poll:');
expect(tweet.author.screen_name?.toLowerCase()).toEqual('twitter');
expect(tweet.author.name).toBeTruthy();
expect(tweet.author.avatar_url).toBeTruthy();
expect(tweet.author.banner_url).toBeTruthy();
expect(tweet.author.avatar_color).toBeTruthy();
expect(tweet.twitter_card).toEqual('tweet');
expect(tweet.created_at).toEqual('Thu Jul 14 04:43:31 +0000 2022');
expect(tweet.created_timestamp).toEqual(1657773811);
expect(tweet.created_at).toEqual('Thu Oct 25 15:07:31 +0000 2018');
expect(tweet.created_timestamp).toEqual(1540480051);
expect(tweet.lang).toEqual('en');
expect(tweet.replying_to).toBeNull();
expect(tweet.poll).toBeTruthy();
const poll = tweet.poll as APIPoll;
expect(poll.ends_at).toEqual('2022-07-15T04:43:31Z');
expect(poll.ends_at).toEqual('2018-10-26T03:07:30Z');
expect(poll.time_left_en).toEqual('Final results');
expect(poll.total_votes).toEqual(194);
expect(poll.total_votes).toEqual(54703);
const choices = poll.choices as APIPollChoice[];
expect(choices[0].label).toEqual('1');
expect(choices[0].count).toEqual(14);
expect(choices[0].percentage).toEqual(7.2);
expect(choices[1].label).toEqual('2');
expect(choices[1].count).toEqual(36);
expect(choices[1].percentage).toEqual(18.6);
expect(choices[2].label).toEqual('3');
expect(choices[2].count).toEqual(80);
expect(choices[2].percentage).toEqual(41.2);
expect(choices[3].label).toEqual('4');
expect(choices[3].count).toEqual(64);
expect(choices[3].percentage).toEqual(33);
expect(choices[0].label).toEqual('Yesssss');
expect(choices[0].count).toEqual(14773);
expect(choices[0].percentage).toEqual(27);
expect(choices[1].label).toEqual('No');
expect(choices[1].count).toEqual(3618);
expect(choices[1].percentage).toEqual(6.6);
expect(choices[2].label).toEqual('Maybe?');
expect(choices[2].count).toEqual(4606);
expect(choices[2].percentage).toEqual(8.4);
expect(choices[3].label).toEqual('Just show me the results');
expect(choices[3].count).toEqual(31706);
expect(choices[3].percentage).toEqual(58);
});