Skip to content

Commit

Permalink
Cody/fix getUserLeagues function (#647)
Browse files Browse the repository at this point in the history
Closes #484 

Appwrite returns an array with an empty string if the user is not in any
leagues
- changed the check to account for this
- modified the test for getUserLeagues
  • Loading branch information
kepsteen authored Oct 30, 2024
1 parent 7d3529e commit 96d4679
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@ describe('utils', () => {
});
});

xdescribe('getUserLeagues', () => {
describe('getUserLeagues', () => {
it('should return the list of leagues the user is a part of', async () => {
(getCurrentLeague as jest.Mock).mockResolvedValue(mockLeague);
const result = await getUserLeagues(mockUserData.leagues);
expect(result).toStrictEqual([mockLeague]);
});
it('should return an empty array if the user has no leagues', async () => {
const result = await getUserLeagues([]);
const result = await getUserLeagues(['']);
expect(getCurrentLeague).toHaveBeenCalledTimes(0);
expect(result).toStrictEqual([]);
});
Expand Down
2 changes: 1 addition & 1 deletion utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export const parseUserPick = (
export const getUserLeagues = async (
leagues: IUser['leagues'],
): Promise<ILeague[]> => {
if (!leagues || leagues.length === 0) {
if (!leagues || leagues[0] === '') {
return [];
}
const userLeagues = leagues.map((league) => {
Expand Down

0 comments on commit 96d4679

Please sign in to comment.