-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add extensions field to AppState (#131)
* added extensions field to AppState, including testing * resolved suggestions Norlock * resolved comments, moved extension testcode to unime/src-tauri/tests * move import to dev-dependencies, remove accidental binding * cargo fmt * deleted png and svg files
- Loading branch information
Showing
17 changed files
with
192 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,21 @@ | ||
use identity_wallet::{ | ||
reducer, | ||
state::{actions::ActionTrait, reducers::Reducer}, | ||
}; | ||
|
||
use crate::common::extensions::reducers::test_feat_state; | ||
|
||
/// Action to test the extension field. | ||
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] | ||
pub struct CustomExtensionTest { | ||
pub test_term: Option<String>, | ||
#[serde(default)] | ||
pub test_bool: bool, | ||
} | ||
|
||
#[typetag::serde(name = "[Test] Test")] | ||
impl ActionTrait for CustomExtensionTest { | ||
fn reducers<'a>(&self) -> Vec<Reducer<'a>> { | ||
vec![reducer!(test_feat_state)] | ||
} | ||
} |
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,15 @@ | ||
use identity_wallet::state::FeatTrait; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
pub mod actions; | ||
pub mod reducers; | ||
|
||
// This module is soly for testing and demonstrating the extension system. | ||
#[derive(Debug, Serialize, Deserialize, PartialEq, Default, Clone)] | ||
pub struct CustomExtension { | ||
pub name: String, | ||
pub value: String, | ||
} | ||
|
||
#[typetag::serde(name = "custom_extension")] | ||
impl FeatTrait for CustomExtension {} |
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,27 @@ | ||
use identity_wallet::error::AppError; | ||
use identity_wallet::state::actions::{listen, Action}; | ||
use identity_wallet::state::AppState; | ||
|
||
use super::actions::CustomExtensionTest; | ||
use super::CustomExtension; | ||
|
||
pub async fn test_feat_state(state: AppState, action: Action) -> Result<AppState, AppError> { | ||
if let Some(test_feat_state) = listen::<CustomExtensionTest>(action) { | ||
let mut new_state = state; | ||
|
||
new_state.extensions.insert( | ||
"test".to_string(), | ||
Box::new(CustomExtension { | ||
name: "new".to_string(), | ||
value: if test_feat_state.test_bool { | ||
"new".to_string() | ||
} else { | ||
"old".to_string() | ||
}, | ||
}), | ||
); | ||
|
||
return Ok(new_state); | ||
} | ||
Ok(state) | ||
} |
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,7 @@ | ||
{ | ||
"type": "[Test] Test", | ||
"payload": { | ||
"test_term": "test", | ||
"test_bool": true | ||
} | ||
} |
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,9 @@ | ||
{ | ||
"extensions": { | ||
"test": { | ||
"feat_state_type": "custom_extension", | ||
"name": "new", | ||
"value": "new" | ||
} | ||
} | ||
} |
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,43 @@ | ||
use crate::common::assert_state_update::{assert_state_update, setup_state_file, setup_stronghold}; | ||
use crate::common::extensions::CustomExtension; | ||
use crate::common::json_example; | ||
use identity_wallet::state::AppStateContainer; | ||
use identity_wallet::state::{actions::Action, AppState}; | ||
|
||
#[tokio::test] | ||
#[serial_test::serial] | ||
async fn test_extension() { | ||
setup_state_file(); | ||
setup_stronghold(); | ||
|
||
// Deserializing the AppStates and Actions from the accompanying json files. | ||
let state = AppStateContainer::default() | ||
.insert_extension( | ||
"test", | ||
Box::new(CustomExtension { | ||
name: "test".to_string(), | ||
value: "test".to_string(), | ||
}), | ||
) | ||
.await; | ||
let state2 = json_example::<AppState>("tests/fixtures/states/test_extension.json"); | ||
let action1 = json_example::<Action>("tests/fixtures/actions/test_extension.json"); | ||
|
||
dbg!(&state); | ||
dbg!(&state2); | ||
dbg!(&action1); | ||
|
||
assert_state_update( | ||
// Initial state. | ||
state, | ||
vec![ | ||
// Test action | ||
action1, | ||
], | ||
vec![ | ||
// state including CustomExtension | ||
Some(state2), | ||
], | ||
) | ||
.await; | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
mod credential_offer; | ||
mod extensions; | ||
mod get_state; | ||
mod load_dev_profile; | ||
mod qr_code_scanned; | ||
|