-
-
Notifications
You must be signed in to change notification settings - Fork 21
Implement the missed test case from codecov #3005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
bitfriend
merged 24 commits into
acterglobal:main
from
bitfriend:activate-integration-test
May 26, 2025
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
a6eea79
Implement the missed test case from codecov
bitfriend aecb96b
Implement the missed test case from codecov
bitfriend 594244d
Implement the missed test case from codecov
bitfriend 67cef6f
Merge remote-tracking branch 'upstream/main' into activate-integratio…
bitfriend 49473a4
Fix lint error from git workflow
bitfriend 6f455bd
Implement the missed test case from codecov
bitfriend d818fee
Fix lint error from git workflow
bitfriend ce350bb
Implement the missed test case from codecov
bitfriend ac07611
Implement the missed test case from codecov
bitfriend fa93ac0
Merge remote-tracking branch 'upstream/main' into activate-integratio…
bitfriend f934802
Implement the missed test case from codecov
bitfriend 7dc67c0
Implement the missed test case from codecov
bitfriend 9bfb4bf
Room::room_type() can be replaced with RoomPreview::state_str()
bitfriend 56e92fb
Implement the missed test case from codecov
bitfriend 4589d78
Refactory directory structure of rust test
bitfriend d05c115
Merge remote-tracking branch 'upstream/main' into activate-integratio…
bitfriend 6247fdb
Implement the missed test case from codecov
bitfriend 068505d
Refactor some fns
bitfriend 33b0f88
Fix typo
bitfriend 4b54e57
Refactor code
bitfriend 2d64592
Remove the incorrect comment because timeline doesn't work on space
bitfriend 4ff9ba9
Add event waiting code to fix the intermittent failure in message red…
bitfriend 2c274fd
Don't expose API for comment update for now because its UI is not ready
bitfriend cf3e911
Merge remote-tracking branch 'upstream/main' into activate-integratio…
bitfriend File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
use acter::ActerModel; | ||
use anyhow::{bail, Result}; | ||
use std::{env, io::Write}; | ||
use tempfile::NamedTempFile; | ||
use tokio_retry::{ | ||
strategy::{jitter, FibonacciBackoff}, | ||
Retry, | ||
}; | ||
|
||
use crate::utils::random_user_with_template; | ||
|
||
const TMPL: &str = r#" | ||
version = "0.1" | ||
name = "Smoketest Template" | ||
|
||
[inputs] | ||
main = { type = "user", is-default = true, required = true, description = "The starting user" } | ||
|
||
[objects] | ||
main_space = { type = "space", is-default = true, name = "{{ main.display_name }}’s pins test space" } | ||
|
||
[objects.acter-website-pin] | ||
type = "pin" | ||
title = "Acter Website" | ||
url = "https://acter.global" | ||
|
||
[objects.acter-source-pin] | ||
type = "pin" | ||
title = "Acter Source Code" | ||
url = "https://github.com/acterglobal/a3" | ||
|
||
[objects.example-data-pin] | ||
type = "pin" | ||
title = "Acter example pin" | ||
content = { body = "example pin data" } | ||
"#; | ||
|
||
#[tokio::test] | ||
async fn attachment_can_redact() -> Result<()> { | ||
let _ = env_logger::try_init(); | ||
let (user, sync_state, _engine) = | ||
random_user_with_template("attachment_can_redact", TMPL).await?; | ||
sync_state.await_has_synced_history().await?; | ||
|
||
let retry_strategy = FibonacciBackoff::from_millis(100).map(jitter).take(10); | ||
let fetcher_client = user.clone(); | ||
Retry::spawn(retry_strategy, move || { | ||
let client = fetcher_client.clone(); | ||
async move { | ||
if client.pins().await?.len() != 3 { | ||
bail!("not all pins found"); | ||
} | ||
Ok(()) | ||
} | ||
}) | ||
.await?; | ||
|
||
let pin = user | ||
.pins() | ||
.await? | ||
.into_iter() | ||
.find(|p| !p.is_link()) | ||
.expect("we’ve created one non-link pin"); | ||
|
||
// START actual attachment on pin | ||
|
||
let attachments_manager = pin.attachments().await?; | ||
assert!(!attachments_manager.stats().has_attachments()); | ||
|
||
// ---- let’s make a attachment | ||
|
||
let bytes = include_bytes!("./fixtures/kingfisher.jpg"); | ||
let mut jpg_file = NamedTempFile::new()?; | ||
jpg_file.as_file_mut().write_all(bytes)?; | ||
|
||
let attachments_listener = attachments_manager.subscribe(); | ||
let base_draft = user.image_draft( | ||
jpg_file.path().to_string_lossy().to_string(), | ||
"image/jpeg".to_owned(), | ||
); | ||
let attachment_id = attachments_manager | ||
.content_draft(Box::new(base_draft)) | ||
.await? | ||
.send() | ||
.await?; | ||
|
||
let retry_strategy = FibonacciBackoff::from_millis(500).map(jitter).take(10); | ||
Retry::spawn(retry_strategy.clone(), || async { | ||
if attachments_listener.is_empty() { | ||
bail!("all still empty"); | ||
} | ||
Ok(()) | ||
}) | ||
.await?; | ||
|
||
let attachments = attachments_manager.attachments().await?; | ||
assert_eq!(attachments.len(), 1); | ||
let attachment = attachments | ||
.first() | ||
.expect("first attachment should be available"); | ||
assert_eq!(attachment.event_id(), attachment_id); | ||
assert_eq!(attachment.type_str(), "image"); | ||
let deletable = attachment.can_redact().await?; | ||
assert!(deletable, "my attachment should be deletable"); | ||
|
||
Ok(()) | ||
} | ||
|
||
#[tokio::test] | ||
async fn attachment_download_media() -> Result<()> { | ||
let _ = env_logger::try_init(); | ||
let (user, sync_state, _engine) = | ||
random_user_with_template("attachment_download_media", TMPL).await?; | ||
sync_state.await_has_synced_history().await?; | ||
|
||
let retry_strategy = FibonacciBackoff::from_millis(100).map(jitter).take(10); | ||
let fetcher_client = user.clone(); | ||
Retry::spawn(retry_strategy, move || { | ||
let client = fetcher_client.clone(); | ||
async move { | ||
if client.pins().await?.len() != 3 { | ||
bail!("not all pins found"); | ||
} | ||
Ok(()) | ||
} | ||
}) | ||
.await?; | ||
|
||
let pin = user | ||
.pins() | ||
.await? | ||
.into_iter() | ||
.find(|p| !p.is_link()) | ||
.expect("we’ve created one non-link pin"); | ||
|
||
// START actual attachment on pin | ||
|
||
let attachments_manager = pin.attachments().await?; | ||
assert!(!attachments_manager.stats().has_attachments()); | ||
|
||
// ---- let’s make a attachment | ||
|
||
let bytes = include_bytes!("./fixtures/kingfisher.jpg"); | ||
let mut jpg_file = NamedTempFile::new()?; | ||
jpg_file.as_file_mut().write_all(bytes)?; | ||
|
||
let attachments_listener = attachments_manager.subscribe(); | ||
let base_draft = user.image_draft( | ||
jpg_file.path().to_string_lossy().to_string(), | ||
"image/jpeg".to_owned(), | ||
); | ||
let attachment_id = attachments_manager | ||
.content_draft(Box::new(base_draft)) | ||
.await? | ||
.send() | ||
.await?; | ||
|
||
let retry_strategy = FibonacciBackoff::from_millis(500).map(jitter).take(10); | ||
Retry::spawn(retry_strategy.clone(), || async { | ||
if attachments_listener.is_empty() { | ||
bail!("all still empty"); | ||
} | ||
Ok(()) | ||
}) | ||
.await?; | ||
|
||
let attachments = attachments_manager.attachments().await?; | ||
assert_eq!(attachments.len(), 1); | ||
let attachment = attachments | ||
.first() | ||
.expect("first attachment should be available"); | ||
assert_eq!(attachment.event_id(), attachment_id); | ||
assert_eq!(attachment.type_str(), "image"); | ||
|
||
let dir_path = env::temp_dir().to_string_lossy().to_string(); | ||
let downloaded_path = attachment.download_media(None, dir_path).await?; | ||
assert!( | ||
downloaded_path.text().is_some(), | ||
"my attachment should be downloadable" | ||
); | ||
|
||
let media_path = attachment.media_path(false).await?; | ||
assert!( | ||
media_path.text().is_some(), | ||
"media path should be accessible if it was downloaded once" | ||
); | ||
|
||
Ok(()) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍