| 56 | } |
| 57 | |
| 58 | pub async fn create_and_update_metadata(db: &DatabaseConnection) -> Result<(), DbErr> { |
| 59 | let metadata = metadata::Model { |
| 60 | uuid: Uuid::new_v4(), |
| 61 | ty: "Type".to_owned(), |
| 62 | key: "markup".to_owned(), |
| 63 | value: "1.18".to_owned(), |
| 64 | bytes: vec![1, 2, 3], |
| 65 | date: Some(Date::from_ymd_opt(2021, 9, 27).unwrap()), |
| 66 | time: Some(Time::from_hms_opt(11, 32, 55).unwrap()), |
| 67 | }; |
| 68 | |
| 69 | let res = Metadata::insert(metadata.clone().into_active_model()) |
| 70 | .exec(db) |
| 71 | .await?; |
| 72 | |
| 73 | assert_eq!(Metadata::find().one(db).await?, Some(metadata.clone())); |
| 74 | |
| 75 | assert_eq!(res.last_insert_id, metadata.uuid); |
| 76 | |
| 77 | let update_res = Metadata::update(metadata::ActiveModel { |
| 78 | value: Set("0.22".to_owned()), |
| 79 | ..metadata.clone().into_active_model() |
| 80 | }) |
| 81 | .filter(metadata::Column::Uuid.eq(Uuid::default())) |
| 82 | .exec(db) |
| 83 | .await; |
| 84 | |
| 85 | assert_eq!(update_res, Err(DbErr::RecordNotUpdated)); |
| 86 | |
| 87 | Ok(()) |
| 88 | } |