|
| 1 | +/** |
| 2 | + * @file Contains end-to-end tests for the Vercel preview instance. |
| 3 | + */ |
| 4 | +import dotenv from "dotenv"; |
| 5 | +dotenv.config(); |
| 6 | + |
| 7 | +import { describe } from "@jest/globals"; |
| 8 | +import axios from "axios"; |
| 9 | +import { renderRepoCard } from "../../src/cards/repo-card.js"; |
| 10 | +import { renderStatsCard } from "../../src/cards/stats-card.js"; |
| 11 | +import { renderTopLanguages } from "../../src/cards/top-languages-card.js"; |
| 12 | +import { renderWakatimeCard } from "../../src/cards/wakatime-card.js"; |
| 13 | + |
| 14 | +// Script variables |
| 15 | +const REPO = "dummy-cra"; |
| 16 | +const USER = "grsdummy"; |
| 17 | +const STATS_DATA = { |
| 18 | + name: "grsdummy", |
| 19 | + totalPRs: 1, |
| 20 | + totalCommits: 2, |
| 21 | + totalIssues: 1, |
| 22 | + totalStars: 1, |
| 23 | + contributedTo: 1, |
| 24 | + rank: { |
| 25 | + level: "A+", |
| 26 | + score: 51.01622937949586, |
| 27 | + }, |
| 28 | +}; |
| 29 | +const LANGS_DATA = { |
| 30 | + TypeScript: { |
| 31 | + color: "#3178c6", |
| 32 | + name: "TypeScript", |
| 33 | + size: 2049, |
| 34 | + }, |
| 35 | + HTML: { |
| 36 | + color: "#e34c26", |
| 37 | + name: "HTML", |
| 38 | + size: 1721, |
| 39 | + }, |
| 40 | + CSS: { |
| 41 | + color: "#563d7c", |
| 42 | + name: "CSS", |
| 43 | + size: 930, |
| 44 | + }, |
| 45 | + Python: { |
| 46 | + color: "#3572A5", |
| 47 | + name: "Python", |
| 48 | + size: 671, |
| 49 | + }, |
| 50 | +}; |
| 51 | +const WAKATIME_DATA = { |
| 52 | + human_readable_range: "last week", |
| 53 | + is_already_updating: false, |
| 54 | + is_coding_activity_visible: false, |
| 55 | + is_including_today: false, |
| 56 | + is_other_usage_visible: false, |
| 57 | + is_stuck: false, |
| 58 | + is_up_to_date: false, |
| 59 | + is_up_to_date_pending_future: false, |
| 60 | + percent_calculated: 0, |
| 61 | + range: "last_7_days", |
| 62 | + status: "pending_update", |
| 63 | + timeout: 15, |
| 64 | + username: "grsdummy", |
| 65 | + writes_only: false, |
| 66 | +}; |
| 67 | +const REPOSITORY_DATA = { |
| 68 | + name: "dummy-cra", |
| 69 | + nameWithOwner: "grsdummy/dummy-cra", |
| 70 | + isPrivate: false, |
| 71 | + isArchived: false, |
| 72 | + isTemplate: false, |
| 73 | + stargazers: { |
| 74 | + totalCount: 1, |
| 75 | + }, |
| 76 | + description: "Dummy create react app.", |
| 77 | + primaryLanguage: { |
| 78 | + color: "#3178c6", |
| 79 | + id: "MDg6TGFuZ3VhZ2UyODc=", |
| 80 | + name: "TypeScript", |
| 81 | + }, |
| 82 | + forkCount: 0, |
| 83 | + starCount: 1, |
| 84 | +}; |
| 85 | + |
| 86 | +describe("Fetch Cards", () => { |
| 87 | + let VERCEL_PREVIEW_URL; |
| 88 | + |
| 89 | + beforeAll(() => { |
| 90 | + process.env.NODE_ENV = "development"; |
| 91 | + VERCEL_PREVIEW_URL = process.env.VERCEL_PREVIEW_URL; |
| 92 | + }); |
| 93 | + |
| 94 | + test("retrieve stats card", async () => { |
| 95 | + expect(VERCEL_PREVIEW_URL).toBeDefined(); |
| 96 | + |
| 97 | + // Check if the Vercel preview instance stats card function is up and running. |
| 98 | + await expect( |
| 99 | + axios.get(`${VERCEL_PREVIEW_URL}/api?username=${USER}`), |
| 100 | + ).resolves.not.toThrow(); |
| 101 | + |
| 102 | + // Get local stats card. |
| 103 | + const localStatsCardSVG = renderStatsCard(STATS_DATA); |
| 104 | + |
| 105 | + // Get the Vercel preview stats card response. |
| 106 | + const serverStatsSvg = await axios.get( |
| 107 | + `${VERCEL_PREVIEW_URL}/api?username=${USER}`, |
| 108 | + ); |
| 109 | + |
| 110 | + // Check if stats card from deployment matches the stats card from local. |
| 111 | + expect(serverStatsSvg.data).toEqual(localStatsCardSVG); |
| 112 | + }); |
| 113 | + |
| 114 | + test("retrieve language card", async () => { |
| 115 | + expect(VERCEL_PREVIEW_URL).toBeDefined(); |
| 116 | + |
| 117 | + // Check if the Vercel preview instance language card function is up and running. |
| 118 | + await expect( |
| 119 | + axios.get(`${VERCEL_PREVIEW_URL}/api/top-langs/?username=${USER}`), |
| 120 | + ).resolves.not.toThrow(); |
| 121 | + |
| 122 | + // Get local language card. |
| 123 | + const localLanguageCardSVG = renderTopLanguages(LANGS_DATA); |
| 124 | + |
| 125 | + // Get the Vercel preview language card response. |
| 126 | + const severLanguageSVG = await axios.get( |
| 127 | + `${VERCEL_PREVIEW_URL}/api/top-langs/?username=${USER}`, |
| 128 | + ); |
| 129 | + |
| 130 | + // Check if language card from deployment matches the local language card. |
| 131 | + expect(severLanguageSVG.data).toEqual(localLanguageCardSVG); |
| 132 | + }); |
| 133 | + |
| 134 | + test("retrieve WakaTime card", async () => { |
| 135 | + expect(VERCEL_PREVIEW_URL).toBeDefined(); |
| 136 | + |
| 137 | + // Check if the Vercel preview instance WakaTime function is up and running. |
| 138 | + await expect( |
| 139 | + axios.get(`${VERCEL_PREVIEW_URL}/api/wakatime?username=${USER}`), |
| 140 | + ).resolves.not.toThrow(); |
| 141 | + |
| 142 | + // Get local WakaTime card. |
| 143 | + const localWakaCardSVG = renderWakatimeCard(WAKATIME_DATA); |
| 144 | + |
| 145 | + // Get the Vercel preview WakaTime card response. |
| 146 | + const serverWakaTimeSvg = await axios.get( |
| 147 | + `${VERCEL_PREVIEW_URL}/api/wakatime?username=${USER}`, |
| 148 | + ); |
| 149 | + |
| 150 | + // Check if WakaTime card from deployment matches the local WakaTime card. |
| 151 | + expect(serverWakaTimeSvg.data).toEqual(localWakaCardSVG); |
| 152 | + }); |
| 153 | + |
| 154 | + test("retrieve repo card", async () => { |
| 155 | + expect(VERCEL_PREVIEW_URL).toBeDefined(); |
| 156 | + |
| 157 | + // Check if the Vercel preview instance Repo function is up and running. |
| 158 | + await expect( |
| 159 | + axios.get(`${VERCEL_PREVIEW_URL}/api/pin/?username=${USER}&repo=${REPO}`), |
| 160 | + ).resolves.not.toThrow(); |
| 161 | + |
| 162 | + // Get local repo card. |
| 163 | + const localRepoCardSVG = renderRepoCard(REPOSITORY_DATA); |
| 164 | + |
| 165 | + // Get the Vercel preview repo card response. |
| 166 | + const serverRepoSvg = await axios.get( |
| 167 | + `${VERCEL_PREVIEW_URL}/api/pin/?username=${USER}&repo=${REPO}`, |
| 168 | + ); |
| 169 | + |
| 170 | + // Check if Repo card from deployment matches the local Repo card. |
| 171 | + expect(serverRepoSvg.data).toEqual(localRepoCardSVG); |
| 172 | + }); |
| 173 | +}); |
0 commit comments