added some tests

This commit is contained in:
QkoSad
2025-07-14 10:37:41 +03:00
parent 98e689bfc5
commit e28bde1cfe
5 changed files with 36 additions and 36 deletions
+1 -1
View File
@@ -120,7 +120,7 @@ public class UnitTest1
using HttpClient client = new();
HttpResponseMessage response = await client.GetAsync("http://localhost:5000/api/getuser");
Assert.AreEqual((int)response.StatusCode, 400);
Assert.AreEqual((int)response.StatusCode, 200);
}
[TestMethod]
-1
View File
@@ -1,7 +1,6 @@
using System.IdentityModel.Tokens.Jwt;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;
using Microsoft.IdentityModel.Tokens;
using MySql.Data.MySqlClient;
using Newtonsoft.Json.Linq;
+17 -17
View File
@@ -7,23 +7,6 @@ namespace TimelogBackend;
public class Getuser : Route
{
private static dynamic ExtractDataFromDB(MySqlCommand cmd)
{
using MySqlConnection conn = new(connectionString);
conn.Open();
cmd.Connection = conn;
// execute query and read results
MySqlDataReader reader = cmd.ExecuteReader();
dynamic expando = new ExpandoObject();
while (reader.Read())
{
((IDictionary<string?, object>)expando)[reader["name"].ToString()] = reader[
"SUM(t.time)"
];
}
return expando;
}
public static void HandleRequest(HttpListenerRequest request, HttpListenerResponse response)
{
try
@@ -56,4 +39,21 @@ public class Getuser : Route
SendError(response, ex);
}
}
private static dynamic ExtractDataFromDB(MySqlCommand cmd)
{
using MySqlConnection conn = new(connectionString);
conn.Open();
cmd.Connection = conn;
// execute query and read results
MySqlDataReader reader = cmd.ExecuteReader();
dynamic expando = new ExpandoObject();
while (reader.Read())
{
((IDictionary<string?, object>)expando)[reader["name"].ToString()] = reader[
"SUM(t.time)"
];
}
return expando;
}
}
+15 -14
View File
@@ -11,13 +11,13 @@ import {
} from "@mui/material";
interface User {
date: string;
f_name: string;
l_name: string;
mail: string;
name: string;
time: number;
user: number;
Date: string;
FName: string;
LName: string;
Mail: string;
Name: string;
Time: number;
User: number;
}
//TODO date input should send error when there is no data in the response
@@ -47,6 +47,7 @@ const LeftSide = ({
useEffect(() => {
async function fetchData() {
const resp = await api.get("/getall", { params });
console.log(resp.data);
if (resp.data.length) setUsers(resp.data);
}
async function resetData() {
@@ -156,14 +157,14 @@ const LeftSide = ({
{users.length > 0 && Array.isArray(users) ? (
users.map((post, idx) => (
<TableRow key={idx}>
<TableCell>{post.f_name} </TableCell>
<TableCell>{post.l_name} </TableCell>
<TableCell>{post.mail} </TableCell>
<TableCell>{post.name} </TableCell>
<TableCell>{post.date.slice(0, 10)} </TableCell>
<TableCell>{post.time} </TableCell>
<TableCell>{post.FName} </TableCell>
<TableCell>{post.LName} </TableCell>
<TableCell>{post.Mail} </TableCell>
<TableCell>{post.Name} </TableCell>
<TableCell>{post.Date.slice(0, 10)} </TableCell>
<TableCell>{post.Time} </TableCell>
<TableCell>
<button onClick={() => viewProjectHours(post.user)}>
<button onClick={() => viewProjectHours(post.User)}>
Hours
</button>
</TableCell>
+3 -3
View File
@@ -28,13 +28,13 @@ const RightSide = ({ reset }: { reset: boolean }) => {
// turn the data into form suitable to charts
if (filter === "project")
for (let idx = 1; idx < resp.data.length; idx++) {
resp.data[idx] = [resp.data[idx].name, resp.data[idx].total_time];
resp.data[idx] = [resp.data[idx].Name, resp.data[idx].TotalTime];
}
else if (filter === "user")
for (let idx = 1; idx < resp.data.length; idx++) {
resp.data[idx] = [
resp.data[idx].f_name + " " + resp.data[idx].l_name,
resp.data[idx].total_time,
resp.data[idx].FName + " " + resp.data[idx].LName,
resp.data[idx].TotalTime,
];
}
setChartData(resp.data);