improving get method and its test

This commit is contained in:
filipriec
2025-02-24 20:27:18 +01:00
parent 7e45daff10
commit 7a98bcd72e
4 changed files with 34 additions and 36 deletions

View File

@@ -1,4 +1,4 @@
grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.Adresar/GetAdresar grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
{ {
"id": "1", "id": "1",
"firma": "Updated Firma", "firma": "Updated Firma",
@@ -17,7 +17,7 @@
"skladu": "Updated Skladu", "skladu": "Updated Skladu",
"fax": "Updated Fax" "fax": "Updated Fax"
} }
grpcurl -plaintext -d '{"id": 2}' localhost:50051 multieko2.Adresar/GetAdresar grpcurl -plaintext -d '{"id": 2}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
{ {
"id": "2", "id": "2",
"firma": "asdfasf", "firma": "asdfasf",
@@ -36,15 +36,15 @@
"skladu": "f", "skladu": "f",
"fax": " " "fax": " "
} }
grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.Adresar/DeleteAdresar grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.adresar.Adresar/DeleteAdresar
{ {
"success": true "success": true
} }
grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.Adresar/GetAdresar grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
ERROR: ERROR:
Code: NotFound Code: NotFound
Message: no rows returned by a query that expected to return at least one row Message: no rows returned by a query that expected to return at least one row
grpcurl -plaintext -d '{"id": 2}' localhost:50051 multieko2.Adresar/GetAdresar grpcurl -plaintext -d '{"id": 2}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
{ {
"id": "2", "id": "2",
"firma": "asdfasf", "firma": "asdfasf",
@@ -80,7 +80,7 @@ ERROR:
"telefon": "New Telefon", "telefon": "New Telefon",
"skladu": "New Skladu", "skladu": "New Skladu",
"fax": "New Fax" "fax": "New Fax"
}' localhost:50051 multieko2.Adresar/PostAdresar }' localhost:50051 multieko2.adresar.Adresar/PostAdresar
{ {
"id": "43", "id": "43",
"firma": "New Firma", "firma": "New Firma",
@@ -116,7 +116,7 @@ ERROR:
"telefon": "Updated Telefon", "telefon": "Updated Telefon",
"skladu": "Updated Skladu", "skladu": "Updated Skladu",
"fax": "Updated Fax" "fax": "Updated Fax"
}' localhost:50051 multieko2.Adresar/PutAdresar }' localhost:50051 multieko2.adresar.Adresar/PutAdresar
{ {
"id": "43", "id": "43",
"firma": "Updated Firma", "firma": "Updated Firma",
@@ -135,7 +135,7 @@ ERROR:
"skladu": "Updated Skladu", "skladu": "Updated Skladu",
"fax": "Updated Fax" "fax": "Updated Fax"
} }
grpcurl -plaintext -d '{"id": 43}' localhost:50051 multieko2.Adresar/GetAdresar grpcurl -plaintext -d '{"id": 43}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
{ {
"id": "43", "id": "43",
"firma": "Updated Firma", "firma": "Updated Firma",

View File

@@ -1,31 +1,27 @@
# TOTAL items in the adresar
grpcurl -plaintext localhost:50051 multieko2.Adresar/GetAdresarCount
{
"count": "43"
}
# Item at this count. If there are 43 items, number 1 is the first item # TOTAL items in the adresar
grpcurl -plaintext -d '{"position": 1}' localhost:50051 multieko2.Adresar/GetAdresarByPosition grpcurl -plaintext localhost:50051 multieko2.adresar.Adresar/GetAdresarCount
{ {
"id": "2", "count": "5"
"firma": "asdfasf", }
"kz": " ", # Item at this count. If there are 43 items, number 1 is the first item
"drc": " ", grpcurl -plaintext -d '{"position": 1}' localhost:50051 multieko2.adresar.Adresar/GetAdresarByPosition
"ulica": " ", {
"psc": "sdfasdf", "id": "1",
"firma": "ks555",
"kz": "f",
"drc": "asdf",
"ulica": "as",
"psc": "f",
"mesto": "asf", "mesto": "asf",
"stat": "as", "stat": "as",
"banka": "df", "banka": "fa",
"ucet": "asf", "telefon": "a",
"skladm": "f", "skladu": "fd",
"ico": "f", "fax": "asf"
"kontakt": "f",
"telefon": "f",
"skladu": "f",
"fax": " "
} }
# Item fetched by id. The first item was created and removed, therefore number 1 in ids doenst exists, since first to exist now has number 2 # Item fetched by id. The first item was created and removed, therefore number 1 in ids doenst exists, since first to exist now has number 2
grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.Adresar/GetAdresar grpcurl -plaintext -d '{"id": 1}' localhost:50051 multieko2.adresar.Adresar/GetAdresar
ERROR: ERROR:
Code: NotFound Code: NotFound
Message: no rows returned by a query that expected to return at least one row Message: no rows returned by a query that expected to return at least one row

View File

@@ -30,13 +30,16 @@ pub async fn get_adresar(
skladu, skladu,
fax fax
FROM adresar FROM adresar
WHERE id = $1 WHERE id = $1 AND deleted = false
"#, "#,
request.id request.id
) )
.fetch_one(db_pool) .fetch_one(db_pool)
.await .await
.map_err(|e| Status::not_found(e.to_string()))?; .map_err(|e| match e {
sqlx::Error::RowNotFound => Status::not_found("Record not found"),
_ => Status::internal(format!("Database error: {}", e)),
})?;
Ok(AdresarResponse { Ok(AdresarResponse {
id: adresar.id, id: adresar.id,

View File

@@ -157,11 +157,10 @@ async fn test_get_deleted_record(
) { ) {
let (pool, id) = existing_deleted_record.await; let (pool, id) = existing_deleted_record.await;
let request = GetAdresarRequest { id }; let request = GetAdresarRequest { id };
let response = get_adresar(&pool, request).await.unwrap(); let result = get_adresar(&pool, request).await;
assert_eq!(response.firma, "Deleted Company"); assert!(result.is_err());
assert_eq!(response.kz, ""); assert_eq!(result.unwrap_err().code(), tonic::Code::NotFound);
assert_eq!(response.drc, "");
} }
#[rstest] #[rstest]