From 008b14f1b10d584c8a87ce6b913e15f593b92c55 Mon Sep 17 00:00:00 2001 From: ItsRauf <31735267+ItsRauf@users.noreply.github.com> Date: Mon, 20 Apr 2026 12:58:17 -0700 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(workspace):=20rem?= =?UTF-8?q?ove=20tests=20and=20update=20ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/changesets.yml | 12 +-- .github/workflows/validate.yml | 14 +-- packages/platforms/src/CBC.test.ts | 32 ------- packages/platforms/src/Instagram.test.ts | 40 -------- packages/platforms/src/Reddit.test.ts | 31 ------ packages/platforms/src/Threads.test.ts | 34 ------- packages/platforms/src/TikTok.test.ts | 37 -------- packages/platforms/src/TruthSocial.test.ts | 90 ------------------ packages/platforms/src/Twitter.test.ts | 39 -------- packages/platforms/src/utils.test.ts | 104 --------------------- 10 files changed, 5 insertions(+), 428 deletions(-) delete mode 100644 packages/platforms/src/CBC.test.ts delete mode 100644 packages/platforms/src/Instagram.test.ts delete mode 100644 packages/platforms/src/Reddit.test.ts delete mode 100644 packages/platforms/src/Threads.test.ts delete mode 100644 packages/platforms/src/TikTok.test.ts delete mode 100644 packages/platforms/src/TruthSocial.test.ts delete mode 100644 packages/platforms/src/Twitter.test.ts delete mode 100644 packages/platforms/src/utils.test.ts diff --git a/.github/workflows/changesets.yml b/.github/workflows/changesets.yml index ad4e553..d3e1735 100644 --- a/.github/workflows/changesets.yml +++ b/.github/workflows/changesets.yml @@ -21,17 +21,7 @@ jobs: uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Setup pnpm - uses: pnpm/action-setup@v2 - with: - version: ${{ env.PNPM_VERSION }} - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ env.NODE_VERSION }} - cache: 'pnpm' - - name: Install Dependencies - run: pnpm install --frozen-lockfile + - uses: ./.github/actions/setup - name: Get Release Version id: versioning run: | diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index e9d9df4..109169a 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -12,18 +12,12 @@ jobs: validate: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 - uses: ./.github/actions/setup - name: Lint and format check run: pnpm biome ci - name: Build all packages run: pnpm build - - test: - needs: validate - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ./.github/actions/setup - - name: Run tests - run: pnpm test diff --git a/packages/platforms/src/CBC.test.ts b/packages/platforms/src/CBC.test.ts deleted file mode 100644 index 6ebaa19..0000000 --- a/packages/platforms/src/CBC.test.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { CBC } from "./CBC.ts"; - -describe("CBC", () => { - const cbc = new CBC(); - - const valid_urls = [ - "https://www.cbc.ca/news/canada/1.7654321", - "https://cbc.ca/news/1.7654321", - "https://www.cbc.ca/news/politics/some-article-1.7654321/" - ]; - - const invalid_urls = [ - "https://notcbc.ca/news/1.123", - "https://example.com" - ]; - - it.each(valid_urls)("matches %s", (url) => { - expect(cbc.matchesUrl(url)).toBe(true); - }); - - it.each(invalid_urls)("rejects %s", (url) => { - expect(cbc.matchesUrl(url)).toBe(false); - }); - - it("extracts cbc id", () => { - const match = cbc.regex.exec( - "https://www.cbc.ca/news/canada/1.7654321" - ); - expect(match?.groups?.cbc_id).toBe("1.7654321"); - }); -}); diff --git a/packages/platforms/src/Instagram.test.ts b/packages/platforms/src/Instagram.test.ts deleted file mode 100644 index 8bb4116..0000000 --- a/packages/platforms/src/Instagram.test.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { Instagram } from "./Instagram.ts"; - -describe("Instagram", () => { - const instagram = new Instagram(); - - const valid_urls = [ - "https://www.instagram.com/p/ABC123/", - "https://instagram.com/p/ABC123", - "https://www.instagram.com/user/p/ABC123/", - "https://www.instagram.com/reel/ABC123/", - "https://www.instagram.com/reels/ABC123/", - "https://www.instagram.com/user/reel/ABC123", - "https://www.instagram.com/stories/ABC123/", - "https://www.instagram.com/share/ABC123/", - "https://www.instagram.com/user/share/ABC123" - ]; - - const invalid_urls = [ - "https://instagram.com/user", - "https://instagram.com/user/followers", - "https://notinstagram.com/p/ABC123", - "https://example.com" - ]; - - it.each(valid_urls)("matches %s", (url) => { - expect(instagram.matchesUrl(url)).toBe(true); - }); - - it.each(invalid_urls)("rejects %s", (url) => { - expect(instagram.matchesUrl(url)).toBe(false); - }); - - it("extracts shortcode", () => { - const match = instagram.regex.exec( - "https://www.instagram.com/p/CxYz123_Ab/" - ); - expect(match?.groups?.ig_shortcode).toBe("CxYz123_Ab"); - }); -}); diff --git a/packages/platforms/src/Reddit.test.ts b/packages/platforms/src/Reddit.test.ts deleted file mode 100644 index 354c1f9..0000000 --- a/packages/platforms/src/Reddit.test.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { Reddit } from "./Reddit.ts"; - -describe("Reddit", () => { - const reddit = new Reddit(); - - const valid_urls = [ - "https://www.reddit.com/r/javascript/comments/abc123/some_title", - "https://old.reddit.com/r/javascript/comments/abc123/", - "https://reddit.com/r/javascript/comments/abc123", - "https://www.reddit.com/r/pics/s/AbCdEfGhIj", - "https://reddit.com/r/pics/s/AbCdEfGhIj/", - "https://redd.it/abc123", - "https://redd.it/abc123/" - ]; - - const invalid_urls = [ - "https://www.reddit.com/r/javascript", - "https://www.reddit.com/user/someone", - "https://notreddit.com/r/test/comments/abc", - "https://example.com" - ]; - - it.each(valid_urls)("matches %s", (url) => { - expect(reddit.matchesUrl(url)).toBe(true); - }); - - it.each(invalid_urls)("rejects %s", (url) => { - expect(reddit.matchesUrl(url)).toBe(false); - }); -}); diff --git a/packages/platforms/src/Threads.test.ts b/packages/platforms/src/Threads.test.ts deleted file mode 100644 index 74ab2e5..0000000 --- a/packages/platforms/src/Threads.test.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { Threads } from "./Threads.ts"; - -describe("Threads", () => { - const threads = new Threads(); - - const valid_urls = [ - "https://www.threads.net/@user/post/CxYz123_Ab", - "https://threads.net/@user/post/CxYz123_Ab/", - "https://www.threads.net/@some.user/post/ABC123" - ]; - - const invalid_urls = [ - "https://threads.net/@user", - "https://threads.net/@user/replies", - "https://notthreads.net/@user/post/ABC", - "https://example.com" - ]; - - it.each(valid_urls)("matches %s", (url) => { - expect(threads.matchesUrl(url)).toBe(true); - }); - - it.each(invalid_urls)("rejects %s", (url) => { - expect(threads.matchesUrl(url)).toBe(false); - }); - - it("extracts shortcode and username", () => { - const match = threads.regex.exec( - "https://www.threads.net/@zuck/post/CxYz123_Ab" - ); - expect(match?.groups?.thread_shortcode).toBe("CxYz123_Ab"); - }); -}); diff --git a/packages/platforms/src/TikTok.test.ts b/packages/platforms/src/TikTok.test.ts deleted file mode 100644 index 0b050f1..0000000 --- a/packages/platforms/src/TikTok.test.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { TikTok } from "./TikTok.ts"; - -describe("TikTok", () => { - const tiktok = new TikTok(); - - const valid_urls = [ - "https://www.tiktok.com/@user/video/123456789", - "https://tiktok.com/@user/video/123456789", - "https://m.tiktok.com/@user/video/123456789", - "https://vm.tiktok.com/ZMhAbCdEf/", - "https://www.tiktok.com/t/ZTAbCdEf/" - ]; - - const invalid_urls = [ - "https://nottiktok.com/@user/video/123", - "https://example.com" - ]; - - it.each(valid_urls)("matches %s", (url) => { - expect(tiktok.matchesUrl(url)).toBe(true); - }); - - it.each(invalid_urls)("rejects %s", (url) => { - expect(tiktok.matchesUrl(url)).toBe(false); - }); - - it("extracts user and video id from detail pattern", () => { - const detail_regex = - /https:\/\/(?:m|www|vm)?\.?tiktok\.com\/(?@[\w.-]+)\/video\/(?\d+)/; - const match = detail_regex.exec( - "https://www.tiktok.com/@cooluser/video/7234567890123456789" - ); - expect(match?.groups?.tiktok_user).toBe("@cooluser"); - expect(match?.groups?.tiktok_id).toBe("7234567890123456789"); - }); -}); diff --git a/packages/platforms/src/TruthSocial.test.ts b/packages/platforms/src/TruthSocial.test.ts deleted file mode 100644 index 57984b2..0000000 --- a/packages/platforms/src/TruthSocial.test.ts +++ /dev/null @@ -1,90 +0,0 @@ -import { beforeAll, describe, expect, it } from "vitest"; -import { TruthSocial } from "./TruthSocial.ts"; - -beforeAll(() => { - process.env.DISCORD_BOT_TOKEN = "test-token"; - process.env.EMBEDLY_API_DOMAIN = "localhost"; -}); - -describe("TruthSocial", () => { - const ts = new TruthSocial(); - - const valid_urls = [ - "https://truthsocial.com/@realDonaldTrump/posts/116268334535345382", - "https://truthsocial.com/@user/posts/123456/", - "https://www.truthsocial.com/@user/posts/123456" - ]; - - const invalid_urls = [ - "https://truthsocial.com/@user", - "https://truthsocial.com/@user/following", - "https://nottruthsocial.com/@user/posts/123", - "https://example.com" - ]; - - it.each(valid_urls)("matches %s", (url) => { - expect(ts.matchesUrl(url)).toBe(true); - }); - - it.each(invalid_urls)("rejects %s", (url) => { - expect(ts.matchesUrl(url)).toBe(false); - }); - - it("extracts status id", async () => { - const id = await ts.parsePostId( - "https://truthsocial.com/@realDonaldTrump/posts/116268334535345382" - ); - expect(id).toBe("116268334535345382"); - }); - - it("transforms raw data correctly", () => { - const raw = { - id: "116268334535345382", - created_at: "2026-03-21T17:26:31.318Z", - url: "https://truthsocial.com/@realDonaldTrump/116268334535345382", - content: "

Hello world

", - account: { - display_name: "Donald J. Trump", - username: "realDonaldTrump", - url: "https://truthsocial.com/@realDonaldTrump", - avatar: "https://example.com/avatar.jpeg" - }, - replies_count: 5221, - reblogs_count: 4472, - favourites_count: 15994, - media_attachments: [] - }; - - const data = ts.transformRawData(raw); - expect(data.platform).toBe("Truth Social"); - expect(data.name).toBe("Donald J. Trump"); - expect(data.username).toBe("realDonaldTrump"); - expect(data.description).toBe("Hello world"); - expect(data.stats?.comments).toBe(5221); - expect(data.stats?.reposts).toBe(4472); - expect(data.stats?.likes).toBe(15994); - expect(data.timestamp).toBe( - Math.floor(new Date("2026-03-21T17:26:31.318Z").getTime() / 1000) - ); - }); - - it("strips html from content", () => { - const raw = { - created_at: "2026-03-21T00:00:00Z", - url: "https://truthsocial.com/@user/123", - content: "

First paragraph

Second & third

", - account: { - display_name: "User", - username: "user", - url: "https://truthsocial.com/@user", - avatar: "https://example.com/avatar.png" - }, - replies_count: 0, - reblogs_count: 0, - favourites_count: 0 - }; - - const data = ts.transformRawData(raw); - expect(data.description).toBe("First paragraph\n\nSecond & third"); - }); -}); diff --git a/packages/platforms/src/Twitter.test.ts b/packages/platforms/src/Twitter.test.ts deleted file mode 100644 index 0784688..0000000 --- a/packages/platforms/src/Twitter.test.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { Twitter } from "./Twitter.ts"; - -describe("Twitter", () => { - const twitter = new Twitter(); - - const valid_urls = [ - "https://twitter.com/user/status/123456789", - "https://x.com/user/status/123456789", - "https://www.twitter.com/user/status/123456789", - "https://www.x.com/user/status/123456789", - "https://x.com/user/statuses/123456789", - "https://x.com/user/status/123456789/", - "https://mobile.x.com/user/status/123456789", - "https://mobile.twitter.com/user/status/123456789" - ]; - - const invalid_urls = [ - "https://nottwitter.com/user/status/123", - "https://x.com/user/likes", - "https://twitter.com/user", - "https://example.com" - ]; - - it.each(valid_urls)("matches %s", (url) => { - expect(twitter.matchesUrl(url)).toBe(true); - }); - - it.each(invalid_urls)("rejects %s", (url) => { - expect(twitter.matchesUrl(url)).toBe(false); - }); - - it("extracts tweet id", () => { - const match = twitter.regex.exec( - "https://x.com/elonmusk/status/1234567890" - ); - expect(match?.groups?.tweet_id).toBe("1234567890"); - }); -}); diff --git a/packages/platforms/src/utils.test.ts b/packages/platforms/src/utils.test.ts deleted file mode 100644 index 4cfa944..0000000 --- a/packages/platforms/src/utils.test.ts +++ /dev/null @@ -1,104 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { getPlatformFromURL } from "./main.ts"; -import { EmbedlyPlatformType } from "./types.ts"; -import { hasLink, isEscaped, isSpoiler } from "./utils.ts"; - -describe("getPlatformFromURL", () => { - it("detects twitter", () => { - const result = getPlatformFromURL("https://x.com/user/status/123"); - expect(result?.type).toBe(EmbedlyPlatformType.Twitter); - }); - - it("detects instagram", () => { - const result = getPlatformFromURL( - "https://www.instagram.com/p/ABC123/" - ); - expect(result?.type).toBe(EmbedlyPlatformType.Instagram); - }); - - it("detects tiktok", () => { - const result = getPlatformFromURL( - "https://www.tiktok.com/@user/video/123" - ); - expect(result?.type).toBe(EmbedlyPlatformType.TikTok); - }); - - it("detects reddit", () => { - const result = getPlatformFromURL( - "https://www.reddit.com/r/test/comments/abc123/title" - ); - expect(result?.type).toBe(EmbedlyPlatformType.Reddit); - }); - - it("detects threads", () => { - const result = getPlatformFromURL( - "https://www.threads.net/@user/post/ABC123" - ); - expect(result?.type).toBe(EmbedlyPlatformType.Threads); - }); - - it("detects cbc", () => { - const result = getPlatformFromURL( - "https://www.cbc.ca/news/1.7654321" - ); - expect(result?.type).toBe(EmbedlyPlatformType.CBC); - }); - - it("returns null for unknown urls", () => { - expect(getPlatformFromURL("https://example.com")).toBeNull(); - expect(getPlatformFromURL("https://google.com")).toBeNull(); - }); -}); - -describe("hasLink", () => { - it("detects urls in text", () => { - expect(hasLink("check out https://example.com")).toBe(true); - expect(hasLink("visit http://test.org/page")).toBe(true); - expect(hasLink("go to example.com/path")).toBe(true); - }); - - it("rejects plain text", () => { - expect(hasLink("no links here")).toBe(false); - expect(hasLink("just some words")).toBe(false); - }); -}); - -describe("isSpoiler", () => { - it("detects url inside spoiler tags", () => { - expect( - isSpoiler( - "https://x.com/user/status/123", - "look ||https://x.com/user/status/123||" - ) - ).toBe(true); - }); - - it("returns false when url is not spoilered", () => { - expect( - isSpoiler( - "https://x.com/user/status/123", - "https://x.com/user/status/123" - ) - ).toBe(false); - }); -}); - -describe("isEscaped", () => { - it("detects escaped urls", () => { - expect( - isEscaped( - "https://x.com/user/status/123", - "" - ) - ).toBe(true); - }); - - it("returns false for non-escaped urls", () => { - expect( - isEscaped( - "https://x.com/user/status/123", - "https://x.com/user/status/123" - ) - ).toBe(false); - }); -});