Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not documented list routes test #109

Merged
merged 2 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/auth/jwt/ietf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,23 @@ pub struct Claims {

#[cfg(test)]
mod tests {
use std::ops::{Add, Sub};
use std::str::FromStr;

use super::*;
use crate::auth::jwt::decode_auth_token;
use crate::util::serde_util::UriOrString;
use chrono::{TimeDelta, Utc};
use jsonwebtoken::{encode, EncodingKey, Header, TokenData};
use serde_derive::{Deserialize, Serialize};
use serde_json::from_str;
use std::ops::{Add, Sub};
use std::str::FromStr;
use url::Url;

use crate::auth::jwt::decode_auth_token;
use crate::auth::jwt::ietf::{Claims, Subject};
use crate::util::serde_util::UriOrString;

const TEST_JWT_SECRET: &str = "test-jwt-secret";
const AUDIENCE: &[&str] = &["authenticated"];
const REQUIRED_CLAIMS: &[&str] = &[];

#[test]
fn test_decode_token() {
fn decode_token() {
let jwt = build_token(false, None);

let decoded: TokenData<Claims> =
Expand All @@ -79,7 +77,7 @@ mod tests {
}

#[test]
fn test_decode_token_expired() {
fn decode_token_expired() {
let (_, jwt) = build_token(true, None);

let decoded: anyhow::Result<TokenData<Claims>> =
Expand All @@ -89,7 +87,7 @@ mod tests {
}

#[test]
fn test_decode_token_wrong_audience() {
fn decode_token_wrong_audience() {
let (_, jwt) = build_token(false, Some("different-audience".to_string()));

let decoded: anyhow::Result<TokenData<Claims>> =
Expand Down
2 changes: 1 addition & 1 deletion src/auth/jwt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub enum Subject {

#[cfg(test)]
mod tests {
use crate::auth::jwt::Subject;
use super::*;
use serde_derive::{Deserialize, Serialize};
use serde_json::from_str;
use std::str::FromStr;
Expand Down
2 changes: 1 addition & 1 deletion src/auth/jwt/openid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub enum Acr {

#[cfg(test)]
mod tests {
use crate::auth::jwt::openid::Acr;
use super::*;
use serde_derive::{Deserialize, Serialize};
use serde_json::from_str;
use std::str::FromStr;
Expand Down
4 changes: 2 additions & 2 deletions src/config/service/http/initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ impl<T: Default> InitializerConfig<T> {
}

#[cfg(test)]
mod test {
mod tests {
use super::*;
use serde_json::Value;

#[test]
fn test_custom_config() {
fn custom_config() {
// Note: since we're parsing into a Initializer config struct directly, we don't
// need to prefix `foo` with `initializer`. If we want to actually provide custom initializer
// configs, the table key will need to be `[initializer.foo]`.
Expand Down
4 changes: 2 additions & 2 deletions src/config/service/http/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,12 @@ impl<T: Default> MiddlewareConfig<T> {
}

#[cfg(test)]
mod test {
mod tests {
use super::*;
use serde_json::Value;

#[test]
fn test_custom_config() {
fn custom_config() {
// Note: since we're parsing into a Middleware config struct directly, we don't
// need to prefix `foo` with `middleware`. If we want to actually provide custom middleware
// configs, the table key will need to be `[middleware.foo]`.
Expand Down
9 changes: 6 additions & 3 deletions src/service/http/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ mod tests {
#[test]
#[cfg(feature = "open-api")]
fn list_routes() {
use crate::service::http::service::HttpService;
use aide::axum::routing::{delete_with, get_with, post_with, put_with};
use super::*;
use aide::axum::routing::{delete_with, get, get_with, post_with, put_with};
use aide::axum::ApiRouter;
use aide::openapi::OpenApi;
use itertools::Itertools;
Expand All @@ -152,6 +152,9 @@ mod tests {
.api_route("/a", delete_with(api_method, |op| op))
.api_route("/c", get_with(api_method, |op| op))
.api_route("/b", get_with(api_method, |op| op))
// Methods registered with `get` instead of `get_with` will not have OpenAPI
// documentation generated, but will still be included in the list of routes.
.api_route("/not_documented", get(api_method))
.finish_api(&mut open_api);

let service = HttpService {
Expand All @@ -166,7 +169,7 @@ mod tests {
.collect_vec();
assert_eq!(
paths,
["/a", "/b", "/bar", "/baz", "/c", "/foo"]
["/a", "/b", "/bar", "/baz", "/c", "/foo", "/not_documented"]
.iter()
.map(|s| s.to_string())
.collect_vec()
Expand Down