Skip to content

Commit f63822b

Browse files
committed
Create proper config for integration tests
1 parent 0c0ae11 commit f63822b

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

src/domain/models/week.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub(crate) struct WeekNumber(u8);

tests/integration/cli.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
use crate::helpers::maconomy_mock::{
2-
mock_add_row, mock_get_instance, mock_get_table_rows, mock_job_number_search, mock_set_hours,
3-
mock_tasks_search,
1+
use crate::helpers::{
2+
config::create_test_config,
3+
maconomy_mock::{
4+
mock_add_row, mock_get_instance, mock_get_table_rows, mock_job_number_search,
5+
mock_set_hours, mock_tasks_search,
6+
},
47
};
58
use assert_cmd::{assert::OutputAssertExt, Command};
69
use std::{env, ffi};
710
use wiremock::MockServer;
811

9-
const COOKIE_PATH: &str = "tests/integration/helpers/integration_test_maconomy_cookie";
10-
1112
fn run_json(
1213
args: impl IntoIterator<Item = impl AsRef<ffi::OsStr>>,
1314
server_url: &str,
@@ -25,18 +26,14 @@ fn run(
2526
// output.stdout.into_output().to_string()
2627
}
2728

28-
fn use_mock_auth_cookie_file() {
29-
env::set_var("MACONOMY__AUTHENTICATION__SSO__COOKIE_PATH", COOKIE_PATH);
30-
}
31-
3229
#[tokio::main]
3330
#[test]
3431
async fn test_get_timesheet() {
3532
// Given
3633
let mock_server = MockServer::start().await;
3734
mock_get_instance(None).mount(&mock_server).await;
3835
mock_get_table_rows(None).mount(&mock_server).await;
39-
use_mock_auth_cookie_file();
36+
create_test_config();
4037

4138
let expected = serde_json::json!({
4239
"lines": [
@@ -91,7 +88,7 @@ async fn test_set_hours() {
9188
// mock_tasks_search(None).mount(&mock_server).await;
9289
mock_add_row(None).mount(&mock_server).await;
9390
mock_set_hours(None).mount(&mock_server).await;
94-
use_mock_auth_cookie_file();
91+
create_test_config();
9592

9693
// When
9794
let output = run(
@@ -125,7 +122,7 @@ async fn test_set_hours_err() {
125122
mock_set_hours(None).mount(&mock_server).await;
126123
mock_tasks_search(None).mount(&mock_server).await;
127124
mock_add_row(None).mount(&mock_server).await;
128-
use_mock_auth_cookie_file();
125+
create_test_config();
129126

130127
// When
131128
let output = run(
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const CONFIG: &[(&str, &str)] = &[
2+
("COMPANY_ID", "company123"),
3+
("AUTHENTICATION__SSO__LOGIN_URL", "https://some.website.com"),
4+
(
5+
"AUTHENTICATION__SSO__COOKIE_PATH",
6+
"tests/integration/helpers/integration_test_maconomy_cookie",
7+
),
8+
// `MACONOMY_URL` is set by the tests (from mock URL)
9+
];
10+
11+
pub(crate) fn create_test_config() {
12+
for (key, value) in CONFIG {
13+
std::env::set_var(format!("MACONOMY__{key}"), value);
14+
}
15+
}

tests/integration/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
mod cli;
22
mod helpers {
3+
pub(crate) mod config;
34
pub(crate) mod maconomy_mock;
45
pub(crate) mod mock_data;
56
}

0 commit comments

Comments
 (0)