+ More comprehensive testing on /neighbor/update
The cases that actually matter should be covered now so I'm confident with this endpoint's behavior ! A preliminary db::neighbors::get is done to cover the 404 case Basically if a bad url is used in the request we should 404 the update as there won't be anything relevant to update
This commit is contained in:
parent
8bff61ab71
commit
e94c720332
@ -141,6 +141,7 @@ if __name__ == '__main__':
|
||||
req(admin,'post', '/neighbor/add', {}, 200, body=to_json(tmp_neighbor)),
|
||||
req(admin, 'get', '/neighbor/list', {}, 200, verbose=True),
|
||||
req(admin, 'put', '/neighbor/update', {'url':str(now)}, 200, body=to_json(updated_neighbor)),
|
||||
req(admin, 'put', '/neighbor/update', {'url':'fake'}, 404, body=to_json(updated_neighbor)),
|
||||
req(admin, 'get', '/neighbor/list', {}, 200, verbose=True),
|
||||
])
|
||||
|
||||
|
@ -104,12 +104,21 @@ pub async fn update_neighbor(p: &Pool, response: &mut Response<Body>, params: Ha
|
||||
// Verify query string parameter **and** body before attempting to reach database
|
||||
match (target, json) {
|
||||
(Some(target_url), Ok(neighbor)) => {
|
||||
// Only return a 500 if something happened on db-lib's end
|
||||
if let Err(e) = db::neighbors::update(p, target_url, neighbor).await {
|
||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||
eprintln!("/neighbor/update [DB-LIB] {}", e);
|
||||
match db::neighbors::get(p, target_url).await {
|
||||
Ok(row) => if row.is_some() {
|
||||
if let Err(e) = db::neighbors::update(p, target_url, neighbor).await {
|
||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||
eprintln!("/neighbor/update [DB-LIB] {}", e);
|
||||
}
|
||||
// Nothing to do on success 200 is already set by hyper
|
||||
} else{
|
||||
*response.status_mut() = StatusCode::NOT_FOUND;
|
||||
},
|
||||
Err(e) => {
|
||||
eprintln!("/neighbor/update {}", e);
|
||||
*response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||
}
|
||||
}
|
||||
// Nothing to do on success 200 is already set by hyper
|
||||
},
|
||||
_ => *response.status_mut() = StatusCode::BAD_REQUEST
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user