@sockethub/platform-irc 4.0.0-alpha.4 → 4.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/API.md +123 -77
- package/README.md +68 -73
- package/package.json +17 -22
- package/src/index.test.data.ts +60 -0
- package/src/index.test.ts +277 -0
- package/src/index.ts +764 -0
- package/src/octal-hack.js +4 -0
- package/src/schema.ts +66 -0
- package/src/types.ts +18 -0
- package/typedoc.json +11 -0
- package/index.js +0 -700
- package/index.test.data.js +0 -61
- package/index.test.js +0 -204
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import { beforeEach, describe, expect, it } from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type ActivityStream,
|
|
5
|
+
type CredentialsObject,
|
|
6
|
+
addPlatformSchema,
|
|
7
|
+
getPlatformSchema,
|
|
8
|
+
validateCredentials,
|
|
9
|
+
validatePlatformSchema,
|
|
10
|
+
} from "@sockethub/schemas";
|
|
11
|
+
import type { GetClientCallback } from "./index";
|
|
12
|
+
|
|
13
|
+
import IRC from "./index";
|
|
14
|
+
|
|
15
|
+
const actor = {
|
|
16
|
+
type: "person",
|
|
17
|
+
id: "testingham@irc.example.com",
|
|
18
|
+
name: "testingham",
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const newActor = {
|
|
22
|
+
type: "person",
|
|
23
|
+
id: "testler@irc.example.com",
|
|
24
|
+
name: "testler",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const targetRoom = {
|
|
28
|
+
type: "room",
|
|
29
|
+
id: "irc.example.com/a-room",
|
|
30
|
+
name: "#a-room",
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const validCredentials = {
|
|
34
|
+
context: "irc",
|
|
35
|
+
type: "credentials",
|
|
36
|
+
actor: actor,
|
|
37
|
+
object: {
|
|
38
|
+
type: "credentials",
|
|
39
|
+
nick: "testingham",
|
|
40
|
+
server: "irc.example.com",
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
describe("Initialize IRC Platform", () => {
|
|
45
|
+
let platform;
|
|
46
|
+
beforeEach(() => {
|
|
47
|
+
platform = new IRC({
|
|
48
|
+
debug: () => {},
|
|
49
|
+
updateActor: function async() {
|
|
50
|
+
return Promise.resolve();
|
|
51
|
+
},
|
|
52
|
+
sendToClient: () => {},
|
|
53
|
+
});
|
|
54
|
+
platform.ircConnect = (
|
|
55
|
+
credentials: CredentialsObject,
|
|
56
|
+
cb: GetClientCallback,
|
|
57
|
+
) => {
|
|
58
|
+
cb(null, {
|
|
59
|
+
end: () => {},
|
|
60
|
+
on: () => {},
|
|
61
|
+
raw: () => {},
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
if (!getPlatformSchema("irc/credentials")) {
|
|
65
|
+
addPlatformSchema(platform.schema.credentials, `irc/credentials`);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("lists required types enum", () => {
|
|
70
|
+
expect(platform.schema.messages.properties.type.enum).toEqual([
|
|
71
|
+
"connect",
|
|
72
|
+
"update",
|
|
73
|
+
"join",
|
|
74
|
+
"leave",
|
|
75
|
+
"send",
|
|
76
|
+
"query",
|
|
77
|
+
"announce",
|
|
78
|
+
"disconnect"
|
|
79
|
+
]);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("returns a config object", () => {
|
|
83
|
+
expect(platform.config).toEqual({
|
|
84
|
+
connectTimeoutMs: 30000,
|
|
85
|
+
persist: true,
|
|
86
|
+
requireCredentials: ["connect", "update"],
|
|
87
|
+
initialized: false,
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("schema format validation", () => {
|
|
92
|
+
expect(validatePlatformSchema(platform.schema)).toEqual("");
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("credential schema", () => {
|
|
96
|
+
it("valid credentials", () => {
|
|
97
|
+
expect(validateCredentials(validCredentials)).toEqual("");
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("invalid credentials type", () => {
|
|
101
|
+
expect(
|
|
102
|
+
validateCredentials({
|
|
103
|
+
context: "irc",
|
|
104
|
+
type: "credentials",
|
|
105
|
+
// @ts-expect-error test invalid params
|
|
106
|
+
object: {
|
|
107
|
+
host: "example.com",
|
|
108
|
+
port: "6667",
|
|
109
|
+
},
|
|
110
|
+
}),
|
|
111
|
+
).toEqual("[irc] /object: must have required property 'type'");
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("invalid credentials port", () => {
|
|
115
|
+
expect(
|
|
116
|
+
// @ts-expect-error test invalid params
|
|
117
|
+
validateCredentials({
|
|
118
|
+
context: "irc",
|
|
119
|
+
type: "credentials",
|
|
120
|
+
object: {
|
|
121
|
+
type: "credentials",
|
|
122
|
+
host: "example.com",
|
|
123
|
+
port: "6667",
|
|
124
|
+
},
|
|
125
|
+
}),
|
|
126
|
+
).toEqual("[irc] /object/port: must be number");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("invalid credentials additional prop", () => {
|
|
130
|
+
expect(
|
|
131
|
+
// @ts-expect-error test invalid params
|
|
132
|
+
validateCredentials({
|
|
133
|
+
context: "irc",
|
|
134
|
+
type: "credentials",
|
|
135
|
+
object: {
|
|
136
|
+
type: "credentials",
|
|
137
|
+
host: "example.com",
|
|
138
|
+
port: 6667,
|
|
139
|
+
},
|
|
140
|
+
}),
|
|
141
|
+
).toEqual(
|
|
142
|
+
"[irc] /object: must NOT have additional properties: host",
|
|
143
|
+
);
|
|
144
|
+
});
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
describe("platform type methods", () => {
|
|
148
|
+
beforeEach((done) => {
|
|
149
|
+
platform.connect(
|
|
150
|
+
{
|
|
151
|
+
context: "irc",
|
|
152
|
+
type: "connect",
|
|
153
|
+
actor: actor,
|
|
154
|
+
},
|
|
155
|
+
{ object: { server: "a server address" } },
|
|
156
|
+
done,
|
|
157
|
+
);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe("after join", () => {
|
|
161
|
+
beforeEach((done) => {
|
|
162
|
+
platform.join(
|
|
163
|
+
{
|
|
164
|
+
context: "irc",
|
|
165
|
+
type: "join",
|
|
166
|
+
actor: actor,
|
|
167
|
+
target: targetRoom,
|
|
168
|
+
},
|
|
169
|
+
done,
|
|
170
|
+
);
|
|
171
|
+
platform.completeJob();
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it("has join channel registered", () => {
|
|
175
|
+
expect(platform.channels.has("#a-room")).toEqual(true);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("leave()", (done) => {
|
|
179
|
+
platform.leave(
|
|
180
|
+
{
|
|
181
|
+
context: "irc",
|
|
182
|
+
type: "leave",
|
|
183
|
+
actor: actor,
|
|
184
|
+
target: targetRoom,
|
|
185
|
+
},
|
|
186
|
+
done,
|
|
187
|
+
);
|
|
188
|
+
platform.completeJob();
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
it("send()", (done) => {
|
|
192
|
+
platform.send(
|
|
193
|
+
{
|
|
194
|
+
context: "irc",
|
|
195
|
+
type: "send",
|
|
196
|
+
actor: actor,
|
|
197
|
+
object: { content: "har dee dar" },
|
|
198
|
+
target: targetRoom,
|
|
199
|
+
} as ActivityStream,
|
|
200
|
+
done,
|
|
201
|
+
);
|
|
202
|
+
platform.completeJob();
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it("update() topic", (done) => {
|
|
206
|
+
platform.update(
|
|
207
|
+
{
|
|
208
|
+
context: "irc",
|
|
209
|
+
type: "update",
|
|
210
|
+
actor: actor,
|
|
211
|
+
object: { type: "topic", content: "important details" },
|
|
212
|
+
target: targetRoom,
|
|
213
|
+
},
|
|
214
|
+
validCredentials,
|
|
215
|
+
done,
|
|
216
|
+
);
|
|
217
|
+
platform.completeJob();
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("update() nick change", (done) => {
|
|
221
|
+
platform.update(
|
|
222
|
+
{
|
|
223
|
+
context: "irc",
|
|
224
|
+
type: "update",
|
|
225
|
+
actor: actor,
|
|
226
|
+
object: { type: "address" },
|
|
227
|
+
target: newActor,
|
|
228
|
+
},
|
|
229
|
+
validCredentials,
|
|
230
|
+
done,
|
|
231
|
+
);
|
|
232
|
+
platform.completeJob();
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("query()", (done) => {
|
|
236
|
+
platform.query(
|
|
237
|
+
{
|
|
238
|
+
context: "irc",
|
|
239
|
+
type: "query",
|
|
240
|
+
actor: actor,
|
|
241
|
+
target: targetRoom,
|
|
242
|
+
object: { type: "attendance" },
|
|
243
|
+
},
|
|
244
|
+
done,
|
|
245
|
+
);
|
|
246
|
+
platform.completeJob();
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("disconnect()", (done) => {
|
|
250
|
+
expect(platform.config.initialized).toEqual(true);
|
|
251
|
+
let cleanupCalled = false;
|
|
252
|
+
platform.cleanup = (cb) => {
|
|
253
|
+
cleanupCalled = true;
|
|
254
|
+
cb();
|
|
255
|
+
}
|
|
256
|
+
platform.disconnect({
|
|
257
|
+
context: "irc",
|
|
258
|
+
type: "disconnect",
|
|
259
|
+
actor: actor,
|
|
260
|
+
},
|
|
261
|
+
() => {
|
|
262
|
+
expect(platform.config.initialized).toEqual(true);
|
|
263
|
+
expect(cleanupCalled).toEqual(true);
|
|
264
|
+
done();
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it("cleanup()", (done) => {
|
|
269
|
+
expect(platform.config.initialized).toEqual(true);
|
|
270
|
+
platform.cleanup(() => {
|
|
271
|
+
expect(platform.config.initialized).toEqual(false);
|
|
272
|
+
done();
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
});
|