Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
18970b1
update package.json to latest release version
chris-nowicki Aug 29, 2024
8bafcb7
Merge branch 'develop' into alex/implement-admin-league-operation
alexappleget Aug 30, 2024
ba09e35
Fix: Added in functionality to create a new league.
alexappleget Sep 3, 2024
20072fe
Fix: Added in functionality for deleting a league.
alexappleget Sep 3, 2024
3357249
Fix: Changed function name for creating a new league in page.tsx
alexappleget Sep 3, 2024
2b443a1
Fix: Added the getCurrentLeague function to the page file for grabbin…
alexappleget Sep 3, 2024
08095de
Fix: Handled param for handleGetLeague().
alexappleget Sep 3, 2024
033c33a
Fix: added <tbody> parent element to data table because of hydration …
alexappleget Sep 3, 2024
697a7af
Fix: Adding in data table for league data.
alexappleget Sep 3, 2024
01cd943
Merge branch 'develop' into alex/implement-admin-league-operation
alexappleget Oct 10, 2024
1fe5867
Fix: Cleaned up page.tsx for Admin League Operations.
alexappleget Oct 10, 2024
db19193
Merge remote-tracking branch 'origin/develop' into alex/implement-adm…
alexappleget Oct 15, 2024
da1d086
Nit Fix: Alphabetized the column headers
alexappleget Oct 15, 2024
00bab8c
Fix: Cleaned up page.tsx and added in <TableData /> component.
alexappleget Oct 15, 2024
d5f1eb7
Fix: Deleted apiFunctions and interface props as they aren't within t…
alexappleget Oct 15, 2024
6ae8dcd
Fix: Cleaned up column keys/headers for LeagueHeader for readability.
alexappleget Oct 15, 2024
80a8505
Fix: Fetched user league data and tweaked table column functionality …
alexappleget Oct 15, 2024
0036b06
Fix: Creating apiFunction to grab all entries in the leagues a user i…
alexappleget Oct 15, 2024
13d2a75
Fix: updated function to grab entries length.
alexappleget Oct 16, 2024
8d900d7
Fix: Got it working to show total entries in each league.
alexappleget Oct 16, 2024
7a0d5f4
Fix: Got data table to render total entries and entries alive. Also s…
alexappleget Oct 16, 2024
a3b6742
Fix: Deleted the utils function I created.
alexappleget Oct 16, 2024
f31c3b9
Fix: created interface file for new column props.
alexappleget Oct 16, 2024
5b7e609
Fix: alphabetized combinedData props.
alexappleget Oct 16, 2024
2d93d72
Fix: alphabetized things that I can in the page.tsx file for admin le…
alexappleget Oct 16, 2024
62873d3
Fix: alphabetized imports in TableColumns
alexappleget Oct 16, 2024
9939f20
Fix: creating api test for the getAllLeagueEntries();
alexappleget Oct 16, 2024
d621df0
Fix: fixed testing for getAllLeagueEntries()
alexappleget Oct 16, 2024
1559c7d
Fix: fixed testing
alexappleget Oct 16, 2024
798ff07
Fix: made page.tsx testing that passes but has an error.
alexappleget Oct 16, 2024
fea5080
Merge remote-tracking branch 'origin/develop' into alex/implement-adm…
alexappleget Oct 16, 2024
a0c3859
Fix: deleted comment code
alexappleget Oct 17, 2024
4017afd
Merge remote-tracking branch 'origin/develop' into alex/implement-adm…
alexappleget Oct 17, 2024
8f8258a
Fix: created test for getAllLeagueEntries() apiFunction
alexappleget Oct 17, 2024
d2f88e4
Fix: Fixed api function testing for getAllLeagueEntries.
alexappleget Oct 17, 2024
a894326
Fix: created testing for admin league page
alexappleget Oct 17, 2024
1f6048e
Fix: added sorting code
alexappleget Oct 17, 2024
6572029
Fix: got rid of trycatch{} block.
alexappleget Oct 18, 2024
2e8b5ae
Fix: handled comment by changing console.error to throw new Error in …
alexappleget Oct 21, 2024
8f62f60
Merge remote-tracking branch 'origin/develop' into alex/implement-adm…
alexappleget Oct 24, 2024
36f4803
Merge remote-tracking branch 'origin/develop' into alex/implement-adm…
alexappleget Oct 27, 2024
6a7650a
Fix: Handled Shashi's comment about apiFunction error code.
alexappleget Oct 28, 2024
adffce8
Merge remote-tracking branch 'origin/develop' into alex/implement-adm…
alexappleget Oct 31, 2024
fa72e54
Fix: changed divs to p tags.
alexappleget Oct 31, 2024
d2aa3b2
Merge remote-tracking branch 'origin/develop' into alex/implement-adm…
alexappleget Nov 6, 2024
31a41c4
Fix: changed <p> tags to <span> tags
alexappleget Nov 11, 2024
7436de1
Merge remote-tracking branch 'origin/develop' into alex/implement-adm…
alexappleget Nov 11, 2024
abe1d5d
Fix: Created apiFunction to grab entry data for the league provided. …
alexappleget Nov 18, 2024
04f22e9
Fix: Created player columns code as well as props.
alexappleget Nov 18, 2024
5ea61a4
Fix: replaced divs with spans to avoid classless divs
alexappleget Nov 18, 2024
389ebc2
Fix: Fixed testing
alexappleget Nov 18, 2024
f6944f2
Fix: fixed testing for apiFunction getTotalEntries
alexappleget Nov 18, 2024
3134021
Fix: changed getAllLeagueEntries apiFunction name to getTotalEntries
alexappleget Nov 18, 2024
f301ee9
Fix: fixed testing
alexappleget Nov 18, 2024
b64d2ed
Merge branch 'alex/implement-admin-league-operation' into alex/implem…
alexappleget Nov 18, 2024
3c00a2b
Fix: Deleted page.tsx test to try and pinpoint appwrite errors
alexappleget Nov 18, 2024
2375c47
Fix: created test for player table in the page.tsx
alexappleget Nov 18, 2024
cfd0ece
Fix: added / to fix test in the mock
alexappleget Nov 18, 2024
b26a582
Fix: changed test name to match new function name
alexappleget Nov 18, 2024
b1afad7
Merge branch 'alex/implement-admin-league-operation' into alex/implem…
alexappleget Nov 18, 2024
5998ed0
Fix: created test for getAllLeagueEntries function
alexappleget Nov 18, 2024
c212efd
Merge remote-tracking branch 'origin/develop' into alex/implement-adm…
alexappleget Nov 21, 2024
2ea96f4
Fix: added spacing for SelectedTeams into Selected Teams
alexappleget Nov 25, 2024
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
103 changes: 103 additions & 0 deletions api/apiFunctions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
resetPassword,
resetRecoveredPassword,
updateUserEmail,
getTotalEntries,
getAllLeagueEntries
} from './apiFunctions';
import { IUser } from './apiFunctions.interface';
import { account, databases, ID } from './config';
Expand Down Expand Up @@ -497,4 +499,105 @@ describe('apiFunctions', () => {
);
});
});

describe('getTotalEntries()', () => {
beforeEach(() => {
jest.clearAllMocks();
});
it('should return the total number of entries and alive entries in a league', async () => {
(databases.listDocuments as jest.Mock).mockResolvedValue({
documents: [
{
name: 'Entry 1',
user: '1234',
league: {
$id: 'league1',
survivors: ['123'],
participants: ['123', '1234'],
leagueName: 'League 1',
logo: '',
},
eliminated: true,
selectedTeams: ['Browns', 'Bears'],
},
{
name: 'Entry 2',
user: '1234',
league: {
$id: 'league1',
survivors: ['123'],
participants: ['123', '1234'],
leagueName: 'League 1',
logo: '',
},
eliminated: false,
selectedTeams: ['Patriots', 'Eagles'],
},
{
name: 'Entry 3',
user: '1234',
league: {
$id: 'league2',
survivors: ['123'],
participants: ['123', '1234'],
leagueName: 'League 2',
logo: '',
},
eliminated: false,
selectedTeams: ['Bears', 'Cowboys'],
},
],
});

const leagues = ['league1', 'league2'];

const result = await getTotalEntries({ leagues });

expect(result).toEqual([
{
totalEntries: 2,
alive: 1,
},
{
totalEntries: 1,
alive: 1,
},
]);
});
});

describe('getAllLeagueEntries()', () => {
it('should return all the entry data for a given league', async () => {
(databases.listDocuments as jest.Mock).mockResolvedValue({
documents: [
{
name: 'Entry 1',
user: '1234',
league: {
$id: 'league1',
survivors: ['123'],
participants: ['123', '1234'],
leagueName: 'League 1',
logo: '',
},
eliminated: true,
selectedTeams: ['Browns', 'Bears'],
},
],
});

const league = 'league1'

const result = await getAllLeagueEntries({ leagueId: league });

expect(result).toEqual([
{
entryName: 'Entry 1',
entryUser: '1234',
entrySelectedTeams: ['Browns', 'Bears'],
entryEliminated: true,
}
]);
});
});
});
79 changes: 78 additions & 1 deletion api/apiFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,6 @@ export async function createEntry({
}

/**

* Update an entry
* @param props - The entry data
* @param props.entryId - The entry ID
Expand Down Expand Up @@ -498,3 +497,81 @@ export async function addUserToLeague({
throw new Error('Error getting user document ID', { cause: error });
}
}

/**
* Grabs the length of entries in each league.
* @param props - Props being passed in.
* @param props.leagues - All user leagues.
* @returns {Promise<number>} - Length of entries.
*/
export async function getTotalEntries({
leagues,
}: {
leagues: string[];
}): Promise<{ totalEntries: number; alive: number }[]> {
try {
const response = await databases.listDocuments(
appwriteConfig.databaseId,
Collection.ENTRIES,
[Query.limit(5000)],
);
const entries = leagues.map((leagueId) => {
const leagueEntries = response.documents.filter(
(entry) => entry.league.$id === leagueId,
);
const aliveEntries = leagueEntries.filter(
(aliveEntry) => aliveEntry.eliminated === false,
);

return {
totalEntries: leagueEntries.length,
alive: aliveEntries.length,
};
});
return entries;
} catch (error) {
throw error;
}
}

/**
* To get all entry data for the player data table.
* @param props - Props being passed in.
* @param props.leagueId - ID of the league.
* @returns {Promise} - All the entries in that league.
*/
export async function getAllLeagueEntries({
leagueId,
}: {
leagueId: string;
}): Promise<
{
entryName: string;
entryUser: string;
entrySelectedTeams: string[];
entryEliminated: boolean;
}[]
> {
try {
const response = await databases.listDocuments(
appwriteConfig.databaseId,
Collection.ENTRIES,
[Query.limit(5000)],
);

const entries = response.documents.filter(
(entry) => entry.league.$id === leagueId,
);

const mappedEntries = entries.map((entry) => ({
entryName: entry.name,
entryUser: entry.user,
entrySelectedTeams: entry.selectedTeams,
entryEliminated: entry.eliminated,
}));

return mappedEntries;
} catch (error) {
throw error;
}
}
46 changes: 41 additions & 5 deletions app/(admin)/admin/leagues/page.test.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
import { render, screen } from '@testing-library/react';
import { render, screen, waitFor } from '@testing-library/react';
import AdminLeagues from './page';
import { getUserLeagues } from '@/utils/utils';
import { getTotalEntries } from '@/api/apiFunctions';

jest.mock('@/store/dataStore', () => ({
useDataStore: jest.fn(() => ({
user: {
documentId: '123',
id: '1234',
email: 'test@test.com',
leagues: ['league1', 'league2'],
},
})),
}));

jest.mock('@/utils/utils', () => ({
getUserLeagues: jest.fn(() => Promise.resolve([])),
cn: jest.fn(),
}));

jest.mock('@/api/apiFunctions', () => ({
getTotalEntries: jest.fn(),
}));

describe('AdminLeagues', () => {
it('should render the AdminLeagues page with LeagueCard components', () => {
render(<AdminLeagues />);
const leagueCards = screen.getAllByTestId('LeagueCard');
expect(leagueCards.length).toBe(3);
render(<AdminLeagues />);

const mockGetUserLeagues = getUserLeagues as jest.Mock;
const mockGetTotalEntries = getTotalEntries as jest.Mock;

beforeEach(() => {
jest.clearAllMocks();
});

it('should render the League data table component', async () => {
mockGetTotalEntries.mockResolvedValue([]);

mockGetUserLeagues.mockResolvedValue([]);

await waitFor(() => {
const leagueTable = screen.getByTestId('data-table');
expect(leagueTable).toBeInTheDocument();
});
});
});
54 changes: 34 additions & 20 deletions app/(admin)/admin/leagues/page.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,48 @@
// Copyright (c) Gridiron Survivor.
// Licensed under the MIT License.

import { JSX } from 'react';
import { LeagueCard } from '@/components/LeagueCard/LeagueCard';
'use client';
import { getTotalEntries } from '@/api/apiFunctions';
import { getUserLeagues } from '@/utils/utils';
import { IEntryWithLeague } from '@/components/TableColumns/LeagueColumns/LeagueColumns.interface';
import { JSX, useEffect, useState } from 'react';
import { leagueColumns } from '@/components/TableColumns/LeagueColumns/LeagueColumns';
import TableData from '@/components/TableData/TableData';
import { useDataStore } from '@/store/dataStore';

/**
* Renders the admin page.
* @returns {JSX.Element} - The rendered Admin Leagues page.
*/
const AdminLeagues = (): JSX.Element => {
const [leaguesData, setLeaguesData] = useState<IEntryWithLeague[]>([]);
const { user } = useDataStore((state) => state);

/**
* Get all leagues the user is a part of.
*/
const fetchData = async (): Promise<void> => {
const entries = await getTotalEntries({ leagues: user.leagues });
const leagues = await getUserLeagues(user.leagues);
const combinedData = leagues.map((league, index) => ({
aliveEntries: entries[index].alive,
leagueId: '',
leagueName: league.leagueName,
logo: '',
participants: league.participants,
survivors: league.survivors,
totalEntries: entries[index].totalEntries,
}));
setLeaguesData(combinedData);
};

useEffect(() => {
fetchData();
}, [user.leagues]);

return (
<section className="grid grid-cols-2 gap-6">
<LeagueCard
href={'#'}
survivors={20}
title={'Demo League 1'}
totalPlayers={30}
/>
<LeagueCard
href={'#'}
survivors={20}
title={'Demo League 2'}
totalPlayers={30}
/>
<LeagueCard
href={'#'}
survivors={20}
title={'Demo League 3'}
totalPlayers={30}
/>
<TableData columns={leagueColumns} data={leaguesData} />
</section>
);
};
Expand Down
31 changes: 21 additions & 10 deletions app/(admin)/admin/players/page.test.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
// /Users/ryanfurrer/Developer/GitHub/gridiron-survivor/app/(admin)/admin/notifications/page.test.tsx
import { render, screen, waitFor } from "@testing-library/react";
import AdminPlayers from "./page";
import { getAllLeagueEntries } from "@/api/apiFunctions";

import { render, screen } from '@testing-library/react';
import AdminPlayers from './page';
import React from 'react';
jest.mock('@/api/apiFunctions', () => ({
getAllLeagueEntries: jest.fn(),
}));

describe('Admin players page', () => {
it(`should render it's content`, () => {
render(<AdminPlayers />);
const adminNotificationsContent = screen.getByTestId(
'admin-players-content',
);
expect(adminNotificationsContent).toBeInTheDocument();
render(<AdminPlayers />);

const mockGetAllLeagueEntries = getAllLeagueEntries as jest.Mock;

beforeEach(() => {
jest.clearAllMocks();
});

it('should render the Player data table component', async () => {
mockGetAllLeagueEntries.mockResolvedValue({});

await waitFor(() => {
const playerTable = screen.getByTestId('data-table');
expect(playerTable).toBeInTheDocument();
})
})
});
Loading