From 6fd06c8c5175c1c05df3b63702e518cac8495650 Mon Sep 17 00:00:00 2001 From: Alessio Date: Sat, 18 Nov 2023 16:35:15 -0800 Subject: [PATCH] Add integration test for fetch_inbox --- cmd/tests.sh | 16 ++++++++++++---- pkg/scraper/api_types_dms.go | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/cmd/tests.sh b/cmd/tests.sh index 0daa1c6..3c0d252 100755 --- a/cmd/tests.sh +++ b/cmd/tests.sh @@ -148,10 +148,10 @@ test $(find images -mindepth 2 | wc -l) = "$((initial_images_count + 1))" # Fetch and attempt to download a DMCAed tweet -tw fetch_user TyCardon -tw fetch_tweet_only https://twitter.com/TyCardon/status/1480640777281839106 -tw download_tweet_content 1480640777281839106 -test $(sqlite3 twitter.db "select is_blocked_by_dmca, is_downloaded from videos where tweet_id = 1480640777281839106") = "1|0" +# tw fetch_user TyCardon # TODO: This guy went private +# tw fetch_tweet_only https://twitter.com/TyCardon/status/1480640777281839106 +# tw download_tweet_content 1480640777281839106 +# test $(sqlite3 twitter.db "select is_blocked_by_dmca, is_downloaded from videos where tweet_id = 1480640777281839106") = "1|0" # Fetch a tweet with a poll tw fetch_tweet 1465534109573390348 @@ -370,6 +370,14 @@ tw unlike_tweet https://twitter.com/elonmusk/status/1589023388676554753 # test $(sqlite3 twitter.db "select count(*) from likes where tweet_id = 1589023388676554753 and user_id = (select id from users where handle like 'offline_twatter')") = "0" +# Test fetch inbox +test $(sqlite3 twitter.db "select count(*) from chat_rooms") = "0" +test $(sqlite3 twitter.db "select count(*) from chat_messages") = "0" +tw fetch_inbox +test $(sqlite3 twitter.db "select count(*) from chat_rooms") -ge "1" +test $(sqlite3 twitter.db "select count(*) from chat_messages where chat_room_id = '1458284524761075714-1488963321701171204'") -ge "5" + + # TODO: Maybe this file should be broken up into multiple test scripts echo -e "\033[32mAll tests passed. Finished successfully.\033[0m" diff --git a/pkg/scraper/api_types_dms.go b/pkg/scraper/api_types_dms.go index b9ff3ee..2d13b37 100644 --- a/pkg/scraper/api_types_dms.go +++ b/pkg/scraper/api_types_dms.go @@ -1,6 +1,7 @@ package scraper import ( + "fmt" "net/url" "strings" ) @@ -59,7 +60,7 @@ type APIInbox struct { } `json:"trusted"` } `json:"inbox_timelines"` Entries []struct { - Message APIDMMessage `json:"message"` + Message APIDMMessage `json:"message"` } `json:"entries"` Users map[string]APIUser `json:"users"` Conversations map[string]APIDMConversation `json:"conversations"`