Add unit tests
This commit is contained in:
@ -5,6 +5,7 @@ use crate::{Context, Error};
|
||||
|
||||
/// Configure whether other users can set reminders to your direct messages
|
||||
#[poise::command(slash_command, rename = "dm")]
|
||||
#[cfg(not(test))]
|
||||
pub async fn allowed_dm(_ctx: Context<'_>) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ impl Recordable for Options {
|
||||
|
||||
/// Allow other users to set reminders in your direct messages
|
||||
#[poise::command(slash_command, rename = "allow", identifying_name = "set_allowed_dm")]
|
||||
#[cfg(not(test))]
|
||||
pub async fn set(ctx: Context<'_>) -> Result<(), Error> {
|
||||
(Options {}).run(ctx).await
|
||||
}
|
||||
|
@ -31,6 +31,48 @@ impl Recordable for Options {
|
||||
|
||||
/// Get the link to the web dashboard
|
||||
#[poise::command(slash_command, rename = "dashboard", identifying_name = "dashboard")]
|
||||
#[cfg(not(test))]
|
||||
pub async fn command(ctx: Context<'_>) -> Result<(), Error> {
|
||||
(Options {}).run(ctx).await
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::env;
|
||||
|
||||
use sqlx::Pool;
|
||||
use tokio::sync::{broadcast, Mutex};
|
||||
|
||||
use crate::{
|
||||
commands::dashboard::Options,
|
||||
test::{MockCache, TestContext, TestData},
|
||||
utils::Recordable,
|
||||
Data,
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn dashboard_command() {
|
||||
let (tx, _rx) = broadcast::channel(16);
|
||||
let database = Pool::connect(&env::var("DATABASE_URL").expect("No database URL provided"))
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let ctx = TestContext {
|
||||
data: &Data { database, popular_timezones: vec![], _broadcast: tx },
|
||||
cache: &MockCache {},
|
||||
test_data: &Mutex::new(TestData { replies: vec![] }),
|
||||
shard_id: 0,
|
||||
};
|
||||
|
||||
let res = (Options {}).run(ctx).await;
|
||||
|
||||
assert!(res.is_ok(), "command OK");
|
||||
assert_eq!(ctx.test_data.lock().await.replies.len(), 1, "one message sent");
|
||||
assert!(
|
||||
ctx.sent_content()
|
||||
.await
|
||||
.contains(&String::from("**https://beta.reminder-bot.com/dashboard**")),
|
||||
"content correct"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,21 +1,41 @@
|
||||
#[cfg(not(test))]
|
||||
pub mod allowed_dm;
|
||||
#[cfg(not(test))]
|
||||
mod autocomplete;
|
||||
#[cfg(not(test))]
|
||||
pub mod clock;
|
||||
#[cfg(not(test))]
|
||||
pub mod clock_context_menu;
|
||||
#[cfg(not(test))]
|
||||
pub mod command_macro;
|
||||
pub mod dashboard;
|
||||
#[cfg(not(test))]
|
||||
pub mod delete;
|
||||
#[cfg(not(test))]
|
||||
pub mod donate;
|
||||
#[cfg(not(test))]
|
||||
pub mod help;
|
||||
#[cfg(not(test))]
|
||||
pub mod info;
|
||||
#[cfg(not(test))]
|
||||
pub mod look;
|
||||
#[cfg(not(test))]
|
||||
pub mod multiline;
|
||||
#[cfg(not(test))]
|
||||
pub mod nudge;
|
||||
#[cfg(not(test))]
|
||||
pub mod offset;
|
||||
#[cfg(not(test))]
|
||||
pub mod pause;
|
||||
#[cfg(not(test))]
|
||||
pub mod remind;
|
||||
#[cfg(not(test))]
|
||||
pub mod settings;
|
||||
#[cfg(not(test))]
|
||||
pub mod timer;
|
||||
#[cfg(not(test))]
|
||||
pub mod timezone;
|
||||
#[cfg(not(test))]
|
||||
pub mod todo;
|
||||
#[cfg(not(test))]
|
||||
pub mod webhook;
|
||||
|
Reference in New Issue
Block a user