@@ -5,9 +5,11 @@ use chrono::Utc;
|
||||
use forage_core::auth::*;
|
||||
use forage_core::platform::{
|
||||
Artifact, ArtifactContext, CreatePolicyInput, CreateReleasePipelineInput, CreateTriggerInput,
|
||||
Destination, Environment, ForestPlatform, Organisation, OrgMember, PlatformError, Policy,
|
||||
ReleasePipeline, Trigger, UpdatePolicyInput, UpdateReleasePipelineInput, UpdateTriggerInput,
|
||||
Destination, Environment, ForestPlatform, NotificationPreference, Organisation, OrgMember,
|
||||
PlatformError, Policy, ReleasePipeline, Trigger, UpdatePolicyInput, UpdateReleasePipelineInput,
|
||||
UpdateTriggerInput,
|
||||
};
|
||||
use forage_core::integrations::InMemoryIntegrationStore;
|
||||
use forage_core::session::{
|
||||
CachedOrg, CachedUser, InMemorySessionStore, SessionData, SessionStore,
|
||||
};
|
||||
@@ -53,6 +55,9 @@ pub(crate) struct MockPlatformBehavior {
|
||||
pub create_release_pipeline_result: Option<Result<ReleasePipeline, PlatformError>>,
|
||||
pub update_release_pipeline_result: Option<Result<ReleasePipeline, PlatformError>>,
|
||||
pub delete_release_pipeline_result: Option<Result<(), PlatformError>>,
|
||||
pub get_artifact_spec_result: Option<Result<String, PlatformError>>,
|
||||
pub get_notification_preferences_result: Option<Result<Vec<NotificationPreference>, PlatformError>>,
|
||||
pub set_notification_preference_result: Option<Result<(), PlatformError>>,
|
||||
}
|
||||
|
||||
pub(crate) fn ok_tokens() -> AuthTokens {
|
||||
@@ -675,6 +680,40 @@ impl ForestPlatform for MockPlatformClient {
|
||||
let b = self.behavior.lock().unwrap();
|
||||
b.delete_release_pipeline_result.clone().unwrap_or(Ok(()))
|
||||
}
|
||||
|
||||
async fn get_artifact_spec(
|
||||
&self,
|
||||
_access_token: &str,
|
||||
_artifact_id: &str,
|
||||
) -> Result<String, PlatformError> {
|
||||
let b = self.behavior.lock().unwrap();
|
||||
b.get_artifact_spec_result
|
||||
.clone()
|
||||
.unwrap_or(Ok(String::new()))
|
||||
}
|
||||
|
||||
async fn get_notification_preferences(
|
||||
&self,
|
||||
_access_token: &str,
|
||||
) -> Result<Vec<NotificationPreference>, PlatformError> {
|
||||
let b = self.behavior.lock().unwrap();
|
||||
b.get_notification_preferences_result
|
||||
.clone()
|
||||
.unwrap_or(Ok(Vec::new()))
|
||||
}
|
||||
|
||||
async fn set_notification_preference(
|
||||
&self,
|
||||
_access_token: &str,
|
||||
_notification_type: &str,
|
||||
_channel: &str,
|
||||
_enabled: bool,
|
||||
) -> Result<(), PlatformError> {
|
||||
let b = self.behavior.lock().unwrap();
|
||||
b.set_notification_preference_result
|
||||
.clone()
|
||||
.unwrap_or(Ok(()))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn make_templates() -> TemplateEngine {
|
||||
@@ -705,6 +744,22 @@ pub(crate) fn test_state_with(
|
||||
(state, sessions)
|
||||
}
|
||||
|
||||
pub(crate) fn test_state_with_integrations(
|
||||
mock: MockForestClient,
|
||||
platform: MockPlatformClient,
|
||||
) -> (AppState, Arc<InMemorySessionStore>, Arc<InMemoryIntegrationStore>) {
|
||||
let sessions = Arc::new(InMemorySessionStore::new());
|
||||
let integrations = Arc::new(InMemoryIntegrationStore::new());
|
||||
let state = AppState::new(
|
||||
make_templates(),
|
||||
Arc::new(mock),
|
||||
Arc::new(platform),
|
||||
sessions.clone(),
|
||||
)
|
||||
.with_integration_store(integrations.clone());
|
||||
(state, sessions, integrations)
|
||||
}
|
||||
|
||||
pub(crate) fn test_app() -> Router {
|
||||
let (state, _) = test_state();
|
||||
crate::build_router(state)
|
||||
|
||||
Reference in New Issue
Block a user