@sockethub/irc2as 4.0.0-alpha.3

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.
@@ -0,0 +1,108 @@
1
+ module.exports = [
2
+ { context: 'irc',
3
+ type: 'update',
4
+ actor: {
5
+ type: 'service',
6
+ id: 'localhost',
7
+ name: 'localhost'
8
+ },
9
+ object: {
10
+ type: 'topic',
11
+ content: '- -'
12
+ }
13
+ },
14
+ { context: 'irc',
15
+ type: 'update',
16
+ actor: {
17
+ type: 'service',
18
+ id: 'localhost',
19
+ name: 'localhost'
20
+ },
21
+ object: {
22
+ type: 'topic',
23
+ content: "- on the https://freenode.live website for our call for volunteers and call for - participation. " +
24
+ "If you are interested in sponsoring next year's event, please - send us an e-mail to sponsor@freenode.live " +
25
+ "- - Thank you for using freenode! - -"
26
+ }
27
+ },
28
+ { context: 'irc',
29
+ type: 'update',
30
+ actor:
31
+ { type: 'person',
32
+ id: 'donkey2018@localhost',
33
+ name: 'donkey2018' },
34
+ target:
35
+ { type: 'person',
36
+ id: 'slvrbckt@localhost',
37
+ name: 'slvrbckt' },
38
+ object: { type: 'address' }
39
+ },
40
+ { context: 'irc',
41
+ type: 'update',
42
+ actor:
43
+ { type: 'person',
44
+ id: 'slvrbckt@localhost',
45
+ name: 'slvrbckt' },
46
+ target:
47
+ { type: 'person',
48
+ id: 'donkey2018@localhost',
49
+ name: 'donkey2018' },
50
+ object: { type: 'address' }
51
+ },
52
+ { context: 'irc',
53
+ type: 'leave',
54
+ actor:
55
+ { type: 'person',
56
+ id: 'slvrbckt@localhost',
57
+ name: 'slvrbckt' },
58
+ target:
59
+ { type: 'room',
60
+ id: 'localhost/#debian',
61
+ name: '#debian' },
62
+ object: { type: 'message', content: 'user has left the channel' }
63
+ },
64
+ {context:"irc",type:"leave",actor:{type:"person",id:"jarlaxl_@localhost",name:"jarlaxl_"},target:{type:"service",id:"localhost"},object:{type:"message",content:"user has quit"}},
65
+ {context:"irc",type:"join",actor:{id:"localhost",type:"service"},error:"no such channel sdfsdfsdfsdfsdf",target:{id:"sdfsdfsdfsdfsdf@localhost",type:"person"}},
66
+ {context:"irc",type:"update",actor:{type:"person",id:"lio17@localhost",name:"lio17"},target:{type:"room",id:"localhost/#kosmos-random",name:"#kosmos-random"},object:{type:"topic","content":"testing123"}},
67
+ {context:"irc",type:"send",actor:{type:"person",id:"hyper_slvrbckt@localhost",name:"hyper_slvrbckt"},target:{type:"room", id:"localhost/#kosmos-random",name:"#kosmos-random"},object:{type:"message",content:"-ssssssss"}},
68
+ {context:"irc",type:"update",actor:{type:"person",id:"lio17@localhost",name:"lio17"},target:{type:"room",id:"localhost/#kosmos-random",name:"#kosmos-random"},object:{type:"topic","content":"no longer boating in senegal"}},
69
+ {context:"irc",type:"send",actor:{type:"person",id:"raucao@localhost",name:"raucao"},target:{type:"room",id:"localhost/#kosmos-random",name:"#kosmos-random"},object:{type:"me",content:"is thinking about sending someone to get b33rz"}},
70
+ {context:"irc",type:"update",object:{type:"presence",role:"member"},actor:{type:"person",id:"hyper_slvrbckt@localhost",name:"hyper_slvrbckt"},target:{type:"room",id:"localhost/#kosmos-random",name:"#kosmos-random"}},
71
+ {context:"irc",type:"update",object:{type:"presence",role:"member"},actor:{type:"person",id:"hyper_slvrbckt@localhost",name:"hyper_slvrbckt"},target:{type:"room",id:"localhost/#kosmos-random",name:"#kosmos-random"}},
72
+ {context:"irc",type:"update",object:{type:"presence",role:"member"},actor:{type:"person",id:"hyper_slvrbckt@localhost",name:"hyper_slvrbckt"},target:{type:"room",id:"localhost/#kosmos-random",name:"#kosmos-random"}},
73
+ {context:"irc",type:"update",object:{type:"presence",role:"member"},actor:{type:"person",id:"hyper_slvrbckt@localhost",name:"hyper_slvrbckt"},target:{type:"room",id:"localhost/#kosmos-random",name:"#kosmos-random"}},
74
+ {context:"irc",type:"update",actor:{type:"person",id:"hyper_slvrbckt@localhost",name:"hyper_slvrbckt"},target:{type:"room",id:"localhost/#kosmos-random",name:"#kosmos-random"},object:{type:"presence",role:"member"}},
75
+ {context:"irc",type:"update",actor:{type:"person",id:"gregkare@localhost",name:"gregkare"},target:{type:"room",id:"localhost/#kosmos-random",name:"#kosmos-random"},object:{type:"presence",role:"member"}},
76
+ {context:"irc",type:"update",actor:{type:"person",id:"slvrbckt@localhost",name:"slvrbckt"},target:{type:"room",id:"localhost/#kosmos",name:"#kosmos"},object:{type:"presence",role:"member"}},
77
+ {context:"irc",type:"update",actor:{type:"person",id:"lio17@localhost",name:"lio17"},target:{type:"room",id:"localhost/#kosmos",name:"#kosmos"},object:{type:"presence",role:"member"}},
78
+ {context:"irc",type:"update",actor:{type:"person",id:"M-silverbucket@localhost",name:"M-silverbucket"},target:{type:"room",id:"localhost/#kosmos",name:"#kosmos"},object:{type:"presence",role:"member"}},
79
+ {context:"irc",type:"update",actor:{type:"person",id:"botka1@localhost",name:"botka1"},target:{type:"room",id:"localhost/#kosmos",name:"#kosmos"},object:{type:"presence",role:"member"}},
80
+ {context:"irc",type:"update",actor:{type:"person",id:"derbumi@localhost",name:"derbumi"},target:{type:"room",id:"localhost/#kosmos",name:"#kosmos"},object:{type:"presence",role:"member"}},
81
+ {context:"irc",type:"update",actor:{type:"person",id:"ChanServ@localhost",name:"ChanServ"},target:{type:"room",id:"localhost/#kosmos",name:"#kosmos"},object:{type:"presence",role:"member"}},
82
+ {context:"irc",type:"update",actor:{type:"person",id:"gregkare@localhost",name:"gregkare"},target:{type:"room",id:"localhost/#kosmos",name:"#kosmos"},object:{type:"presence",role:"member"}},
83
+ {context:"irc",type:"update",actor:{type:"person",id:"hal8000@localhost",name:"hal8000"},target:{type:"room",id:"localhost/#kosmos-random",name:"#kosmos-random"},object:{type:"presence",role:"member"}},
84
+ {context:"irc",type:"update",actor:{type:"person",id:"bkero-@localhost",name:"bkero-"},target:{type:"room",id:"localhost/#kosmos",name:"#kosmos"},object:{type:"presence",role:"member"}},
85
+ {context:"irc",type:"update",actor:{type:"person",id:"galfert@localhost",name:"galfert"},target:{type:"room",id:"localhost/#kosmos",name:"#kosmos"},object:{type:"presence",role:"member"}},
86
+ {context:"irc",type:"update",actor:{type:"person",id:"raucao@localhost",name:"raucao"},target:{type:"room",id:"localhost/#kosmos",name:"#kosmos"},object:{type:"presence",role:"member"}},
87
+ {context:"irc",type:"update",actor:{type:"person",id:"hal8000@localhost",name:"hal8000"},target:{type:"room",id:"localhost/#kosmos",name:"#kosmos"},object:{type:"presence",role:"member"}},
88
+ {context:"irc",type:"update",actor:{type:"person",id:"bkero@localhost",name:"bkero"},target:{type:"room",id:"localhost/#kosmos",name:"#kosmos"},object:{type:"presence",role:"member"}},
89
+ {context:"irc",type:"update",actor:{type:"person",id:"bumi[m]@localhost",name:"bumi[m]"},target:{type:"room",id:"localhost/#kosmos",name:"#kosmos"},object:{type:"presence",role:"member"}},
90
+ {context:"irc",type:"update",actor:{type:"person",id:"slvrbckt@localhost"},target:{type:"room",id:"localhost/#debian"},error:"You're not a channel operator"},
91
+ {context:"irc",type:"update",actor:{type:"person",id:"slvrbckt@localhost"},target:{type:"room",id:"localhost/#kosmos-random"},error:"You're not a channel operator"},
92
+ {context:'irc',type: "add", actor: { type: "person", id: "alice@localhost", name: "alice" }, target: { type: "person", id: "Kilroy@localhost", name: "Kilroy" }, object: { type: "relationship", relationship: "role", subject: { type: "presence", role: "owner" }, object: { type: "room", id: "localhost/#Finnish", name: "#Finnish" } } },
93
+ {context:'irc',type: "add", actor: { type: "person", id: "bob@localhost", name: "bob" }, target: { type: "person", id: "alice@localhost", name: "alice" }, object: { type: "relationship", relationship: "role", subject: { type: "presence", role: "participant" }, object: { type: "room", id: "localhost/#room_a", name: "#room_a" } } },
94
+ {context:'irc',type: "add", actor: { type: "person", id: "alice@localhost", name: "alice" }, target: { type: "person", id: "bob@localhost", name: "bob" }, object: { type: "relationship", relationship: "role", subject: { type: "presence", role: "admin" }, object: { type: "room", id: "localhost/#room_b", name: "#room_b" } } },
95
+ {context:"irc",type:"update",target:{type:"room",id:"localhost/#freenode-sponsors"},actor:{type:"person",id:"hyper_slvrbckt@localhost"},error:"Cannot join channel (+i) - you must be invited"},
96
+ {context:"irc",type:"update",target:{type:"service",id:"localhost"},error:"Nickname is already in use.",actor:{type:"person",id:"nkj@localhost",name:"nkj"}},
97
+ {context:"irc",type:"update",target:{type:"service",id:"localhost"},error:"Nickname is already in use.",actor:{type:"person",id:"slvrbckt@localhost",name:"slvrbckt"}},
98
+ {context:"irc",type:"send",actor:{type:"service",id:"localhost"},object:{type:"message",content:"This nickname is registered. Please choose a different nickname, or identify via /msg NickServ identify <password>."},target:{type:"person",id:"boo@localhost",name:"boo"}},
99
+ {context:"irc",type:"send",actor:{type:"service",id:"localhost"},object:{type:"message",content:"You have 30 seconds to identify to your nickname before it is changed."},target:{type:"person",id:"boo@localhost",name:"boo"}},
100
+ {context:"irc",type:"send",actor:{type:"service",id:"localhost"},object:{type:"message",content:"You failed to identify in time for the nickname boo"},target:{type:"person",id:"boo@localhost",name:"boo"}},
101
+ {context:"irc",type:"update",target:{type:"service",id:"localhost"},error:"Nick/channel is temporarily unavailable",actor:{type:"person",id:"boo@localhost",name:"boo"}},
102
+ {context:"irc",type:"update",actor:{type:"person",id:"sh-WjwOE@localhost",name:"sh-WjwOE"},target:{type:"person",id:"woooo@localhost",name:"woooo"},object:{type:"address"}},
103
+ {context:"irc","type":"send","actor":{"type":"service","id":"localhost"},"object":{"type":"message","content":"Last login from: ~slvrbckt@localhost on Feb 09 18:45:19 2022 +0000."},"target":{"type":"person","id":"slvrbckt@localhost","name":"slvrbckt"}},
104
+ {"context":"irc","type":"join","actor":{"type":"person","id":"myuser@localhost","name":"myuser"},"target":{"type":"room","id":"localhost/#kosmos-random","name":"#kosmos-random"}},
105
+ {"context":"irc","type":"update","actor":{"type":"person","id":"myuser@localhost","name":"myuser"},"target":{"type":"room","id":"localhost/#kosmos-random","name":"#kosmos-random"},"object":{"type":"presence","role":"member"}},
106
+ {"context":"irc","type":"update","actor":{"type":"person","id":"botka@localhost","name":"botka"},"target":{"type":"room","id":"localhost/#kosmos-random","name":"#kosmos-random"},"object":{"type":"presence","role":"owner"}},
107
+ {"context":"irc","type":"update","actor":{"type":"person","id":"foouser@localhost","name":"foouser"},"target":{"type":"room","id":"localhost/#kosmos-random","name":"#kosmos-random"},"object":{"type":"presence","role":"member"}},
108
+ ];
@@ -0,0 +1,93 @@
1
+ const chai = require('chai');
2
+ const schemas = require('@sockethub/schemas').default;
3
+ const fs = require("fs");
4
+ const equal = require('fast-deep-equal');
5
+ const expect = chai.expect;
6
+
7
+ const IRC2AS = require('./index');
8
+ const outputs = require('./index.test.data');
9
+ const ircdata = fs.readFileSync('./src/index.test.data.irc.txt', 'utf-8');
10
+ const inputs = ircdata.split('\n');
11
+
12
+ function matchStream(done) {
13
+ return (stream) => {
14
+ expect(typeof stream.published).to.eql('string');
15
+ delete stream.published;
16
+ let matched = false;
17
+ for (let i = 0; i <= outputs.length; i++) {
18
+ matched = equal(stream, outputs[i]);
19
+ if (matched) {
20
+ // when matched, remove output entry from list
21
+ outputs.splice(i, 1);
22
+ break;
23
+ }
24
+ }
25
+ if (! matched) {
26
+ console.log();
27
+ console.log('available matches:' + JSON.stringify(outputs));
28
+ console.log('failed to find match for: ' + JSON.stringify(stream));
29
+ return done(new Error('failed matching ' + JSON.stringify(stream)));
30
+ }
31
+ const err = schemas.validateActivityStream(stream);
32
+ if (err) {
33
+ return done(new Error(err + ' - ' + JSON.stringify(stream)));
34
+ }
35
+ };
36
+ }
37
+
38
+ describe('IRC2AS', () => {
39
+ let irc2as, pongs = 0, pings = 0;
40
+ // it("provides expected properties", () => {
41
+ beforeEach(() => {
42
+ irc2as = new IRC2AS({server: 'localhost'});
43
+ expect(irc2as).to.have.property('events');
44
+ expect(typeof irc2as.events.on).to.equal('function');
45
+ irc2as.events.on('unprocessed', (string) => {
46
+ console.log('unprocessed> ' + string);
47
+ });
48
+ irc2as.events.on('pong', (time) => {
49
+ pongs++;
50
+ });
51
+ irc2as.events.on('ping', (time) => {
52
+ pings++;
53
+ });
54
+ });
55
+
56
+ describe('inputs generate expected outputs', () => {
57
+ it("inputs generate expected outputs", (done) => {
58
+ irc2as.events.on('incoming', matchStream(done));
59
+ irc2as.events.on('error', matchStream(done));
60
+ for (let i = 0; inputs.length > i; i++) {
61
+ irc2as.input(inputs[i]);
62
+ }
63
+ setTimeout(() => {
64
+ expect(outputs.length).to.equal(0);
65
+ done();
66
+ }, 0);
67
+ });
68
+ it("ping and pong count", () => {
69
+ expect(pings).to.eql(2);
70
+ expect(pongs).to.eql(3);
71
+ });
72
+ });
73
+
74
+ describe('handle many room joins', () => {
75
+ let totalCount = 0;
76
+ it('send join messages', (done) => {
77
+ irc2as.events.on('incoming', () => {
78
+ totalCount += 1;
79
+ if (totalCount === 5 * 100) {
80
+ done();
81
+ }
82
+ });
83
+ for (let i = 0; i < 5; i++) {
84
+ let names = ':hitchcock.freenode.net 353 hyper_slvrbckt @ #kosmos-random :hyper_slvrbckt ';
85
+ for (let n = 0; n < 100; n++) {
86
+ names += ` gregkare${i}${n} hal8000${i}${n} botka${i}${n} raucao${i}${n} galfert${i}${n}`;
87
+ }
88
+ irc2as.input(names);
89
+ }
90
+ irc2as.input(':hitchcock.freenode.net 366 hyper_slvrbckt #kosmos-random :End of /NAMES list.');
91
+ });
92
+ });
93
+ });