forked from xmppjs/xmpp.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopen.js
More file actions
74 lines (55 loc) · 1.98 KB
/
Copy pathopen.js
File metadata and controls
74 lines (55 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import { EventEmitter } from "@xmpp/events";
import { mockSocket } from "@xmpp/test";
import Connection from "../index.js";
class MockParser extends EventEmitter {}
test("open() sets xml:lang attribute when lang option is provided", async () => {
const conn = new Connection({ domain: "example.com", lang: "en" });
conn.Parser = MockParser;
conn.socket = mockSocket();
// Emit 'open' event after a small delay to let open() set up
setTimeout(() => conn.emit("open"), 10);
await conn.open({ domain: "example.com", lang: "en" });
expect(conn.root.attrs["xml:lang"]).toBe("en");
expect(conn.root.attrs.to).toBe("example.com");
});
test("open() omits xml:lang attribute when lang option is undefined", async () => {
const conn = new Connection({ domain: "example.com" });
conn.Parser = MockParser;
conn.socket = mockSocket();
setTimeout(() => conn.emit("open"), 10);
await conn.open({ domain: "example.com", lang: undefined });
// The xml:lang attribute should be undefined (will be omitted in XML output)
expect(conn.root.attrs["xml:lang"]).toBe(undefined);
expect(conn.root.attrs.to).toBe("example.com");
});
test("start() passes lang option to open()", async () => {
const conn = new Connection({
service: "xmpp://localhost:5222",
domain: "example.com",
lang: "fr",
});
conn.Parser = MockParser;
// Mock connect to succeed immediately
conn.connect = async () => {
conn.socket = mockSocket();
conn._status("connect");
};
// Emit events after start() sets up listeners
setTimeout(() => {
conn.emit("open");
conn.emit("online");
}, 10);
await conn.start();
expect(conn.root.attrs["xml:lang"]).toBe("fr");
});
test("restart() passes lang option to open()", async () => {
const conn = new Connection({
domain: "example.com",
lang: "de",
});
conn.Parser = MockParser;
conn.socket = mockSocket();
setTimeout(() => conn.emit("open"), 10);
await conn.restart();
expect(conn.root.attrs["xml:lang"]).toBe("de");
});