Browse Source

Test order and cfd insertion in the actor

Check whether after inserting order and the cfd the Cfd feed works as expected
debug-statements
Mariusz Klochowicz 3 years ago
parent
commit
5b615476a3
No known key found for this signature in database GPG Key ID: 470C865699C8D4D
  1. 30
      daemon/src/db.rs

30
daemon/src/db.rs

@ -562,14 +562,16 @@ fn convert_to_system_time(row_secs: i64, row_nanos: i32) -> Result<SystemTime> {
#[cfg(test)]
mod tests {
use crate::cfd_actors;
use pretty_assertions::assert_eq;
use rand::Rng;
use rust_decimal_macros::dec;
use sqlx::SqlitePool;
use time::macros::datetime;
use time::OffsetDateTime;
use tokio::sync::watch;
use crate::db::insert_order;
use crate::db::{self, insert_order};
use crate::model::cfd::{Cfd, CfdState, Order, Origin};
use crate::model::Usd;
@ -595,6 +597,32 @@ mod tests {
assert_eq!(vec![cfd], loaded);
}
#[tokio::test]
async fn test_insert_like_cfd_actor() {
let mut conn = setup_test_db().await;
let cfds = load_all_cfds(&mut conn).await.unwrap();
let (cfd_feed_sender, cfd_feed_receiver) = watch::channel(cfds.clone());
assert_eq!(cfd_feed_receiver.borrow().clone(), vec![]);
let cfd_1 = Cfd::dummy();
db::insert_order(&cfd_1.order, &mut conn).await.unwrap();
cfd_actors::insert_cfd(&cfd_1, &mut conn, &cfd_feed_sender)
.await
.unwrap();
assert_eq!(cfd_feed_receiver.borrow().clone(), vec![cfd_1.clone()]);
let cfd_2 = Cfd::dummy();
db::insert_order(&cfd_2.order, &mut conn).await.unwrap();
cfd_actors::insert_cfd(&cfd_2, &mut conn, &cfd_feed_sender)
.await
.unwrap();
assert_eq!(cfd_feed_receiver.borrow().clone(), vec![cfd_1, cfd_2]);
}
#[tokio::test]
async fn test_insert_and_load_cfd_by_order_id() {
let mut conn = setup_test_db().await;

Loading…
Cancel
Save