Skip to content

Commit

Permalink
test: testing welds feature
Browse files Browse the repository at this point in the history
  • Loading branch information
NexRX committed Dec 21, 2023
1 parent 29d3b3f commit 71e0b54
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tests/feature_testing/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#[cfg(feature = "openapi")]
mod openapi;
#[cfg(feature = "builder")]
mod builder;
mod builder;
#[cfg(feature = "welds")]
mod welds;
48 changes: 48 additions & 0 deletions tests/feature_testing/welds.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use restructed::Models;
use welds::state::DbState;

#[derive(Models, Clone, PartialEq, Eq, Debug)]
#[patch(UserUpdatables, omit(id), default_derives = true)]
#[view(UserId, fields(id))]
struct User {
id: i32,
display_name: String,
bio: String,
password: String,
}

impl User {
pub fn new() -> Self {
User {
id: 123,
display_name: "Cool Doode".to_string(),
bio: "I'm a cool doode, what can I say?".to_string(),
password: "Pls don't hack me".to_string(),
}
}
}

#[test]
fn can_build() {
let user = User::new();

let id = UserId::builder()
.id(user.id)
.build();
assert_eq!(&id.id, &user.id);

let patch = UserUpdatables::builder()
.display_name(Some("Cooler doode".to_string()))
.bio(None)
.password(Some("Can't hack 'dis".to_string()))
.build();

let mut state = DbState::new_uncreated(user.clone());
patch.merge_weld_mut(&mut state);


assert_ne!(*state, user);
assert_eq!(*state.display_name, "Cooler doode".to_string());
assert_eq!(*state.bio, "I'm a cool doode, what can I say?".to_string());
assert_eq!(*state.password, "Can't hack 'dis".to_string());
}

0 comments on commit 71e0b54

Please sign in to comment.