diff --git a/crates/lavina-core/src/dialog.rs b/crates/lavina-core/src/dialog.rs index f597295..71745e5 100644 --- a/crates/lavina-core/src/dialog.rs +++ b/crates/lavina-core/src/dialog.rs @@ -110,7 +110,7 @@ impl DialogRegistry { sender: from.clone(), receiver: to.clone(), body: body.clone(), - created_at: chrono::Utc::now(), // todo + created_at: created_at.clone(), }; player.update(update).await; return Ok(()); diff --git a/crates/lavina-core/src/player.rs b/crates/lavina-core/src/player.rs index 5696f08..3842f17 100644 --- a/crates/lavina-core/src/player.rs +++ b/crates/lavina-core/src/player.rs @@ -106,6 +106,7 @@ impl PlayerConnection { Ok(deferred.await?) } + /// Handler in [Player::send_dialog_message]. pub async fn send_dialog_message(&self, recipient: PlayerId, body: Str) -> Result<()> { let (promise, deferred) = oneshot(); let cmd = ClientCommand::SendDialogMessage { diff --git a/crates/projection-irc/tests/lib.rs b/crates/projection-irc/tests/lib.rs index 5a4eb7c..6a90c46 100644 --- a/crates/projection-irc/tests/lib.rs +++ b/crates/projection-irc/tests/lib.rs @@ -635,3 +635,63 @@ async fn server_time_capability() -> Result<()> { server.server.terminate().await?; Ok(()) } + +#[tokio::test] +async fn scenario_two_players_dialog() -> Result<()> { + let mut server = TestServer::start().await?; + + // test scenario + + server.storage.create_user("tester1").await?; + server.storage.set_password("tester1", "password").await?; + server.storage.create_user("tester2").await?; + server.storage.set_password("tester2", "password").await?; + + let mut stream1 = TcpStream::connect(server.server.addr).await?; + let mut s1 = TestScope::new(&mut stream1); + + let mut stream2 = TcpStream::connect(server.server.addr).await?; + let mut s2 = TestScope::new(&mut stream2); + + s1.send("CAP LS 302").await?; + s1.send("NICK tester1").await?; + s1.send("USER UserName 0 * :Real Name").await?; + s1.expect_cap_ls().await?; + s1.send("CAP REQ :sasl").await?; + s1.expect(":testserver CAP tester1 ACK :sasl").await?; + s1.send("AUTHENTICATE PLAIN").await?; + s1.expect(":testserver AUTHENTICATE +").await?; + s1.send("AUTHENTICATE dGVzdGVyMQB0ZXN0ZXIxAHBhc3N3b3Jk").await?; // base64-encoded 'tester1\x00tester1\x00password' + s1.expect(":testserver 900 tester1 tester1 tester1 :You are now logged in as tester1").await?; + s1.expect(":testserver 903 tester1 :SASL authentication successful").await?; + s1.send("CAP END").await?; + s1.expect_server_introduction("tester1").await?; + s1.expect_nothing().await?; + + s2.send("CAP LS 302").await?; + s2.send("NICK tester2").await?; + s2.send("USER UserName 0 * :Real Name").await?; + s2.expect_cap_ls().await?; + s2.send("CAP REQ :sasl").await?; + s2.expect(":testserver CAP tester2 ACK :sasl").await?; + s2.send("AUTHENTICATE PLAIN").await?; + s2.expect(":testserver AUTHENTICATE +").await?; + s2.send("AUTHENTICATE dGVzdGVyMgB0ZXN0ZXIyAHBhc3N3b3Jk").await?; // base64-encoded 'tester2\x00tester2\x00password' + s2.expect(":testserver 900 tester2 tester2 tester2 :You are now logged in as tester2").await?; + s2.expect(":testserver 903 tester2 :SASL authentication successful").await?; + s2.send("CAP END").await?; + s2.expect_server_introduction("tester2").await?; + s2.expect_nothing().await?; + + s1.send("PRIVMSG tester2 :Henlo! How are you?").await?; + s1.expect_nothing().await?; + s2.expect(":tester1 PRIVMSG tester2 :Henlo! How are you?").await?; + s2.expect_nothing().await?; + + s2.send("PRIVMSG tester1 good").await?; + s2.expect_nothing().await?; + s1.expect(":tester2 PRIVMSG tester1 :good").await?; + s1.expect_nothing().await?; + + Ok(()) +}