From 975c9e315ce2a59ebb6742a0b1e42c1716dcec8c Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 30 Jun 2024 08:09:10 +0100 Subject: [PATCH] fix: where repo config is in server should register webhook --- crates/repo-actor/README.md | 1 + crates/repo-actor/src/handlers/clone_repo.rs | 5 ++ .../src/tests/handlers/clone_repo.rs | 50 +++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/crates/repo-actor/README.md b/crates/repo-actor/README.md index 18c2b8e..2fddd0b 100644 --- a/crates/repo-actor/README.md +++ b/crates/repo-actor/README.md @@ -4,6 +4,7 @@ stateDiagram-v2 CloneRepo --> LoadConfigFromRepo :on repo config CloneRepo --> ValidateRepo :on server config +CloneRepo --> RegisterWebhook :on server config LoadConfigFromRepo --> ReceiveRepoConfig diff --git a/crates/repo-actor/src/handlers/clone_repo.rs b/crates/repo-actor/src/handlers/clone_repo.rs index 752300e..a5ff362 100644 --- a/crates/repo-actor/src/handlers/clone_repo.rs +++ b/crates/repo-actor/src/handlers/clone_repo.rs @@ -27,6 +27,11 @@ impl Handler for actor::RepoActor { &self.log, ); } else { + actor::do_send( + ctx.address(), + actor::messages::RegisterWebhook::new(), + &self.log, + ); actor::do_send( ctx.address(), actor::messages::ValidateRepo::new(self.message_token), diff --git a/crates/repo-actor/src/tests/handlers/clone_repo.rs b/crates/repo-actor/src/tests/handlers/clone_repo.rs index 6d80dc9..d61258a 100644 --- a/crates/repo-actor/src/tests/handlers/clone_repo.rs +++ b/crates/repo-actor/src/tests/handlers/clone_repo.rs @@ -105,6 +105,56 @@ async fn when_server_has_no_repo_config_should_send_load_from_repo() -> TestResu Ok(()) } +/// The server config can optionally include the names of the main, next and dev +/// branches. When it does we should go straight to sending a [ValidateRepo] message. +#[actix::test] +async fn when_server_has_repo_config_should_send_validate_repo() -> TestResult { + //given + let fs = given::a_filesystem(); + let (mut open_repository, repo_details) = given::an_open_repository(&fs); + #[allow(clippy::unwrap_used)] + given::has_all_valid_remote_defaults(&mut open_repository, &repo_details); + + let mut repository_factory = MockRepositoryFactory::new(); + expect::open_repository(&mut repository_factory, open_repository); + fs.dir_create(&repo_details.gitdir)?; + + //when + let (addr, log) = when::start_actor(repository_factory, repo_details, given::a_forge()); + addr.send(CloneRepo::new()).await?; + System::current().stop(); + + //then + log.require_message_containing("send: ValidateRepo")?; + + Ok(()) +} + +/// The server config can optionally include the names of the main, next and dev +/// branches. When it does we should register the webhook by sending [RegisterWebhook] message. +#[actix::test] +async fn when_server_has_repo_config_should_send_register_webhook() -> TestResult { + //given + let fs = given::a_filesystem(); + let (mut open_repository, repo_details) = given::an_open_repository(&fs); + #[allow(clippy::unwrap_used)] + given::has_all_valid_remote_defaults(&mut open_repository, &repo_details); + + let mut repository_factory = MockRepositoryFactory::new(); + expect::open_repository(&mut repository_factory, open_repository); + fs.dir_create(&repo_details.gitdir)?; + + //when + let (addr, log) = when::start_actor(repository_factory, repo_details, given::a_forge()); + addr.send(CloneRepo::new()).await?; + System::current().stop(); + + //then + log.require_message_containing("send: RegisterWebhook")?; + + Ok(()) +} + #[test_log::test(actix::test)] async fn opened_repo_with_no_default_push_should_not_proceed() -> TestResult { //given