From d8acf63e1d3d962fbc5a2e8266c34d0fed15324a Mon Sep 17 00:00:00 2001 From: Bruno Windels Date: Wed, 2 Jun 2021 18:38:16 +0200 Subject: [PATCH] change mock event api a bit to be easier to read --- src/matrix/room/sending/SendQueue.js | 8 ++++---- src/mocks/event.js | 14 +++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/matrix/room/sending/SendQueue.js b/src/matrix/room/sending/SendQueue.js index cdab31a8..0e1b116d 100644 --- a/src/matrix/room/sending/SendQueue.js +++ b/src/matrix/room/sending/SendQueue.js @@ -315,7 +315,7 @@ export class SendQueue { import {HomeServer as MockHomeServer} from "../../../mocks/HomeServer.js"; import {createMockStorage} from "../../../mocks/Storage.js"; import {NullLogger} from "../../../logging/NullLogger.js"; -import {event, withTextBody, withTxnId} from "../../../mocks/event.js"; +import {createEvent, withTextBody, withTxnId} from "../../../mocks/event.js"; import {poll} from "../../../mocks/poll.js"; export function tests() { @@ -326,12 +326,12 @@ export function tests() { const hs = new MockHomeServer(); // 1. enqueue and start send event 1 const queue = new SendQueue({roomId: "!abc", storage, hsApi: hs.api}); - const event1 = withTextBody(event("m.room.message", "$123"), "message 1"); + const event1 = withTextBody("message 1", createEvent("m.room.message", "$123")); await logger.run("event1", log => queue.enqueueEvent(event1.type, event1.content, null, log)); assert.equal(queue.pendingEvents.length, 1); const sendRequest1 = hs.requests.send[0]; // 2. receive remote echo, before /send has returned - const remoteEcho = withTxnId(event1, sendRequest1.arguments[2]); + const remoteEcho = withTxnId(sendRequest1.arguments[2], event1); const txn = await storage.readWriteTxn([storage.storeNames.pendingEvents]); const removal = await logger.run("remote echo", log => queue.removeRemoteEchos([remoteEcho], txn, log)); await txn.complete(); @@ -339,7 +339,7 @@ export function tests() { queue.emitRemovals(removal); assert.equal(queue.pendingEvents.length, 0); // 3. now enqueue event 2 - const event2 = withTextBody(event("m.room.message", "$456"), "message 2"); + const event2 = withTextBody("message 2", createEvent("m.room.message", "$456")); await logger.run("event2", log => queue.enqueueEvent(event2.type, event2.content, null, log)); // even though the first pending event has been removed by the remote echo, // the second should get the next index, as the send loop is still blocking on the first one diff --git a/src/mocks/event.js b/src/mocks/event.js index b7d20c8a..01cff281 100644 --- a/src/mocks/event.js +++ b/src/mocks/event.js @@ -14,18 +14,22 @@ See the License for the specific language governing permissions and limitations under the License. */ -export function event(type, id = null) { +export function createEvent(type, id = null) { return {type, event_id: id}; } -export function withContent(event, content) { +export function withContent(content, event) { return Object.assign({}, event, {content}); } -export function withTextBody(event, body) { - return withContent(event, {body, msgtype: "m.text"}); +export function withSender(sender, event) { + return Object.assign({}, event, {sender}); } -export function withTxnId(event, txnId) { +export function withTextBody(body, event) { + return withContent({body, msgtype: "m.text"}, event); +} + +export function withTxnId(txnId, event) { return Object.assign({}, event, {unsigned: {transaction_id: txnId}}); }