Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

fix: test to check repo tab #9217

Merged
merged 1 commit into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion tests/profile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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");
Expand Down
55 changes: 55 additions & 0 deletions tests/setup/global-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 },
);
};