diff --git a/tests/profile.spec.js b/tests/profile.spec.js index d9f9668afad..57b3206bcbb 100644 --- a/tests/profile.spec.js +++ b/tests/profile.spec.js @@ -30,7 +30,7 @@ test("Tabs change correctly", async ({ page }) => { await expect(page.locator("h3").first()).toHaveText(/Top Teacher Award/); }); -test("Tabs have deep linking", async ({ page }) => { +test("Tabs have deep linking test milestone", async ({ page }) => { const username = "_test-profile-user-6"; await page.goto(`/${username}?tab=milestones`); await expect(page.getByRole("link", { name: /Milestones/ })).toHaveAttribute( @@ -40,6 +40,17 @@ test("Tabs have deep linking", async ({ page }) => { await expect(page.locator("h3").first()).toHaveText(/Top Teacher Award/); }); +test("Tabs have deep linking test repos", async ({ page }) => { + const username = "_test-profile-user-6"; + await page.goto(`/${username}?tab=repos`); + await expect( + page.locator("main").getByRole("link", { name: /Repos/ }), + ).toHaveAttribute("class", /border-tertiary-medium/); + await expect( + page.getByRole("link", { name: "EddieHubCommunity/BioDrop" }), + ).toHaveText(/EddieHubCommunity\/BioDrop/); +}); + test("Profile views increase", async ({ page }) => { await connectMongo(); await page.goto("/_test-profile-user-3"); diff --git a/tests/setup/global-setup.js b/tests/setup/global-setup.js index 27d756436a8..b80c5c7a5fb 100644 --- a/tests/setup/global-setup.js +++ b/tests/setup/global-setup.js @@ -5,6 +5,9 @@ const { USERS } = require("./test-users.js"); import icons from "@config/icons.json"; import logger from "@config/logger"; +import getGitHubRepo from "@services/github/getRepo.js"; +import { Profile } from "@models/index.js"; +import connectMongo from "@config/mongo.js"; const links = Object.keys(icons).map((icon, index) => { return { @@ -73,4 +76,56 @@ module.exports = async () => { logger.error(e); throw new Error(`Test data not loaded into database`); } + + // for user "_test-profile-user-6" we need to add a repo + // this is because the repo is not in the json data + await connectMongo(); + let githubData = {}; + const repoUrl = "https://github.com/EddieHubCommunity/BioDrop"; + try { + githubData = await getGitHubRepo(repoUrl); + } catch (e) { + const error = `failed to get data for repo: ${repoUrl}`; + logger.error(e, error); + return { error }; + } + + if (githubData.error) { + return logger.error(e, error); + } + + await Profile.findOneAndUpdate( + { + username: "_test-profile-user-6", + }, + { + $set: { + source: "database", + }, + $push: { + repos: { + url: githubData.url, + fullname: githubData.name, + name: githubData.name, + owner: githubData.owner.login, + description: githubData.description, + topics: githubData.topics, + stats: { + issues: githubData.open_issues_count, + stars: githubData.stargazers_count, + forks: githubData.forks_count, + watchers: githubData.watchers_count, + subscribers: githubData.subscribers_count, + }, + dates: { + createdAt: githubData.created_at, + updatedAt: githubData.updated_at, + pushedAt: githubData.pushed_at, + }, + updatedAt: new Date(), + }, + }, + }, + { new: true }, + ); };