release_checker/tests/register_origin_test.rs

116 lines
4.0 KiB
Rust

use serial_test::serial;
use test_context::test_context;
use application::configuration::{ArgumentParser, Settings, VcsType};
use application::console::Console;
use application::Application;
use test_utilities::notification::FakeNotification;
use test_utilities::{database::FunctionalTestContext, get_origin, get_origins_count};
#[test_context(FunctionalTestContext)]
#[test]
#[serial]
fn shoud_save_only_one_origin(context: &FunctionalTestContext) {
let parser = ArgumentParser {};
let console = Console {};
let fake_notification = FakeNotification { callback: || {} };
let settings = Settings::new(None).unwrap();
let arguments = vec![
String::from("release_checker"),
String::from("register"),
String::from("origin"),
String::from("github"),
String::from("name"),
String::from("owner_name"),
String::from("repo_name"),
];
let application = Application::new(&settings, &console, &fake_notification, parser, arguments);
application.run();
application.run();
let total_count_of_origins = get_origins_count(&settings.database.get_connection());
assert_eq!(1, total_count_of_origins);
}
#[test_context(FunctionalTestContext)]
#[test]
#[serial]
fn shoud_update_on_second_insert(context: &FunctionalTestContext) {
let parser = ArgumentParser {};
let console = Console {};
let fake_notification = FakeNotification { callback: || {} };
let settings = Settings::new(None).unwrap();
let arguments = vec![
String::from("release_checker"),
String::from("register"),
String::from("origin"),
String::from("github"),
String::from("name"),
String::from("owner_name"),
String::from("repo_name"),
];
let application = Application::new(&settings, &console, &fake_notification, parser, arguments);
let console = Console {};
let console = Console {};
application.run();
let total_count_of_origins = get_origins_count(&settings.database.get_connection());
let origin = get_origin(String::from("name"), &settings.database.get_connection());
assert_eq!(1, total_count_of_origins);
assert_eq!(origin.owner_name, "owner_name");
assert_eq!(origin.repo_name, "repo_name");
assert_eq!(origin.name, "name");
assert_eq!(origin.vcs_type, VcsType::Github);
let parser = ArgumentParser {};
let console = Console {};
let fake_notification = FakeNotification { callback: || {} };
let settings = Settings::new(None).unwrap();
let arguments = vec![
String::from("release_checker"),
String::from("register"),
String::from("origin"),
String::from("github"),
String::from("name"),
String::from("owner_name_updated"),
String::from("repo_name_updated"),
];
let application = Application::new(&settings, &console, &fake_notification, parser, arguments);
application.run();
let total_count_of_origins = get_origins_count(&settings.database.get_connection());
let origin = get_origin(String::from("name"), &settings.database.get_connection());
assert_eq!(1, total_count_of_origins);
assert_eq!(origin.repo_name, "repo_name_updated");
assert_eq!(origin.owner_name, "owner_name_updated");
assert_eq!(origin.name, "name");
assert_eq!(origin.vcs_type, VcsType::Github);
}
#[test_context(FunctionalTestContext)]
#[test]
#[serial]
fn should_route_to_origin(context: &FunctionalTestContext) {
let parser = ArgumentParser {};
let console = Console {};
let fake_notification = FakeNotification { callback: || {} };
let settings = Settings::new(None).unwrap();
let arguments = vec![
String::from("release_checker"),
String::from("register"),
String::from("origin"),
String::from("github"),
String::from("name"),
String::from("owner_name"),
String::from("repo_name"),
];
let application = Application::new(&settings, &console, &fake_notification, parser, arguments);
application.run();
}