running 1 test
test tests::handler_handles ... FAILED
failures:
- --- tests::handler_handles stdout ----
handler
thread 'tests::handler_handles' panicked at 'assertion failed: `(left == right)`
left: `ApiGatewayProxyResponse { status_code: 200, headers: {}, multi_value_headers: {}, body: Some(Text("{\\"name\\":\\"Charmander\\",\\"hp\\":39}")), is_base64_encoded: Some(false) }`,
right: `ApiGatewayProxyResponse { status_code: 200, headers: {}, multi_value_headers: {}, body: Some(Text("{\\"name\\":\\"Bulbasaur\\",\\"hp\\":45}")), is_base64_encoded: Some(false) }`', crates/pokemon-api/src/main.rs:123:9
Our SQL query is currently hard coded to fetch bulbasaur
.
sqlx::query_as!(
PokemonHp,
r#"SELECT name, hp FROM pokemon WHERE slug = "bulbasaur""#
)
We can replace "bulbasaur"
with a ?
placeholder. After we do this, we need to pass the additional argument in because sqlx will keep track of how many placeholders we're using and how many arguments we're passing in.
sqlx::query_as!(
PokemonHp,
r#"SELECT name, hp FROM pokemon WHERE slug = ?"#,
"charmander"
)
Running cargo test
with either the local database connection or the one we set up for the serverless function will show us a new test failure, which is expected because we changed the query.
running 1 test
test tests::handler_handles ... FAILED
failures:
---- tests::handler_handles stdout ----
handler
thread 'tests::handler_handles' panicked at 'assertion failed: `(left == right)`
left: `ApiGatewayProxyResponse { status_code: 200, headers: {}, multi_value_headers: {}, body: Some(Text("{\"name\":\"Charmander\",\"hp\":39}")), is_base64_encoded: Some(false) }`,
right: `ApiGatewayProxyResponse { status_code: 200, headers: {}, multi_value_headers: {}, body: Some(Text("{\"name\":\"Bulbasaur\",\"hp\":45}")), is_base64_encoded: Some(false) }`', crates/pokemon-api/src/main.rs:123:9
We can update the handler_handles
test to use the new data and the tests will pass.
&PokemonHp{
name: String::from("Charmander"),
hp: 39
},