You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is the recommended flow write unit tests involving headers and cognito authorization? The objective is to write unit tests which mimic frontend requests passing through the http api gateway. For example, suppose we have the function
pubasyncfnhttp_404(_request:Request,_context:Context) -> Result<Response<Body>,Error>{let body = json!({"message":"The requested resource or route do not exist.",});let response = Response::builder().status(404).header("content-type","application/json").body(Body::from(serde_json::to_string(&body)?)).unwrap();Ok(response)}#[tokio::test]asyncfnget_auth_uri(){let global_settings = setup().await;let expected = json!({"message":"The requested resource or route do not exist.".to_string(),}).into_response();let request = Request::new(lambda_http::Body::Text("{}"));let response = handle_get_auth_uri(request,Context::default()).await.expect("expected Ok(_) value").into_response();assert_eq!(response.body(), expected.body())}
We can set a few things beside the body, such as query parameters with request.with_query_string_parameters but I don't see how to set headers or Cognito related parameters. This issue mentions that the CognitoIdentity parameters are deprecated and cannot be used in Context, but there also isn't a clear way to set the RequestContext for mocking. What is the recommended way to do this?
The text was updated successfully, but these errors were encountered:
Hi,
What is the recommended flow write unit tests involving headers and cognito authorization? The objective is to write unit tests which mimic frontend requests passing through the http api gateway. For example, suppose we have the function
We can set a few things beside the body, such as query parameters with
request.with_query_string_parameters
but I don't see how to set headers or Cognito related parameters. This issue mentions that the CognitoIdentity parameters are deprecated and cannot be used inContext
, but there also isn't a clear way to set the RequestContext for mocking. What is the recommended way to do this?The text was updated successfully, but these errors were encountered: