Skip to content

Commit

Permalink
Fix logic of old robonode-server empty response at robonode-client side
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylavrenov committed Sep 16, 2024
1 parent 469136f commit 77f2c10
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions crates/robonode-client/src/enroll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ impl Client {
let url = format!("{}/enroll", self.base_url);
let res = self.reqwest.post(url).json(&req).send().await?;
match res.status() {
StatusCode::CREATED => Ok(res.json().await?),
StatusCode::CREATED => {
if let Some(0) = res.content_length() {
Ok(EnrollResponse {
scan_result_blob: None,
})
} else {
Ok(res.json().await?)
}
}
status => Err(Error::Call(EnrollError::from_response(
status,
res.text().await?,
Expand Down Expand Up @@ -157,17 +165,11 @@ mod tests {
public_key: b"123",
liveness_data_signature: b"signature",
};
let sample_response = serde_json::json!({
"scanResultBlob": "scanResultBlob"
});

let expected_response: EnrollResponse =
serde_json::from_value(sample_response.clone()).unwrap();

Mock::given(matchers::method("POST"))
.and(matchers::path("/enroll"))
.and(matchers::body_json(&sample_request))
.respond_with(ResponseTemplate::new(201).set_body_json(&sample_response))
.respond_with(ResponseTemplate::new(201))
.mount(&mock_server)
.await;

Expand All @@ -176,8 +178,7 @@ mod tests {
reqwest: reqwest::Client::new(),
};

let actual_response = client.enroll(sample_request).await.unwrap();
assert_eq!(actual_response, expected_response);
client.enroll(sample_request).await.unwrap();
}

#[tokio::test]
Expand Down

0 comments on commit 77f2c10

Please sign in to comment.