Full fix for getProject route, testing, integration testing and frontend-API code
This commit is contained in:
		
							parent
							
								
									741ad50ccf
								
							
						
					
					
						commit
						0c2617d0cb
					
				
					 7 changed files with 82 additions and 2 deletions
				
			
		|  | @ -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(), | ||||
|       }; | ||||
|     } | ||||
|   }, | ||||
| }; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Imbus
						Imbus