Skip to content

Commit 64bea41

Browse files
committed
tests
1 parent 06c51ce commit 64bea41

File tree

2 files changed

+31
-22
lines changed

2 files changed

+31
-22
lines changed

example/src/app.rs

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use async_trait::async_trait;
22
use loco_openapi::prelude::*;
33
use loco_rs::{
4-
Result,
54
app::{AppContext, Hooks, Initializer},
65
bgworker::{BackgroundWorker, Queue},
7-
boot::{BootResult, StartMode, create_app},
6+
boot::{create_app, BootResult, StartMode},
87
config::Config,
98
controller::AppRoutes,
109
db::{self, truncate_table},
1110
environment::Environment,
1211
task::Tasks,
12+
Result,
1313
};
1414
use migration::Migrator;
1515
use std::path::Path;
@@ -42,26 +42,34 @@ impl Hooks for App {
4242
create_app::<Self, Migrator>(mode, environment, config).await
4343
}
4444

45-
async fn initializers(_ctx: &AppContext) -> Result<Vec<Box<dyn Initializer>>> {
46-
Ok(vec![Box::new(
47-
loco_openapi::OpenapiInitializerWithSetup::new(
48-
|ctx| {
49-
#[derive(OpenApi)]
50-
#[openapi(
51-
modifiers(&SecurityAddon),
52-
info(
53-
title = "Loco Demo",
54-
description = "This app is a kitchensink for various capabilities and examples of the [Loco](https://loco.rs) project."
55-
)
56-
)]
57-
struct ApiDoc;
58-
set_jwt_location_ctx(ctx);
45+
async fn initializers(ctx: &AppContext) -> Result<Vec<Box<dyn Initializer>>> {
46+
let mut initializers: Vec<Box<dyn Initializer>> = vec![];
47+
48+
if ctx.environment != Environment::Test {
49+
initializers.push(
50+
Box::new(
51+
loco_openapi::OpenapiInitializerWithSetup::new(
52+
|ctx| {
53+
#[derive(OpenApi)]
54+
#[openapi(
55+
modifiers(&SecurityAddon),
56+
info(
57+
title = "Loco Demo",
58+
description = "This app is a kitchensink for various capabilities and examples of the [Loco](https://loco.rs) project."
59+
)
60+
)]
61+
struct ApiDoc;
62+
set_jwt_location_ctx(ctx);
63+
64+
ApiDoc::openapi()
65+
},
66+
None,
67+
),
68+
) as Box<dyn Initializer>
69+
);
70+
}
5971

60-
ApiDoc::openapi()
61-
},
62-
None,
63-
),
64-
)])
72+
Ok(initializers)
6573
}
6674

6775
fn routes(_ctx: &AppContext) -> AppRoutes {
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
22
source: tests/models/users.rs
33
expression: res
4+
snapshot_kind: text
45
---
56
Err(
67
Custom(
7-
"{\"email\":[{\"code\":\"invalid email\",\"message\":null}],\"name\":[{\"code\":\"length\",\"message\":\"Name must be at least 2 characters long.\"}]}",
8+
"{\"email\":[{\"code\":\"email\",\"message\":\"invalid email\"}],\"name\":[{\"code\":\"length\",\"message\":\"Name must be at least 2 characters long.\"}]}",
89
),
910
)

0 commit comments

Comments
 (0)