1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-07-30 04:23:07 +03:00

MatrixClient.setAccountData: await remote echo. (#4695)

* Rewrite `deleteAccountData` test

use fetch-mock rather than whatever this was

* `MatrixClient.setAccountData`: await remote echo

Wait for the echo to come back from the server before we assume the account
data has been successfully set

* Update integration tests

Fix up the integ tests which call `setAccountData` and now need a sync
response.

* Address review comment
This commit is contained in:
Richard van der Hoff
2025-02-10 17:35:08 +01:00
committed by GitHub
parent 30d9b0518f
commit c537a361fb
6 changed files with 303 additions and 80 deletions

View File

@ -19,16 +19,23 @@ import fetchMock from "fetch-mock-jest";
import { type ISyncResponder } from "./SyncResponder";
/**
* An object which intercepts `account_data` get and set requests via fetch-mock.
* An object which intercepts `account_data` get and set requests via fetch-mock.
*
* To use this, call {@link interceptSetAccountData} for each type of account date that should be handled. The updated
* account data will be stored in {@link accountDataEvents}; it will also trigger a sync response echoing the updated
* data.
*
* Optionally, you can also call {@link interceptGetAccountData}.
*/
export class AccountDataAccumulator {
/**
* The account data events to be returned by the sync.
* Will be updated when fetchMock intercepts calls to PUT `/_matrix/client/v3/user/:userId/account_data/`.
* Will be used by `sendSyncResponseWithUpdatedAccountData`
*/
public accountDataEvents: Map<string, any> = new Map();
public constructor(private syncResponder: ISyncResponder) {}
/**
* Intercept requests to set a particular type of account data.
*
@ -53,6 +60,9 @@ export class AccountDataAccumulator {
// update account data for sync response
this.accountDataEvents.set(type!, content);
resolve(content);
// return a sync response
this.sendSyncResponseWithUpdatedAccountData();
return {};
},
opts,
@ -90,9 +100,9 @@ export class AccountDataAccumulator {
/**
* Send a sync response the current account data events.
*/
public sendSyncResponseWithUpdatedAccountData(syncResponder: ISyncResponder): void {
private sendSyncResponseWithUpdatedAccountData(): void {
try {
syncResponder.sendOrQueueSyncResponse({
this.syncResponder.sendOrQueueSyncResponse({
next_batch: 1,
account_data: {
events: Array.from(this.accountDataEvents, ([type, content]) => ({