Full fix for getProject route, testing, integration testing and frontend-API code

This commit is contained in:
Imbus 2024-03-18 16:42:35 +01:00
parent 741ad50ccf
commit 0c2617d0cb
7 changed files with 82 additions and 2 deletions

View file

@ -46,6 +46,7 @@ interface API {
username: string,
token: string,
): Promise<APIResponse<Project[]>>;
getProject(id: number): Promise<APIResponse<Project>>;
}
// Export an instance of the API
@ -253,4 +254,30 @@ export const api: API = {
return Promise.resolve({ success: false, message: "Failed to login" });
}
},
// Gets a projet by id, currently untested since we have no javascript-based tests
async getProject(id: number): Promise<APIResponse<Project>> {
try {
const response = await fetch(`/api/project/${id}`, {
method: "GET",
});
if (!response.ok) {
return {
success: false,
message: "Failed to get project: Response code " + response.status,
};
} else {
const data = (await response.json()) as Project;
return { success: true, data };
}
// The code below is garbage but satisfies the linter
// This needs fixing, do not copy this pattern
} catch (e: unknown) {
return {
success: false,
message: "Failed to get project: " + (e as Error).toString(),
};
}
},
};