-
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Björn Barwinski <[email protected]>
- Loading branch information
1 parent
e4251f2
commit 77e633c
Showing
4 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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,38 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
/// The payload in a [`super::EventPayload::WatchEvent`] type. | ||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | ||
#[non_exhaustive] | ||
pub struct WatchEventPayload { | ||
/// The action that was performed. | ||
pub action: WatchEventAction, | ||
} | ||
|
||
/// The action that was performed as part of the [`super::EventPayload::WatchEvent`]. | ||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] | ||
#[serde(rename_all = "snake_case")] | ||
#[non_exhaustive] | ||
pub enum WatchEventAction { | ||
Started, | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use crate::models::events::{ | ||
payload::{EventPayload, WatchEventAction}, | ||
Event, | ||
}; | ||
|
||
#[test] | ||
fn should_deserialize_with_correct_payload() { | ||
let json = include_str!("../../../../tests/resources/watch_event.json"); | ||
let event: Event = serde_json::from_str(json).unwrap(); | ||
if let Some(EventPayload::WatchEvent(ref payload)) = | ||
event.payload.as_ref().unwrap().specific | ||
{ | ||
assert_eq!(payload.action, WatchEventAction::Started); | ||
} else { | ||
panic!("unexpected event payload encountered: {:#?}", event.payload); | ||
} | ||
} | ||
} |
This file contains 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,22 @@ | ||
{ | ||
"id": "31123637655", | ||
"type": "WatchEvent", | ||
"actor": { | ||
"id": 94867353, | ||
"login": "octocat", | ||
"display_login": "octocat", | ||
"gravatar_id": "", | ||
"url": "https://api.github.com/users/octocat", | ||
"avatar_url": "https://avatars.githubusercontent.com/u/94867353?v=4" | ||
}, | ||
"repo": { | ||
"id": 316335970, | ||
"name": "wayofthepie/test-events", | ||
"url": "https://api.github.com/repos/wayofthepie/test-events" | ||
}, | ||
"public": true, | ||
"created_at": "2023-10-01T07:54:09Z", | ||
"payload": { | ||
"action": "started" | ||
} | ||
} |