Prepping account members for enriching user data.

This commit is contained in:
2026-10-12 13:43:43 +02:00
parent d2993eafe0
commit 945ae46dbe
7 changed files with 154 additions and 29 deletions
+18 -13
View File
@@ -33,11 +33,11 @@ pub struct AccountMemberResponse {
pub user: UserResponse,
}
impl From<domain::AccountMember> for AccountMemberResponse {
fn from(member: domain::AccountMember) -> Self {
impl AccountMemberResponse {
pub fn from_domain(member: domain::AccountMember, user: domain::User) -> Self {
Self {
id: member.id,
user: UserResponse { id: member.user_id },
user: UserResponse { id: user.id },
}
}
}
@@ -57,13 +57,21 @@ mod tests {
}
}
fn response(id: Uuid, user: domain::User) -> AccountMemberResponse {
AccountMemberResponse {
id,
user: UserResponse { id: user.id },
}
}
fn user() -> domain::User {
domain::User { id: Uuid::nil() }
}
#[test]
fn serializes_account_member_response() {
let id = Uuid::new_v4();
let member = request(Uuid::nil())
.into_domain(id, Uuid::new_v4())
.unwrap();
let response = serde_json::to_value(AccountMemberResponse::from(member)).unwrap();
let response = serde_json::to_value(response(id, user())).unwrap();
assert_eq!(response["id"], id.to_string());
assert_eq!(response["user"]["id"], Uuid::nil().to_string());
@@ -72,10 +80,7 @@ mod tests {
#[test]
fn deserializes_account_member_response_as_request() {
let member = request(Uuid::nil())
.into_domain(Uuid::new_v4(), Uuid::new_v4())
.unwrap();
let response = serde_json::to_value(AccountMemberResponse::from(member)).unwrap();
let response = serde_json::to_value(response(Uuid::new_v4(), user())).unwrap();
let request: AccountMemberRequest = serde_json::from_value(response).unwrap();
assert_eq!(request.user.id, Uuid::nil());
@@ -91,8 +96,8 @@ mod tests {
assert_eq!(member.account_id, account_id);
assert_eq!(member.user_id, user_id);
let response = AccountMemberResponse::from(member);
let response = response(id, user());
assert_eq!(response.id, id);
assert_eq!(response.user.id, user_id);
assert_eq!(response.user.id, Uuid::nil());
}
}