Skip to content

Commit

Permalink
Create proper config for integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mawkler committed Nov 12, 2024
1 parent 0c0ae11 commit f63822b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
1 change: 1 addition & 0 deletions src/domain/models/week.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) struct WeekNumber(u8);
21 changes: 9 additions & 12 deletions tests/integration/cli.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
use crate::helpers::maconomy_mock::{
mock_add_row, mock_get_instance, mock_get_table_rows, mock_job_number_search, mock_set_hours,
mock_tasks_search,
use crate::helpers::{
config::create_test_config,
maconomy_mock::{
mock_add_row, mock_get_instance, mock_get_table_rows, mock_job_number_search,
mock_set_hours, mock_tasks_search,
},
};
use assert_cmd::{assert::OutputAssertExt, Command};
use std::{env, ffi};
use wiremock::MockServer;

const COOKIE_PATH: &str = "tests/integration/helpers/integration_test_maconomy_cookie";

fn run_json(
args: impl IntoIterator<Item = impl AsRef<ffi::OsStr>>,
server_url: &str,
Expand All @@ -25,18 +26,14 @@ fn run(
// output.stdout.into_output().to_string()
}

fn use_mock_auth_cookie_file() {
env::set_var("MACONOMY__AUTHENTICATION__SSO__COOKIE_PATH", COOKIE_PATH);
}

#[tokio::main]
#[test]
async fn test_get_timesheet() {
// Given
let mock_server = MockServer::start().await;
mock_get_instance(None).mount(&mock_server).await;
mock_get_table_rows(None).mount(&mock_server).await;
use_mock_auth_cookie_file();
create_test_config();

let expected = serde_json::json!({
"lines": [
Expand Down Expand Up @@ -91,7 +88,7 @@ async fn test_set_hours() {
// mock_tasks_search(None).mount(&mock_server).await;
mock_add_row(None).mount(&mock_server).await;
mock_set_hours(None).mount(&mock_server).await;
use_mock_auth_cookie_file();
create_test_config();

// When
let output = run(
Expand Down Expand Up @@ -125,7 +122,7 @@ async fn test_set_hours_err() {
mock_set_hours(None).mount(&mock_server).await;
mock_tasks_search(None).mount(&mock_server).await;
mock_add_row(None).mount(&mock_server).await;
use_mock_auth_cookie_file();
create_test_config();

// When
let output = run(
Expand Down
15 changes: 15 additions & 0 deletions tests/integration/helpers/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const CONFIG: &[(&str, &str)] = &[
("COMPANY_ID", "company123"),
("AUTHENTICATION__SSO__LOGIN_URL", "https://some.website.com"),
(
"AUTHENTICATION__SSO__COOKIE_PATH",
"tests/integration/helpers/integration_test_maconomy_cookie",
),
// `MACONOMY_URL` is set by the tests (from mock URL)
];

pub(crate) fn create_test_config() {
for (key, value) in CONFIG {
std::env::set_var(format!("MACONOMY__{key}"), value);
}
}
1 change: 1 addition & 0 deletions tests/integration/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod cli;
mod helpers {
pub(crate) mod config;
pub(crate) mod maconomy_mock;
pub(crate) mod mock_data;
}

0 comments on commit f63822b

Please sign in to comment.