2023-06-08 19:51:32 +02:00
|
|
|
mod common;
|
2023-07-21 15:35:31 +02:00
|
|
|
|
2023-06-08 19:51:32 +02:00
|
|
|
use chorus::gateway::*;
|
2023-08-16 00:21:18 +02:00
|
|
|
use chorus::types::{self, Channel, ChannelModifySchema};
|
2023-06-08 19:51:32 +02:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
/// Tests establishing a connection (hello and heartbeats) on the local gateway;
|
|
|
|
async fn test_gateway_establish() {
|
|
|
|
let bundle = common::setup().await;
|
|
|
|
|
2023-07-22 14:38:55 +02:00
|
|
|
Gateway::new(bundle.urls.wss.clone()).await.unwrap();
|
|
|
|
common::teardown(bundle).await
|
2023-06-08 19:51:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
/// Tests establishing a connection and authenticating
|
|
|
|
async fn test_gateway_authenticate() {
|
|
|
|
let bundle = common::setup().await;
|
|
|
|
|
2023-07-22 14:38:55 +02:00
|
|
|
let gateway = Gateway::new(bundle.urls.wss.clone()).await.unwrap();
|
2023-06-08 19:51:32 +02:00
|
|
|
|
|
|
|
let mut identify = types::GatewayIdentifyPayload::common();
|
2023-07-22 14:38:55 +02:00
|
|
|
identify.token = bundle.user.token.clone();
|
2023-06-08 19:51:32 +02:00
|
|
|
|
|
|
|
gateway.send_identify(identify).await;
|
2023-07-22 14:38:55 +02:00
|
|
|
common::teardown(bundle).await
|
2023-06-08 19:51:32 +02:00
|
|
|
}
|
2023-07-21 15:35:31 +02:00
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn test_self_updating_structs() {
|
|
|
|
let mut bundle = common::setup().await;
|
2023-08-16 01:11:32 +02:00
|
|
|
let received_channel = bundle
|
|
|
|
.user
|
|
|
|
.gateway
|
|
|
|
.observe_and_into_inner(bundle.channel.clone())
|
|
|
|
.await;
|
2023-08-15 20:20:58 +02:00
|
|
|
|
2023-08-13 15:52:16 +02:00
|
|
|
assert_eq!(received_channel, bundle.channel.read().unwrap().clone());
|
|
|
|
|
|
|
|
let modify_schema = ChannelModifySchema {
|
|
|
|
name: Some("selfupdating".to_string()),
|
2023-07-21 15:35:31 +02:00
|
|
|
..Default::default()
|
|
|
|
};
|
2023-08-16 01:11:32 +02:00
|
|
|
received_channel
|
|
|
|
.modify(modify_schema, &mut bundle.user)
|
2023-08-13 15:52:16 +02:00
|
|
|
.await
|
|
|
|
.unwrap();
|
2023-08-12 22:40:40 +02:00
|
|
|
assert_eq!(
|
2023-08-16 01:11:32 +02:00
|
|
|
bundle
|
|
|
|
.user
|
|
|
|
.gateway
|
|
|
|
.observe_and_into_inner(bundle.channel.clone())
|
|
|
|
.await
|
|
|
|
.name
|
|
|
|
.unwrap(),
|
2023-08-13 15:52:16 +02:00
|
|
|
"selfupdating".to_string()
|
2023-08-12 22:40:40 +02:00
|
|
|
);
|
2023-08-13 15:52:16 +02:00
|
|
|
|
2023-07-22 14:38:55 +02:00
|
|
|
common::teardown(bundle).await
|
2023-07-21 15:35:31 +02:00
|
|
|
}
|