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

Commit

Permalink
feat: admin list premium users (#9489)
Browse files Browse the repository at this point in the history
* feat: admin list premium users

* fix: profile tab tests
  • Loading branch information
eddiejaoude authored Oct 14, 2023
1 parent 32943ab commit 000fbbc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
1 change: 1 addition & 0 deletions pages/admin/profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default function Users({ profiles }) {
Recently updated
</Button>
<Button href="/admin/profiles?filter=by rank">By Rank</Button>
<Button href="/admin/profiles?filter=premium">Premium</Button>
</div>

<ul role="list" className="divide-y divide-primary-low">
Expand Down
23 changes: 23 additions & 0 deletions pages/api/admin/profiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,29 @@ export async function getProfiles(filter = "recently updated") {
}
}

if (filter === "premium") {
try {
profiles = await Profile.aggregate([
{
$lookup: {
from: "users",
localField: "user",
foreignField: "_id",
as: "user",
},
},
{
$match: {
"user.type": "premium",
},
},
]).limit(20);
} catch (e) {
logger.error(e, "failed loading profiles");
return profiles;
}
}

if (filter === "by rank") {
try {
profiles = await Profile.aggregate([
Expand Down
13 changes: 6 additions & 7 deletions tests/profile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,29 @@ test("Name appears on the page", async ({ page }) => {
test("Tabs change correctly", async ({ page }) => {
const username = "_test-profile-user-6";
await page.goto(`/${username}`);
await expect(page.getByRole("link", { name: /My Links/ })).toHaveAttribute(
await expect(page.getByRole("button", { name: /My Links/ })).toHaveAttribute(
"class",
/border-tertiary-medium/,
);
await expect(page.locator("main")).not.toHaveText(/Top Teacher Award/);
await page.getByRole("link", { name: /Milestones/ }).click();
await page.getByRole("button", { name: /Milestones/ }).click();
await expect(page.locator("h3").first()).toHaveText(/Top Teacher Award/);
});

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(
"class",
/border-tertiary-medium/,
);
await expect(
page.getByRole("button", { name: /Milestones/ }),
).toHaveAttribute("class", /border-tertiary-medium/);
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/ }),
page.locator("main").getByRole("button", { name: /Repos/ }),
).toHaveAttribute("class", /border-tertiary-medium/);
await expect(
page.getByRole("link", { name: "EddieHubCommunity/BioDrop" }),
Expand Down

0 comments on commit 000fbbc

Please sign in to comment.