Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send history in MUCs #227

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Prev Previous commit
Next Next commit
add unit test
  • Loading branch information
uhoreg committed Feb 4, 2021
commit 4f1223e763ecde7296180693f3679e6796c8acdf
49 changes: 49 additions & 0 deletions test/xmppjs/test_HistoryManager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { expect } from "chai";
import { MemoryStorage, HistoryManager } from "../../src/xmppjs/HistoryManager";
import { Element } from "@xmpp/xml";
import { JID } from "@xmpp/jid";

describe("HistoryManager", () => {
describe("MemoryStorage", () => {
it("should return filtered history", async () => {
const historyManager = new HistoryManager(new MemoryStorage(20));
historyManager.addMessage(
"[email protected]", new Element("stanza1"),
new JID("room1", "example.org", "user1"),
);
historyManager.addMessage(
"[email protected]", new Element("stanza2"),
new JID("room1", "example.org", "user1"),
);
historyManager.addMessage(
"[email protected]", new Element("stanza3"),
new JID("room1", "example.org", "user1"),
);
historyManager.addMessage(
"[email protected]", new Element("stanza1"),
new JID("room1", "example.org", "user1"),
);

const unfilteredRoom1 = await historyManager.getHistory("[email protected]", {});
expect(unfilteredRoom1.length).to.equal(3);
const unfilteredRoom2 = await historyManager.getHistory("[email protected]", {});
expect(unfilteredRoom2.length).to.equal(1);

const maxStanzasRoom1 = await historyManager.getHistory("[email protected]", {
maxstanzas: 2,
});
expect(maxStanzasRoom1.length).to.equal(2);
const maxStanzasRoom2 = await historyManager.getHistory("[email protected]", {
maxstanzas: 2,
});
expect(maxStanzasRoom2.length).to.equal(1);

// each stanza will be about 40 characters, so maxchars 50 should
// only give us one stanza
const maxCharsRoom1 = await historyManager.getHistory("[email protected]", {
maxchars: 50,
});
expect(maxCharsRoom1.length).to.equal(1);
});
});
});