Skip to content

Commit

Permalink
fix data store test
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-nowicki committed Oct 16, 2024
1 parent 7b35b78 commit a58e76d
Showing 1 changed file with 34 additions and 31 deletions.
65 changes: 34 additions & 31 deletions store/dataStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ const allLeagues = [
leagueName: 'Test League',
logo: 'https://findmylogo.com/logo.png',
participants: ['123456', '78'],
survivors: ['123456', '78', '9'],}
survivors: ['123456', '78', '9'],
},
];

describe('Data Store', () => {
Expand All @@ -71,23 +72,23 @@ describe('Data Store', () => {
act(() => {
result.current.updateUser(
userData.documentId,
userData.userId,
userData.userEmail,
userData.id,
userData.email,
userData.leagues,
);
});

expect(result.current.user.id).toBe(userData.userId);
expect(result.current.user.email).toBe(userData.userEmail);
expect(result.current.user.id).toBe(userData.id);
expect(result.current.user.email).toBe(userData.email);
});
it('Checks the reset user state matches default', () => {
const { result } = renderHook(() => useDataStore());

act(() => {
result.current.updateUser(
userData.documentId,
userData.userId,
userData.userEmail,
userData.id,
userData.email,
userData.leagues,
);
result.current.resetUser();
Expand Down Expand Up @@ -130,20 +131,20 @@ describe('Data Store', () => {
userResults: {
'123': {
'456': {
'entry1': {
teamName: 'New England Patriots',
correct:true
entry1: {
teamName: 'New England Patriots',
correct: true,
},
entry2: {
teamName: 'Kansas City Chiefs',
correct: false,
},
entry3: {
teamName: 'New England Patriots',
correct: false,
},
},
'entry2': {
teamName: 'Kansas City Chiefs',
correct:false
},
'entry3': {
teamName: 'New England Patriots',
correct:false
}
}
}
},
},
};
act(() => {
Expand All @@ -156,25 +157,27 @@ describe('Data Store', () => {
});
});

describe('League Test', () => {
describe('All Leagues Test', () => {
it('Check the default league state', () => {
const { result } = renderHook(() => useDataStore());
expect(result.current.leagues).toStrictEqual([]);
expect(result.current.allLeagues).toStrictEqual([]);
});
it('Check the updated league state', () => {
const { result } = renderHook(() => useDataStore());

act(() => {
result.current.updateLeagues(league);
result.current.updateAllLeagues(league);
});

expect(result.current.leagues[0].leagueId).toBe(league[0].leagueId);
expect(result.current.leagues[0].leagueName).toBe(league[0].leagueName);
expect(result.current.leagues[0].logo).toBe(league[0].logo);
expect(result.current.leagues[0].participants).toBe(
expect(result.current.allLeagues[0].leagueId).toBe(league[0].leagueId);
expect(result.current.allLeagues[0].leagueName).toBe(
league[0].leagueName,
);
expect(result.current.allLeagues[0].logo).toBe(league[0].logo);
expect(result.current.allLeagues[0].participants).toBe(
league[0].participants,
);
expect(result.current.leagues[0].survivors).toBe(league[0].survivors);
expect(result.current.allLeagues[0].survivors).toBe(league[0].survivors);
});
});

Expand Down Expand Up @@ -219,10 +222,10 @@ xdescribe('getting all leagues test', () => {
expect(result.current.allLeagues).toStrictEqual([]);
});
it('check the updated allLeagues state', async () => {
const { result } = renderHook(() => useDataStore());
const { result } = renderHook(() => useDataStore());
act(() => {
result.current.updateAllLeagues(allLeagues);
});
expect(result.current.allLeagues).toStrictEqual(allLeagues);
})
})
});
});

0 comments on commit a58e76d

Please sign in to comment.