|
1 | 1 | use std::{collections::BTreeMap, time::Duration}; |
2 | 2 |
|
3 | | -use assert_matches2::assert_let; |
| 3 | +use assert_matches2::{assert_let, assert_matches}; |
4 | 4 | use eyeball_im::VectorDiff; |
5 | 5 | use futures_util::FutureExt; |
6 | 6 | use matrix_sdk::{ |
@@ -442,7 +442,7 @@ async fn test_marking_room_as_dm() { |
442 | 442 | client |
443 | 443 | .sync_once(SyncSettings::default()) |
444 | 444 | .await |
445 | | - .expect("We should be able to performa an initial sync"); |
| 445 | + .expect("We should be able to perform an initial sync"); |
446 | 446 |
|
447 | 447 | let account_data = client |
448 | 448 | .account() |
@@ -504,6 +504,48 @@ async fn test_marking_room_as_dm() { |
504 | 504 | server.verify().await; |
505 | 505 | } |
506 | 506 |
|
| 507 | +// Check that we're fetching account data from the server when marking a room as |
| 508 | +// a DM, and that we don't clobber the previous entry if it was impossible to |
| 509 | +// deserialize. |
| 510 | +#[async_test] |
| 511 | +async fn test_marking_room_as_dm_fails_if_undeserializable() { |
| 512 | + let (client, server) = logged_in_client_with_server().await; |
| 513 | + |
| 514 | + mock_sync(&server, &*test_json::SYNC, None).await; |
| 515 | + client |
| 516 | + .sync_once(SyncSettings::default()) |
| 517 | + .await |
| 518 | + .expect("We should be able to perform an initial sync"); |
| 519 | + |
| 520 | + let account_data = client |
| 521 | + .account() |
| 522 | + .account_data::<DirectEventContent>() |
| 523 | + .await |
| 524 | + .expect("We should be able to fetch the account data event from the store"); |
| 525 | + |
| 526 | + assert!(account_data.is_none(), "We should not have any account data initially"); |
| 527 | + |
| 528 | + let bob = user_id!("@bob:example.com"); |
| 529 | + let users = vec![bob.to_owned()]; |
| 530 | + |
| 531 | + // The response must be valid JSON, but not a valid `DirectEventContent` |
| 532 | + // representation. |
| 533 | + Mock::given(method("GET")) |
| 534 | + .and(path("_matrix/client/r0/user/@example:localhost/account_data/m.direct")) |
| 535 | + .and(header("authorization", "Bearer 1234")) |
| 536 | + .respond_with(ResponseTemplate::new(200).set_body_json(json!(["hey", null, true, 42]))) |
| 537 | + .expect(1) |
| 538 | + .named("m.direct account data GET") |
| 539 | + .mount(&server) |
| 540 | + .await; |
| 541 | + |
| 542 | + let result = client.account().mark_as_dm(&DEFAULT_TEST_ROOM_ID, &users).await; |
| 543 | + |
| 544 | + assert_matches!(result, Err(matrix_sdk::Error::SerdeJson(_))); |
| 545 | + |
| 546 | + server.verify().await; |
| 547 | +} |
| 548 | + |
507 | 549 | #[cfg(feature = "e2e-encryption")] |
508 | 550 | #[async_test] |
509 | 551 | async fn test_get_own_device() { |
|
0 commit comments