From c543b1208e24dca979b22015a5a524805a979d8d Mon Sep 17 00:00:00 2001 From: Louis Grasset Date: Sun, 19 Nov 2023 19:39:05 +0100 Subject: [PATCH 1/2] fix(quote): prevent quoting unavailable tweet --- src/helpers/tweet/keep-self-quotes.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/helpers/tweet/keep-self-quotes.ts b/src/helpers/tweet/keep-self-quotes.ts index b3b347d..3156528 100644 --- a/src/helpers/tweet/keep-self-quotes.ts +++ b/src/helpers/tweet/keep-self-quotes.ts @@ -3,8 +3,10 @@ import { Tweet } from "@the-convocation/twitter-scraper"; import { TWITTER_HANDLE } from "../../constants.js"; export const keepSelfQuotes = async (tweet: Tweet) => { - if (tweet.quotedStatus) { - return tweet.quotedStatus.username === TWITTER_HANDLE; + if (tweet.isQuoted) { + return tweet.quotedStatus + ? tweet.quotedStatus.username === TWITTER_HANDLE // If the quoted tweet is from the same user, keep it. + : false; // If the quoted tweet is not available, skip the tweet. } // True by default so chained conditions works From 7c047561410d2f3fbec1a199b00d1a51cbadfc3a Mon Sep 17 00:00:00 2001 From: Louis Grasset Date: Sun, 19 Nov 2023 20:03:26 +0100 Subject: [PATCH 2/2] test(quote): prevent quoting unavailable tweet --- .../tweet/__tests__/keep-self-quotes.spec.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/helpers/tweet/__tests__/keep-self-quotes.spec.ts b/src/helpers/tweet/__tests__/keep-self-quotes.spec.ts index ae03cde..8bcf7fa 100644 --- a/src/helpers/tweet/__tests__/keep-self-quotes.spec.ts +++ b/src/helpers/tweet/__tests__/keep-self-quotes.spec.ts @@ -12,6 +12,7 @@ describe("keepSelfQuotes", () => { describe("when the tweet is a quote", () => { it("should return true when is from the same user", async () => { const result = await keepSelfQuotes({ + isQuoted: true, quotedStatus: { username: "username" }, } as unknown as Tweet); @@ -20,6 +21,7 @@ describe("keepSelfQuotes", () => { it("should return false when is from a different user", async () => { const result = await keepSelfQuotes({ + isQuoted: true, quotedStatus: { username: "potatoinc" }, } as unknown as Tweet); @@ -34,4 +36,15 @@ describe("keepSelfQuotes", () => { expect(result).toBe(true); }); }); + + describe("when the tweet is a quote from a unavailable tweet", () => { + it("should return true when is from the same user", async () => { + const result = await keepSelfQuotes({ + isQuoted: true, + quotedStatus: undefined, + } as unknown as Tweet); + + expect(result).toBe(false); + }); + }); });