-
-
Notifications
You must be signed in to change notification settings - Fork 607
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Polls: count undecryptable poll relations (#3163)
- Loading branch information
Kerry
authored
Feb 20, 2023
1 parent
89df43a
commit 1a91ba5
Showing
2 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,7 +132,7 @@ describe("Poll", () => { | |
}); | ||
|
||
it("filters relations for relevent response events", async () => { | ||
const replyEvent = new MatrixEvent({ type: "m.room.message" }); | ||
const replyEvent = makeRelatedEvent({ type: "m.room.message" }); | ||
const stableResponseEvent = makeRelatedEvent({ type: M_POLL_RESPONSE.stable! }); | ||
const unstableResponseEvent = makeRelatedEvent({ type: M_POLL_RESPONSE.unstable }); | ||
|
||
|
@@ -188,6 +188,47 @@ describe("Poll", () => { | |
}); | ||
}); | ||
|
||
describe("undecryptable relations", () => { | ||
it("counts undecryptable relation events when getting responses", async () => { | ||
const replyEvent = makeRelatedEvent({ type: "m.room.message" }); | ||
const stableResponseEvent = makeRelatedEvent({ type: M_POLL_RESPONSE.stable! }); | ||
const undecryptableEvent = makeRelatedEvent({ type: M_POLL_RESPONSE.unstable }); | ||
jest.spyOn(undecryptableEvent, "isDecryptionFailure").mockReturnValue(true); | ||
|
||
mockClient.relations.mockResolvedValue({ | ||
events: [replyEvent, stableResponseEvent, undecryptableEvent], | ||
}); | ||
const poll = new Poll(basePollStartEvent, mockClient, room); | ||
jest.spyOn(poll, "emit"); | ||
await poll.getResponses(); | ||
expect(poll.undecryptableRelationsCount).toBe(1); | ||
expect(poll.emit).toHaveBeenCalledWith(PollEvent.UndecryptableRelations, 1); | ||
}); | ||
|
||
it("adds to undercryptable event count when new relation is undecryptable", async () => { | ||
const replyEvent = makeRelatedEvent({ type: "m.room.message" }); | ||
const stableResponseEvent = makeRelatedEvent({ type: M_POLL_RESPONSE.stable! }); | ||
const undecryptableEvent = makeRelatedEvent({ type: M_POLL_RESPONSE.unstable }); | ||
const undecryptableEvent2 = makeRelatedEvent({ type: M_POLL_RESPONSE.unstable }); | ||
jest.spyOn(undecryptableEvent, "isDecryptionFailure").mockReturnValue(true); | ||
jest.spyOn(undecryptableEvent2, "isDecryptionFailure").mockReturnValue(true); | ||
|
||
mockClient.relations.mockResolvedValue({ | ||
events: [replyEvent, stableResponseEvent, undecryptableEvent], | ||
}); | ||
const poll = new Poll(basePollStartEvent, mockClient, room); | ||
jest.spyOn(poll, "emit"); | ||
await poll.getResponses(); | ||
expect(poll.undecryptableRelationsCount).toBe(1); | ||
|
||
await poll.onNewRelation(undecryptableEvent2); | ||
|
||
expect(poll.undecryptableRelationsCount).toBe(2); | ||
|
||
expect(poll.emit).toHaveBeenCalledWith(PollEvent.UndecryptableRelations, 2); | ||
}); | ||
}); | ||
|
||
describe("with poll end event", () => { | ||
const stablePollEndEvent = makeRelatedEvent({ type: M_POLL_END.stable!, sender: "@[email protected]" }); | ||
const unstablePollEndEvent = makeRelatedEvent({ type: M_POLL_END.unstable!, sender: "@[email protected]" }); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters