Skip to content

Commit

Permalink
added error to api endpoint function
Browse files Browse the repository at this point in the history
  • Loading branch information
IrisOlfermann committed Jan 15, 2024
1 parent 8a470b1 commit b30b1ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 6 additions & 4 deletions src/Resources/src/api/getParticipationsByDay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ const listDataState = ref([])
* @param date
* @returns list of participants
*/
export default function useParticipationsListData(date: string){
export default async function useParticipationsListData(date: string){

const loaded = ref(false)
let useParticipationsError = false

onMounted(async () => {
await getListData();
Expand All @@ -27,10 +28,11 @@ export default function useParticipationsListData(date: string){
return;
}

const { response: listData, request, error } = useApi<ListData>(
const { error, response: listData, request } = useApi<ListData>(
'GET',
`/api/participations/day/${date}`
);
useParticipationsError = error.value

if (loaded.value === false) {
await request();
Expand All @@ -41,7 +43,7 @@ export default function useParticipationsListData(date: string){
}

return {
listData: readonly(listDataState)
}
useParticipationsError, listData: readonly(listDataState)
};
}

6 changes: 3 additions & 3 deletions src/Resources/tests/unit/api/getParticipationsByDate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ useApi.mockReturnValue(mockedReturnValue);

describe('Test getParticipations', () => {
it('should return a list of participations', async () => {
const { listData } = useParticipationsListData("16/01/2024");
const {useParticipationsError, listData} = await useParticipationsListData("2024-01-16");

// expect(error.value).toBeFalsy();
expect(listData).toEqual(Participations);
expect(useParticipationsError).toBeFalsy();
expect(listData.value).toEqual(Participations);
});
});

0 comments on commit b30b1ac

Please sign in to comment.