Skip to content

Commit

Permalink
Add gateway_info_stream_v2_updated_at_check
Browse files Browse the repository at this point in the history
  • Loading branch information
kurotych committed Dec 18, 2024
1 parent b0bc7a7 commit c9efa11
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions mobile_config/tests/gateway_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,97 @@ async fn gateway_info_v2(pool: PgPool) {
assert_eq!(resp_err.code(), Code::NotFound);
}

#[sqlx::test]
async fn gateway_info_stream_v2_updated_at_check(pool: PgPool) {
let admin_key = make_keypair();
let asset1_pubkey = make_keypair().public_key().clone();
let asset1_hex_idx = 631711281837647359_i64;
let asset2_pubkey = make_keypair().public_key().clone();
let asset2_hex_idx = 631711286145955327_i64;
let asset3_hex_idx = 631711286145006591_i64;
let asset3_pubkey = make_keypair().public_key().clone();

let created_at = Utc::now() - Duration::hours(5);
let refreshed_at = Utc::now() - Duration::hours(3);
let updated_at = Utc::now() - Duration::hours(4);

create_db_tables(&pool).await;
add_db_record(
&pool,
"asset1",
asset1_hex_idx,
"\"wifiIndoor\"",
asset1_pubkey.clone().into(),
created_at,
Some(refreshed_at),
Some(r#"{"wifiInfoV0": {"antenna": 18, "azimuth": 161, "elevation": 2, "electricalDownTilt": 3, "mechanicalDownTilt": 4}}"#)
)
.await;

add_db_record(
&pool,
"asset2",
asset2_hex_idx,
"\"wifiIndoor\"",
asset2_pubkey.clone().into(),
created_at,
None,
Some(r#"{"wifiInfoV0": {"antenna": 18, "azimuth": 161, "elevation": 2, "electricalDownTilt": 3, "mechanicalDownTilt": 4}}"#)
)
.await;

add_db_record(
&pool,
"asset3",
asset3_hex_idx,
"\"wifiDataOnly\"",
asset3_pubkey.clone().into(),
created_at,
Some(refreshed_at),
None,
)
.await;
add_mobile_tracker_record(&pool, asset3_pubkey.clone().into(), updated_at).await;

let (addr, _handle) = spawn_gateway_service(pool.clone(), admin_key.public_key().clone()).await;
let mut client = GatewayClient::connect(addr).await.unwrap();

let req = make_gateway_stream_signed_req_v2(&admin_key, &[], 0);
let stream = client.info_stream_v2(req).await.unwrap().into_inner();

let resp = stream
.filter_map(|result| async { result.ok() })
.collect::<Vec<GatewayInfoStreamResV2>>()
.await;
let gateways = resp.first().unwrap().gateways.clone();
assert_eq!(gateways.len(), 3);
assert_eq!(
gateways
.iter()
.find(|v| v.address == asset1_pubkey.to_vec())
.unwrap()
.updated_at,
refreshed_at.timestamp() as u64
);
assert_eq!(
gateways
.iter()
.find(|v| v.address == asset2_pubkey.to_vec())
.unwrap()
.updated_at,
created_at.timestamp() as u64
);

assert_eq!(
gateways
.iter()
.find(|v| v.address == asset3_pubkey.to_vec())
.unwrap()
.updated_at,
updated_at.timestamp() as u64
);
}

#[sqlx::test]
async fn gateway_stream_info_v2_deployment_info(pool: PgPool) {
let admin_key = make_keypair();
Expand Down

0 comments on commit c9efa11

Please sign in to comment.