add tests for WithRejection<Valid<...>>
This commit is contained in:
26
src/extra.rs
26
src/extra.rs
@@ -30,6 +30,7 @@ impl<T: Validate, R> HasValidate for WithRejection<T, R> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::tests::{Rejection, ValidTest};
|
||||
use crate::Valid;
|
||||
use axum::http::StatusCode;
|
||||
use axum_extra::extract::{Cached, WithRejection};
|
||||
use reqwest::RequestBuilder;
|
||||
@@ -52,7 +53,6 @@ mod tests {
|
||||
}
|
||||
|
||||
impl<T: ValidTest, R: Rejection> ValidTest for WithRejection<T, R> {
|
||||
// just use conflict to test
|
||||
const ERROR_STATUS_CODE: StatusCode = R::STATUS_CODE;
|
||||
|
||||
fn set_valid_request(builder: RequestBuilder) -> RequestBuilder {
|
||||
@@ -68,4 +68,28 @@ mod tests {
|
||||
T::set_invalid_request(builder)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: ValidTest, R> ValidTest for WithRejection<Valid<T>, R> {
|
||||
// just use `418 I'm a teapot` to test
|
||||
const ERROR_STATUS_CODE: StatusCode = StatusCode::IM_A_TEAPOT;
|
||||
// If `WithRejection` is the outermost extractor,
|
||||
// the error code returned will always be the one provided by WithRejection.
|
||||
const INVALID_STATUS_CODE: StatusCode = StatusCode::IM_A_TEAPOT;
|
||||
// If `WithRejection` is the outermost extractor,
|
||||
// the returned body may not be in JSON format.
|
||||
const JSON_SERIALIZABLE: bool = false;
|
||||
|
||||
fn set_valid_request(builder: RequestBuilder) -> RequestBuilder {
|
||||
T::set_valid_request(builder)
|
||||
}
|
||||
|
||||
fn set_error_request(builder: RequestBuilder) -> RequestBuilder {
|
||||
// invalid requests will cause the Valid extractor to fail.
|
||||
T::set_invalid_request(builder)
|
||||
}
|
||||
|
||||
fn set_invalid_request(builder: RequestBuilder) -> RequestBuilder {
|
||||
T::set_invalid_request(builder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user