1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use activitystreams_vocabulary::create_activity;
create_activity! {
/// Indicates that a [Ticket](crate::Ticket) is being assigned to a [Person](activitystreams_vocabulary::Person) or [Team](crate::Team).
///
/// # Example
///
/// ```rust
/// use activityforge::{Assign, context};
/// use activitystreams_vocabulary::Iri;
///
/// # fn main() {
/// let id = Iri::try_from("https://example.dev/aviva/myproject/outbox/reBGo").unwrap();
/// let object = Iri::try_from("https://example.dev/aviva/myproject/issues/1").unwrap();
/// let to0 = Iri::try_from("https://example.dev/bob").unwrap();
///
/// let json_str = format!(
/// r#"{{
/// "@context": [
/// "https://www.w3.org/ns/activitystreams",
/// "https://forgefed.org/ns"
/// ],
/// "type": "Assign",
/// "id": "{id}",
/// "to": [
/// "{to0}"
/// ],
/// "object": "{object}"
/// }}"#
/// );
///
/// let context_property = context::forgefed_context();
///
/// let assign = Assign::new()
/// .with_context_property(context_property)
/// .with_id(id)
/// .with_to([to0])
/// .with_object(object);
///
/// assert_eq!(serde_json::to_string_pretty(&assign).unwrap(), json_str);
/// assert_eq!(
/// serde_json::from_str::<Assign>(json_str.as_str()).unwrap(),
/// assign
/// );
/// # }
/// ```
Assign: crate::ActivityType::Assign {}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::context;
use activitystreams_vocabulary::Iri;
#[test]
fn test_assign() {
let id = Iri::try_from("https://example.dev/aviva/myproject/outbox/reBGo").unwrap();
let object = Iri::try_from("https://example.dev/aviva/myproject/issues/1").unwrap();
let to0 = Iri::try_from("https://example.dev/bob").unwrap();
let json_str = format!(
r#"{{
"@context": [
"https://www.w3.org/ns/activitystreams",
"https://forgefed.org/ns"
],
"type": "Assign",
"id": "{id}",
"to": [
"{to0}"
],
"object": "{object}"
}}"#
);
let context_property = context::forgefed_context();
let assign = Assign::new()
.with_context_property(context_property)
.with_id(id)
.with_to([to0])
.with_object(object);
assert_eq!(serde_json::to_string_pretty(&assign).unwrap(), json_str);
assert_eq!(
serde_json::from_str::<Assign>(json_str.as_str()).unwrap(),
assign
);
}
}